How to Add a Compass in My Programme

I am a learner of OpenGL,and use it to write a full-screen programme with big scene,in which user can walk around.Now I want to add a compass(A box and Needle)at the right-top conner of the screen to indicate the direction.I known how to draw the appearance
of the compass but do not known how to make some setting before drawing the compass.
Can you give me some code or advice?Any help are appreciated!


You got the rotation of your “Player” arount the y-axis.

So this is the rotation in degrees.

Let’s say 0-degree are East,…

To draw the compass simply draw in ortho mode a texture of your compass with the rotation around the Z-axis. You should use a masked texture (–>Nehe tutorial Masking)

Now you have an Texture that rotaes if you user rotates, so you can draw the needle with GL_LINES.

Thanks a lot!
Now my doubt is “how to make the compass at the corner of the screen when user roam around”.Or rather,how to draw a circle there when user roam:the circle is still at the corner,keep immobility,not associated with the 3D volume!

Just render them seperately. draw your scene and your character, then glLoadIdentity(), glPushMatrix(), translate to the upper corner, draw your compass, glPopMatrix()

Thank you very much!
I have finished my idea!

I had a similar problem ( a while ago - but didn’t solve it ).
Drawing a radar - knew how to do it but had a little problem - no way of calculating the Y rotation - used relaive rotation with quaternions so no way too do somthing like y += 30.0f )

I do not really known clearly about what you want for my poor english.The code i wrote is as below,i expect this is helpful for you:
// Reset The Current Modelview Matrix
// Save The Current MODELVIEW Matrix
// Translate To The Object’s Location
// you can add some other code for the setting of the needle …
// draw the need of the compass
// you can add some other code for the setting of the Box …
// Restore The Current MODELVIEW Matrix

[This message has been edited by zjkw (edited 05-21-2002).]