Jump to content
  • Advertisement
Sign in to follow this  
pyroExtreme

OpenGL 2D Texture Rotation

This topic is 2802 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've created a basic 2d engine with SDL using opengl for the rendering side of things and i've got a problem with my rotation of textures.

When setting up opengl I call.


glClearColor( 0.5, 0.5, 1, 0 );
glEnable( GL_TEXTURE_2D );

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glMatrixMode( GL_PROJECTION );
glLoadIdentity();
//Set screen to 0,0 top left
glOrtho( 0, m_ScreenWidth, m_ScreenHeight, 0, -1, 1 );

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();



and when drawing a texture I call


glBindTexture(GL_TEXTURE_2D, m_TextureID);

glMatrixMode(GL_TEXTURE);
glLoadIdentity();

//moves centre of texture to origin then rotates then moves back
glTranslatef(-0.5,-0.5,0.0);
glRotatef(angle,0.0,0.0,1.0);
glTranslatef(0.5,0.5,0.0);
glMatrixMode(GL_MODELVIEW);


glTranslatef( m_X, m_Y, m_Z );
glBegin (GL_QUADS);
glColor3f( 1.0, 1.0, 1.0 );
glTexCoord2i(0, 0);
glVertex3i(0, 0, 0);
glTexCoord2i(1, 0);
glVertex3i(m_Width, 0, 0);
glTexCoord2i(1, 1);
glVertex3i(m_Width, m_Height, 0);
glTexCoord2i(0, 1);
glVertex3i(0, m_Height, 0);
glEnd ();
glLoadIdentity();



But for some unknown reason to me my textures are rotating anticlockwise around Z, I could ofcourse make the angle minus or rotate around -Z but in all the examples I've seen online no one does so I'm thinking I've set something up wrong and would rather get to the root of the problem.

Thanks in advance, hope someone can help me.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!