Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7502929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:02:58+00:00 2026-05-29T21:02:58+00:00

UPDATE See bottom for update. I’ve been looking alot around the internet and I

  • 0

UPDATE

See bottom for update.


I’ve been looking alot around the internet and I have found a few tutorials that explain what I’m trying to achieve but I can’t get it to work, either the tutorial is incomplete or not applicable on my code.

I’m trying something as simple as rotating a 2D image around its origin (center).

I use xStart, xEnd, yStart and yEnd to flip the texture which are either 0 or 1.

This is what the code looks like

GameRectangle dest = destination;
Vector2 position = dest.getPosition();

glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, this->image);

//If the rotation isn't 0 we'll rotate it
if (rotation != 0)
{
    glMatrixMode(GL_TEXTURE);

    glLoadIdentity();
    glTranslatef(0.5, 0.5, 0);
    glRotatef(rotation, 0, 0, 1);

    glMatrixMode(GL_PROJECTION);
}

glBegin(GL_QUADS);
glTexCoord2d(xStart,yStart);
glVertex2f(position.x, position.y);

glTexCoord2d(xEnd,yStart);
glVertex2f(position.x + this->bounds.getWidth(), position.y);

glTexCoord2d(xEnd,yEnd); 
glVertex2f(position.x + this->bounds.getWidth(), position.y + this->bounds.getHeight());

glTexCoord2d(xStart,yEnd);
glVertex2f(position.x, position.y + this->bounds.getHeight());

glEnd();

glDisable(GL_TEXTURE_2D);

//Reset the rotation so next object won't be rotated
glMatrixMode(GL_TEXTURE);

glLoadIdentity();
glRotatef(0, 0, 0, 1);

glMatrixMode(GL_PROJECTION);

This code will draw the image in it’s original size and it will rotate it, but it will rotate it from the top left corner which crops the image a lot. By calling GameRectangle.getOrigin() I can easily get the center of the rectangle, but I don’t know where to use it.

Bit if put:

 glTranslatef(-0.5, -0.5, 0);

After I call the:

 glRotatef(0.5, 0.5, 0);

It will rotate from the center, but it will strech the image if it’s not a perfect 90 degrees rotation.

UPDATE


After trying pretty much everything possible, I got the result I was looking for.

But I’m not sure if this is the best approach. Please tell me if there’s something wrong with my code.

As I mentioned in a comment above, I use the same image multiple times and draw it with different values, so I can’t save anything to the actual image. So I must reset the values everytime after I have rendered it.

I changed my code to this:

//Store the position temporary
GameRectangle dest = destination;
Vector2 position = dest.getPosition();

glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, this->image);

glTranslatef(dest.getOrigin().x, dest.getOrigin().y, 0);
glRotatef(rotation, 0, 0, 1);

glBegin(GL_QUADS);
glTexCoord2d(xStart,yStart);
glVertex2f(-dest.getWidth()/2, -dest.getHeight()/2);

glTexCoord2d(xEnd,yStart);
glVertex2f(dest.getWidth()/2, -dest.getHeight()/2);

glTexCoord2d(xEnd,yEnd); 
glVertex2f(dest.getWidth()/2, dest.getHeight()/2);

glTexCoord2d(xStart,yEnd);
glVertex2f(-dest.getWidth()/2, dest.getHeight()/2);

glEnd();

//Reset the rotation and translation
glRotatef(-rotation,0,0,1);
glTranslatef(-dest.getOrigin().x, -dest.getOrigin().y, 0);

glDisable(GL_TEXTURE_2D);

This rotates the texture together with the quad it’s drawn in, it doesn’t strech or crop. However the edges are a bit jagged if the image is filled square but I guess I can’t avoid that with out antialiasing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:02:59+00:00Added an answer on May 29, 2026 at 9:02 pm

    What you want is this:

    glPushMatrix(); //Save the current matrix.
    //Change the current matrix.
    glTranslatef(dest.getOrigin().x, dest.getOrigin().y, 0);
    glRotatef(rotation, 0, 0, 1);
    
    glBegin(GL_QUADS);
    glTexCoord2d(xStart,yStart);
    glVertex2f(-dest.getWidth()/2, -dest.getHeight()/2);
    
    glTexCoord2d(xEnd,yStart);
    glVertex2f(dest.getWidth()/2, -dest.getHeight()/2);
    
    glTexCoord2d(xEnd,yEnd); 
    glVertex2f(dest.getWidth()/2, dest.getHeight()/2);
    
    glTexCoord2d(xStart,yEnd);
    glVertex2f(-dest.getWidth()/2, dest.getHeight()/2);
    
    glEnd();
    
    //Reset the current matrix to the one that was saved.
    glPopMatrix();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update Added jsfiddle - see bottom of post I currently have a function that
Update Solution Found See Bottom of post if interested Seems simple enough and for
http://pastebin.com/bnMaxjep http://www.vidyasocks.com/index.php See the ticker at the bottom, I want to update that so
UPDATE: Sorry I seemed to have forgot some things...see bottom of the post for
SEE BOTTOM OF THIS POST FOR UPDATE ON THIS PLEASE. I have the below
Update: See the bottom of this question for a C# workaround. Hi there, Consider
I see that EF can update a model based on an existing database schema.
Update: After some more reading I see that this problem is totally general, you
UPDATE: See the bottom of this question for what I did to solve the
I HAVE UPDATED WITH FIDDLES, SEE BOTTOM I am developing a wordpress theme to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.