Hello people, I’m having trouble with rotating textures, it’s something that I have never done yet, and I need it badly.
Up to now I was using this function to draw my textures (I was able to make it support textures with multiple subimages and horizontal mirroring via the ‘facing’ parameter), but I want to add it a ‘angle’ parameter that rotates the texture:
void Draw_Texture(unsigned int texture, int x, int y, unsigned char img_w, unsigned char img_h, unsigned int tex_w, unsigned int tex_h, unsigned char img, bool facing)
{
glEnable( GL_TEXTURE_2D );
// Bind the texture to which subsequent calls refer to
glBindTexture( GL_TEXTURE_2D, texture );
glBegin( GL_QUADS );
// Top-left vertex (corner)
glTexCoord2d( ((double)((img + 1 - facing) * img_w)) / ((double)tex_w), 0 );
glVertex3f( x, y, 0 );
// Bottom-left vertex (corner)
glTexCoord2d( ((double)((img + facing) * img_w)) / ((double)tex_w), 0 );
glVertex3f( x + img_w, y, 0 );
// Bottom-right vertex (corner)
glTexCoord2d( ((double)((img + facing) * img_w)) / ((double)tex_w), ((double) img_h) / ((double)tex_h) );
glVertex3f( x + img_w, y + img_h, 0 );
// Top-right vertex (corner)
glTexCoord2d( ((double)((img + 1 - facing) * img_w)) / ((double)tex_w), ((double) img_h) / ((double)tex_h) );
glVertex3f( x, y + img_h, 0 );
glEnd();
}
I know I have to use the glRotate function, but I do not know where or how, I’ve tried several things and I can get it to rotate, but the texture seems to rotate tracing a curve with center in the origin.
So I guess I have to use some glTranslate too… but I do not know how.
I would like the textures to rotate around an arbitrary point (this is all in 2D that I’m working on) that I would supply to the function.
Please help.
Thanks in advance!