How do I set up OpenGL matrix stack for rasterization-only?

Answer

Something like:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0, 0, width, height); /* viewport size in pixels */

will mean that the 3D point (0,0,0) is in the center of the viewport,
and that
(1,1,0) is the top-right corner of the viewport.

To get a 1:1 pixel mapping, with (0,0,0) in the top-left of the
viewport and (width,height,0) in the bottom-right, do this:
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glScalef(2.0f / (float)width, -2.0f / (float)height, 1.0f);
glTranslatef(-((float)width / 2.0f), -((float)height / 2.0f), 0.0f);
glViewport(0, 0, width, height); /* viewport size in pixels */

All opengl Questions

Ask your interview questions on opengl

Write Your comment or Questions if you want the answers on opengl from opengl Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---