PDA

View Full Version : How to draw an image in it's real size in 3d space



pixelita
05-15-2011, 06:59 AM
Hi

I'm trying to draw a flag (like place-mark) in 3d space.
I want to keep it all the time in original size in pixels and
not to be scaled and rotated automatically. How to do that?

My current source code is:



glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0,WndWidth,0, WndHeight,-1,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glDisable(GL_DEPTH_TEST);
glBindTexture(GL_TEXTURE_2D, flagTexID);
glColor4f(1.0f,1.0f,1.0f,1.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(x1 ,y1 );
glTexCoord2f(0.0f, 1.0f);
glVertex2f(x1 ,y2 );
glTexCoord2f(1.0f, 1.0f);
glVertex2f(x2,y2);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(x2,y1 );
glEnd();

glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);


Thanks

strattonbrazil
05-15-2011, 01:48 PM
You mean you have a perspective camera/scene and you want a fixed annotation on your screen?

What you got works. The only thing you're missing is where on your screen you want to draw it. There's a function called gluProject, which lets you project a 3D point and project it onto your screen. That's the point where you draw your flag.

pixelita
05-15-2011, 03:08 PM
I'll try to explain myself better:
I'm using gluProject(..) and it works. My problem is not position, but scaling and rotation.
I want my place-marks always look at the same fixed size (small flags) and also always to face the front of the quad. Currently when I render my scene (go backward or forward ) then closer placemarks get scaled and look huge and far placemarks look very, very small, while I want them always look like the original image size in pixels. And while rotating the whole scene to prevent the flags from rotating, like I can always see quad front.

Thanks again

MaxH
05-15-2011, 10:16 PM
I would use glDrawPixels.

BionicBytes
05-16-2011, 12:31 AM
Your posted code is missing a vital couple of lines of code to save the current camera!

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0,WndWidth,0, WndHeight,-1,1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

glDisable(GL_DEPTH_TEST);
glBindTexture(GL_TEXTURE_2D, flagTexID);
glColor4f(1.0f,1.0f,1.0f,1.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(x1 ,y1 );
glTexCoord2f(0.0f, 1.0f);
glVertex2f(x1 ,y2 );
glTexCoord2f(1.0f, 1.0f);
glVertex2f(x2,y2);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(x2,y1 );
glEnd();

glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();

strattonbrazil
05-17-2011, 01:12 PM
What you're describing should never happen in an orthographic projection. And ignore the post above. You don't have to push/pop the modelview if you don't have reason to.

How are x2 and y2 derived? Are you using gluProject? If so, you're doing it wrong. x1 and y1 should use gluProject, and x2 and y2 should be a fixed offset from them in screen space. If that increases the size as you move forward or backward, you have a problem with your matrices.

pixelita
05-18-2011, 03:16 AM
How are x2 and y2 derived? Are you using gluProject? If so, you're doing it wrong. x1 and y1 should use gluProject, and x2 and y2 should be a fixed offset from them in screen space.

Thank you!! That was it!

And I appreciate all other replies too for trying to help.