Sorry, I searched it but couldn't figure how to apply it to my code reading the other answers to similar questions. I what to rotate a quad, my code is the following:
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, player_texture);
glBegin(GL_QUADS);
glColor4ub(255, 255, 255, 255);
glTexCoord2d(0,0); glVertex2f(hero.xValue(), hero.yValue());
glTexCoord2d(1,0); glVertex2f(hero.xValue()+hero.lValue(), hero.yValue());
glTexCoord2d(1,1); glVertex2f(hero.xValue()+hero.lValue(), hero.yValue()+hero.hValue());
glTexCoord2d(0,1); glVertex2f(hero.xValue(), hero.yValue()+hero.hValue());
glEnd();
glDisable(GL_TEXTURE_2D);
I'm not sure about how to use the glTranslatef function, I tell it what is the center of my object?
In that case it would be: hero.xValue()+hero.lValue()/2 (x) and hero.yValue()+hero.hValue()/2 (y)
I know I have to use both glTranslatef and glRotate, by the way. When I try, setting glTranslatef with the values I mentioned above, I get a texture floating far from where the hero actually is.
Any help on this matter will be appreciated, thank you.
Obs: hValue = height, lValue = lenght
Edit: New information to show the changes I made after @user55564's comment:
I call init() once, on there I set basic openGL and SDL stuff, among them:
glViewport(0, 0, WIDTH, HEIGHT);
glMatrixMode(GL_MODELVIEW);
then I call my draw function, it has in it:
while (running) {
glLoadIdentity();
.
. stuff non-related to drawing
.
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(0, 0, 0, 0);
glPushMatrix();
glOrtho(0, WIDTH, HEIGHT, 0, -1, 1);
// draws the player
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, player_texture);
glTranslatef(hero.xValue(), hero.yValue(), 0);
glRotatef(0, 0, 0, 1);
glTranslatef(-(hero.xValue()+hero.lValue()/2), -(hero.yValue()+hero.hValue()/2), 0);
glBegin(GL_QUADS);
glColor4ub(255, 255, 255, 255);
glTexCoord2d(0,0); glVertex2f(hero.xValue(), hero.yValue());
glTexCoord2d(1,0); glVertex2f(hero.xValue()+hero.lValue(), hero.yValue());
glTexCoord2d(1,1); glVertex2f(hero.xValue()+hero.lValue(), hero.yValue()+hero.hValue());
glTexCoord2d(0,1); glVertex2f(hero.xValue(), hero.yValue()+hero.hValue());
glEnd();
glDisable(GL_TEXTURE_2D);
glPopMatrix();
// then I use pushmatrix again to draw the enemies and the health bars of both enemies and player (these don't need rotation);
glPushMatrix();
glOrtho(0, WIDTH, HEIGHT, 0, -1, 1);
.
.
.