Jump to content
  • Advertisement
Sign in to follow this  
carucel

OpenGL Rotatate a triangle, N00by Question

This topic is 3671 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

I'm using OpenGL for 2 weeks now, so this may be a very n00by question. This is my drawing code: glColor4f(col.Red(),col.Green(),col.Blue(),col.Alpha()); glBindTexture(GL_TEXTURE_2D, sprite); glRotatef(0.5f, 0.0f, 0.0f, 0.0f); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex2f(x, y); glTexCoord2f(1.0, 0.0); glVertex2f(x+width, y); glTexCoord2f(1.0, 1.0); glVertex2f(x+width, y+height); glTexCoord2f(0.0, 1.0); glVertex2f(x, y+height); glEnd (); glBindTexture(GL_TEXTURE_2D, 0); The function glRotatef, does rotate something, but I want it to rotate the Quad only, not everything. I have more drawing code after this, and that is rotated as well! I only want this quad (rectangle) in this code to be rotated. Please help me out! Thanx. BTW: I'm just drawing 2d. 3d is not involved.

Share this post


Link to post
Share on other sites
Advertisement
Before you call glRotatef, you could call glPushMatrix in order to save the current matrix. Once your current rendering segment is complete, call glPopMatrix to restore the previous matrix, which will be the one before the rotation was applied.

Share this post


Link to post
Share on other sites
Also, you're not specifying an axis to rotate about. Whether you only ue 2D or not is irrelevant, because 2D is only a special case of 3D but it is not treated as a special case by OpenGL. You still need to treat everything as 3D. The axis of rotation should, in your case, probably be the Z-axis.

glRotatef(0.5, 0, 0, 1);

Share this post


Link to post
Share on other sites
Should i put PushMatrix before my other drawing codes, and put PopMatrix before the code of a quad to be rotated and PushMatrix after it again? Like this:

PushMatrix();

glColor4f(col.Red(),col.Green(),col.Blue(),col.Alpha());
glBindTexture(GL_TEXTURE_2D, sprite);
glRotatef(0.5f, 0.0f, 0.0f, 0.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex2f(x, y);
glTexCoord2f(1.0, 0.0); glVertex2f(x+width, y);
glTexCoord2f(1.0, 1.0); glVertex2f(x+width, y+height);
glTexCoord2f(0.0, 1.0); glVertex2f(x, y+height);
glEnd ();
glBindTexture(GL_TEXTURE_2D, 0);

PopMatrix();

Share this post


Link to post
Share on other sites
Thank you all! I tried to put PushMatrix before all my drawing codes and PopMatrix after, and it worked!

Thank you all for the help!

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!