Jump to content
  • Advertisement
Sign in to follow this  
Servant of the Lord

OpenGL Rotating axis-aligned image by 90 degrees

This topic is 2138 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 SFML, but it just wraps OpenGL fairly closely in this area, so this is really an OpenGL question.
My textures are axis-aligned. If I wanted to rotate them 90 degrees, without using a the typical OpenGL fixed-function rotation functions and without using shaders or manipulating matrices, would it make more sense to do it by rotating the position of the vertices or by rotating the texture coordinates?

My code currently looks like this:
//The pre-transform position and size:
float widthBeforeTransform = static_cast<float>(subRect.width);
float heightBeforeTransform = static_cast<float>(subRect.height);
vertices[0].position = sf::Vector2f(0, 0); //<< Should I rotate these?
vertices[1].position = sf::Vector2f(0, heightBeforeTransform);
vertices[2].position = sf::Vector2f(widthBeforeTransform, heightBeforeTransform);
vertices[3].position = sf::Vector2f(widthBeforeTransform, 0);
//Calculate the texture coordinates:
float left   = static_cast<float>(subRect.left);
float right  = left + subRect.width;
float top    = static_cast<float>(subRect.top);
float bottom = top + subRect.height;
//If we're mirroring, swap the texture coordinates vertically and/or horizontally.
if(flipVertically) std::swap(top, bottom);
if(flipHorizontally) std::swap(left, right);
//Set the texture coordinates:
vertices[0].texCoords = sf::Vector2f(left, top); [font='Helvetica Neue', Arial, Verdana, sans-serif]//<< Or should I rotate these?[/font]
vertices[1].texCoords = sf::Vector2f(left, bottom);
vertices[2].texCoords = sf::Vector2f(right, bottom);
vertices[3].texCoords = sf::Vector2f(right, top);

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!