Jump to content
  • Advertisement
Sign in to follow this  

OpenGL 2D Texture Rotation

This topic is 2975 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 );


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

glMatrixMode( GL_MODELVIEW );

and when drawing a texture I call

glBindTexture(GL_TEXTURE_2D, m_TextureID);


//moves centre of texture to origin then rotates then moves back

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 ();

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
Sign in to follow this  

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!