Jump to content
  • Advertisement
Sign in to follow this  
Lode

OpenGL A simple OpenGL camera test

This topic is 4827 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'd like to do the following with OpenGL, to improve my understanding of OpenGL: When doing this:
    glBegin(GL_POINTS);
      glVertex3f(x, y, z);
    glEnd();
I want the point to be drawn at the following pixel on screen (when it's visible):
pixel_x = int(width / 2.0 + width * x / z);
pixel_y = int(height / 2.0 + height * y / z);
Where width and height are the size of the screen in pixels. To do this, what should be the modelview matrix, and what should be the projection matrix? This division through z, is this supposed to be done by one of the matrices, or is there something else in OpenGL that does this? Thanks a lot!

Share this post


Link to post
Share on other sites
Advertisement
You just need to switch from a perspective view to orthographic

glMatrixMode( GL_PROJECTION );
glPushMatrix();
glLoadIdentity();
glOrtho( left, right, bottom, top, near, far );
glMatrixMode( GL_MODELVIEW );

... Draw ...

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

Share this post


Link to post
Share on other sites
OpenGL uses this code to compute the 2D coordinates :

Mesa 3D source code -> file: \src\glu\sgi\libutil\project.c

You can also use vertex program to create your own mapping.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!