Help with square rotating, around it's center!

I want to rotate a square, around it’s center, when mouse position changed, but I don’t know how to do it!

If you can help me, write your code in the rotation function!

#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
#include <iostream>
using namespace std;

SDL_Window *window;
SDL_Event event;
SDL_GLContext glContext;

const struct WindowData{
    int WIDTH=800, HEIGHT=800;
    int POS_X=SDL_WINDOWPOS_CENTERED, POS_Y=SDL_WINDOWPOS_CENTERED;
    const char *TITLE="TEST";
    int FLAG=SDL_WINDOW_OPENGL;
} WindowData;

struct SquareData{
    int WIDTH=100, HEIGHT=100;
    float POS_X=350, POS_Y=350;
    float ANGLE=0;
    SDL_Color FILLCOLOR={255, 0, 0};
} SquareData;

struct MouseData{
    int POS_X=0, POS_Y=0;
} MouseData;

struct PointData{
    int POS_X=SquareData.POS_X+SquareData.WIDTH/2, POS_Y=SquareData.POS_Y;
    SDL_Color FILLCOLOR={255, 255, 255};
} PointData;

void drawSquare(){
    glPushMatrix();
    glTranslatef(SquareData.POS_X+50, SquareData.POS_Y+50, 0);
    glRotatef(SquareData.ANGLE, 0, 0, 1);
    glTranslatef(-(SquareData.POS_X+50), -(SquareData.POS_Y+50), 0);

    glTranslatef(SquareData.POS_X, SquareData.POS_Y, 0);
    glBegin(GL_QUADS);
        glColor3ub(SquareData.FILLCOLOR.r,
                   SquareData.FILLCOLOR.g,
                   SquareData.FILLCOLOR.b);
        glVertex2i(0,                                0);
        glVertex2i(SquareData.WIDTH,                 0);
        glVertex2i(SquareData.WIDTH, SquareData.HEIGHT);
        glVertex2i(0,                SquareData.HEIGHT);
    glEnd();
    glPopMatrix();

    glPushMatrix();
    glBegin(GL_POINTS);
        glColor3f(PointData.FILLCOLOR.r, 
                  PointData.FILLCOLOR.g, 
                  PointData.FILLCOLOR.b);
        glVertex2f(PointData.POS_X, PointData.POS_Y);
    glEnd();
    glPopMatrix();
}

void mouseInput(){
    SDL_GetGlobalMouseState(&MouseData.POS_X, &MouseData.POS_Y);
}

void rotation(){
}

int main(){
    window=SDL_CreateWindow(WindowData.TITLE, WindowData.POS_X, 
                            WindowData.POS_Y, WindowData.WIDTH, 
                            WindowData.HEIGHT, WindowData.FLAG);

    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);

    glContext=SDL_GL_CreateContext(window);

    SDL_GL_SetSwapInterval(SDL_FALSE);

    while(window!=NULL){
        while(SDL_PollEvent(&event)){
            switch(event.type){
                case SDL_QUIT:
                    window=NULL;
                    break;
            }
        }

        mouseInput();

        glClearColor(0, 0, 0, 0);
        glClear(GL_COLOR_BUFFER_BIT);

        glViewport(0, 0, WindowData.WIDTH, WindowData.HEIGHT);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0, WindowData.WIDTH, WindowData.HEIGHT, 0, -10, 10);

        drawSquare();

        SDL_GL_SwapWindow(window);
    }
}

How does it rotate at the moment?

What you probably want to do is move the square to world center (0, 0, 0) minus half the square size, so that the square’s middle point is positioned at (0, 0, 0). After that, do the actual rotation and then finally move the square back to its previous position. The result should be a square that rotates around its center position.

Already solved the problem!

Feel free to post an answer here with your solution since it might help people that has the same issue with the code/game/application.

I deleted the code from the computer 5 days ago…