View Full Version : 3D Camera, but how do you fix certain objects on the screen?
03-29-2003, 12:35 PM
I have a 3d camera that lets you rotate, strafe and move forward and backward in the x-z plane. However, how do I fix certain objects, such as text, so that it is always in the exact same position no matter where the 3d camera is moving. Is it possible to overlay a second matrix that has independant x,y,z value to my current matrix? Or something like this?
Also how do you nullify a colour. I apply a colour to my text but it applies for subsequent objects as well (like my textures). Instead of setting a new colour can I simply turn off my previous colour?
03-29-2003, 12:40 PM
For the camera...
You can use a whole new matrix as you suggested. But I would recommend you use glPushMatrix, glLoadIdentity(), glPushMatrix.
Also, for text you could use glOrtho (2D) rather than perspective (3D).
For the color, look at glPushAttrib and glPopAttrib. You can save and restore many states with this wonderful functions.
03-29-2003, 01:03 PM
Yeah I actually start investigating glPushMatrix and glPullMatrix before you replied. However, if I pushed the matrix and then did glLoadIdentity() to default to the origin if I display the text there I still can't see it because it is off the screen (because the camera is no longer at the origin). Basically I've figured out that if I then translate using the cameras position I can then see the text. Is this how it is done? I was hoping that I wouldn't have to use the cameras position. I.e. the camera and world matrix was completely separate and I would have a text matrix that was always centered on the origin. Perhaps I don't fully understand the concept of matrices in OpenGL.
Actually what I really want it sort of create an overlay. You see I am making a solar system that I want to be able to move around in (which I currently have) however I want the text (i.e. the name of the planet) to overlay whatever is on the screen regardless of where the camera is. Right now I have got the text to appear but if I zoon in too much the planet engulfs the text because it ends up being closer to the camera than the text.
Is this is what is meant by a clipping problem? The text is going behind the object.
Thanks for your help.
[This message has been edited by Rhaegar (edited 03-29-2003).]
03-29-2003, 01:55 PM
Yeah, when you use glPushMat, glLoadIden, glPopMat, you will have to specify your new coordinates starting at the origin; glTanslate, glRotate. http://www.opengl.org/discussion_boards/ubb/smile.gif
That is why I also mentioned glOrtho so that rotation and translation do not affect your text.
Well, about the text being behind your palnets... Disable the depth mask.
glDepthMask( GL_FALSE ); This will avoid the problem of you text not being drawn because it is behind the planet. http://www.opengl.org/discussion_boards/ubb/smile.gif
03-29-2003, 04:42 PM
Do it something like this:
// Prepare to draw
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Clear the screen
glMatrixMode (GL_PROJECTION); // Tell opengl that we are doing project matrix work
glLoadIdentity(); // Clear the matrix
glOrtho(-9.0, 9.0, -9.0, 9.0, 0.0, 30.0); // Setup an Ortho view
glMatrixMode(GL_MODELVIEW); // Tell opengl that we are doing model matrix work. (drawing)
glLoadIdentity(); // Clear the model matrix
glColor3f(1.0, 1.0, 1.0);
// Draw text and 2D stuff with no camera movement
// Change to perspective view and add camera
gluPerspective(60, 1, 1, 30);
glLoadIdentity(); we only use this once
// Camera function here
// Draw 3D stuff here.
Powered by vBulletin® Version 4.2.2 Copyright © 2014 vBulletin Solutions, Inc. All rights reserved.