Presentation is loading. Please wait.

Presentation is loading. Please wait.

Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower.

Similar presentations


Presentation on theme: "Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower."— Presentation transcript:

1 Projections

2 Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower left corner of the viewport rectangle, in pixels width, height - Specify the width and height of the viewport

3 Viewport Example Create two viewports in one window w=Window width h=Window height //Left Viewport glViewport(0.0,0.0,w/2.0,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-w/4.0,w/4.0,-h/2.0,h/2.0,-1.0,1.0); glMatrixMode(GL_MODELVIEW); //Draw the scene drawScene(); //Right Viewport glViewport(w/2.0,0.0,w/2.0,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-w/4.0,w/4.0,-h/2.0,h/2.0,-1.0,1.0); glMatrixMode(GL_MODELVIEW); //Draw the scene drawScene();

4 Projections Flattening a 3D virtual scene by projecting it onto a plane The projected geometry is next rasterized into fragments

5 View Frustum Frustum  A portion of a solid, normally a cone or pyramid, which lies between two parallel planes cutting the solid.  We are interested in Square frusta  Used to define the viewing volume

6 Near and Far Clipping Planes Near and Far clipping planes  “Clip out” geometry outside of them This Geometry is not rendered

7 Orthographic Projection Parallel projection where the view direction is orthogonal to the projection plane Projected Objects do not get bigger/smaller when moved away/toward the viewer

8 Orthographic Example //Left Viewport glViewport(0.0,0.0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-w/4.0,w/4.0,-h/2.0,h/2.0,0.0,1.0); //Draw the scene glMatrixMode(GL_MODELVIEW); drawScene(); void glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal);

9 Perspective Projection Perspective projections have a viewpoint that is a finite distance from the projection plane Objects get smaller as distance from viewer gets larger

10 Perspective Example void glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble nearVal, GLdouble farVal);

11 Perspective Example Defined in “GL/glu.h” void gluPerspective(GLdoublefovy, GLdoubleaspect, GLdoublezNear, GLdoublezFar )‏ //Left Viewport glViewport(0.0,0.0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0,w/h,1.0,20.0); //Draw the scene glMatrixMode(GL_MODELVIEW); drawScene();

12 Model -> View -> Projection Modeling Transformation  Used to position geometry in the scene Viewing Transformation  Used to position and orient the view of a scene Projection Transformation  Used to project a scene onto a viewing plane glVertex Modeling Transformatio n View Transformatio n Projection Transformatio n

13 Setting up the view Used to position and orient the view of a scene Viewing transformation can be thought of as a camera viewing the scene  Order of transformations that setup a camera Position Orientation

14 gluLookAt Defined in void gluLookAt( GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble centerX, GLdouble centerY, GLdouble centerZ, GLdouble upX, GLdouble upY, GLdouble upZ )‏ eyeX,eyeY, eyeZ  Specifies the position of the eye point. centerX, centerY, centerZ  Specifies the position of the reference point. upX, upY, upZ  Specifies the direction of the up vector.

15 gluLookAt continued eyeX,eyeY, eyeZ  Specifies the position of the eye point. centerX, centerY, centerZ  Specifies the position of the reference point. upX, upY, upZ  Specifies the direction of the up vector.

16 Depth Buffer Additional component of the frame buffer Holds the depth value of each fragment Needs to be cleared like color buffer

17 Setting up Depth Test OpenGL disables depth test by default  glEnable(GL_DEPTH_TEST); We have an additional part of the frame buffer that needs clearing  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); We need a drawing context that has a depth buffer  glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH);

18 Depth Test Example void display(void)‏ { glEnable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Setup state to start drawing glBegin(GL_TRIANGLES); glVertex3i(-100, 100, 1); glVertex3i(0, 100, 1); glVertex3i(-50, 50, 1); glVertex3i(50, 50, 3); glVertex3i(100, 100, 3); glVertex3i(75, 20, 3); glEnd(); } int main(int argc, char **argv)‏ { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH); glutCreateWindow("Depth Example"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop(); return 0; } Display code GLUT initialization


Download ppt "Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower."

Similar presentations


Ads by Google