Draw rotated 2D Sprite at position XY on screen

Hi there,

I’m quite new to OpenGL programming (started yesterday) and I’m pretty sure this is a common problem. However I could not find a decent resource that explains it in detail. Most tutorial aim at 3D stuff - or as I’m new to this area I simply do not know the right words to feed to google.

So heres my problem. Drawing a 2D sprite at position x, y at the screen using OpenGL works pretty forward. But if I want to draw the same sprite rotated e.g. by angle 30* theres where the hassle starts.

Without rotation I’m using glTranslate to move position x,y and then start drawing stuff.

With rotation I tried using glRotate to rotate my sprite around the Z axis. Then I use glTranslate to move to my desired position and start drawing.
So the problem seems to be, that glRotate rotates the whole coordinate system, so my old position x,y is no longer at the same place on the screen.
This means I would have to transform x, y to new coordinates in the rotated coordinate system that match the old screen position.

This seems a bit awkward to me. So I’m wondering if this is the right thing to do or if there are easier/better ways to achieve this simple task of drawing a sprite at a certain position. How would an experienced OpenGL programmer solve my problem?

Yes. :slight_smile:

You nearly solved your problem.
The simple solution is: Try translating and THEN rotating. :wink:

I think… there is nothing more to say, so… I’m pretty sure that works :smiley:

Oh my god. I’m feeling really stupid now :persecutioncomplex:. Looks like its time for a programming break :wink:

Thanks never the less ;D

Nah… You’re not stupid. That is a very common mistake :wink:
Rotating is the first very hard thing in OpenGL programming :slight_smile:

You got the theory right: glRotate rotates the entire coordinate system. That’s hardly stupid if you figured that out independently. :slight_smile:

Lots of smilies in this thread. I like :slight_smile: