DOC PREVIEW
UCSD CSE 167 - Rendering in Open GL

This preview shows page 1-2-3-4 out of 12 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 12 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Introduction to Computer GraphicsFarhana Bandukwala, PhDLecture 12: Rendering in Open GLOutline• Scene Setup• Modeling transformations• View setup• Projections• Scale to Screen (to pixels)• Cross product• Drawing surfacesScene Setup• Model transformation– Arrange objects within viewing volume• Viewing transformation– Camera position– Viewing direction– View-up vector• Projection – Choose shape of viewing volume• Viewport transformation– Project to display coordinatesDrawing A CubezxydrawCube(GLfloat color[3]) {glBegin(GL_QUAD_STRIP)glColor3f(color[0],color[1],color[2]);glVertex3f(-1,-1,-1);glVertex3f(-1,1,-1);glVertex3f(1,-1,-1);glVertex3f(1,1,-1);glVertex3f(1,-1,1);glVertex3f(1,1,1);glVertex3f(-1,-1,1);glVertex3f(-1,1,1);glVertex3f(-1,-1,-1);glVertex3f(-1,1,-1);glEnd()glBegin(GL_QUADS)glColor3f(color[0],color[1],color[2]);glVertex3f(-1,-1,-1);glVertex3f(1,-1,-1);glVertex3f(1,-1,1);glVertex3f(1,-1,1);glVertex3f(-1,1,-1);glVertex3f(1,1,-1);glVertex3f(1,1,1);glVertex3f(1,1,1);glEnd()}(-1,-1,-1)(1,1,1)Object coordinates implied by cube definitionDrawing 2 Cubesvoid renderScene(){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );// Draw the geometric primitives{glMatrixMode(GL_MODELVIEW);glLoadIdentity();// DRAW CUBE 1glPushMatrix();glTranslatef(1,4,2);glRotated(45.0,0,1,0);drawCube( color1);glPopMatrix();//DRAW CUBE 2glPushMatrix();glTranslatef(5,2,1);glScalef(1.0,2.0,1.0);drawCube( color2);glPopMatrix();}glutSwapBuffers();}zxyObject coordinates embedded within a world coordinate systemzxyzxyModeling Transformation• Rotation, translation, or scale glMatrixMode(GL_MODELVIEW)glRotate*(angle,x,y,z), glTranslate*(x,y,z), glScale*(x,y,z)glPushMatrix() & glPopMatrix() to isolate transformations applied to different objectsyzxDefine Camera positionvoid renderScene(){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );// Draw the geometric primitives{glMatrixMode(GL_MODELVIEW);glLoadIdentity();//Set up view w/ camera position & orientationgluLookAt(3,3,-3.0,3,3,0.0,0.0,1.0,0.0);// DRAW CUBE 1glPushMatrix();glTranslatef(1,4,2);glRotated(45.0,0,1,0);drawCube( color1);glPopMatrix();//DRAW CUBE 2glPushMatrix();glTranslatef(5,2,1);glScalef(1.0,2.0,1.0);drawCube( color2);glPopMatrix();}glutSwapBuffers();}zxyDefine a camera position & orientationwithin a worldcoordinate systemzxyzxyzxyViewing transformation• Place camera w/ respect to world coordinates• Specify point in object as “eye” point– This determines viewing direction • Specify view-up vectorglMatrixMode(GL_MODELVIEW)gluLookAt(camerax,cameray,cameraz,objectx,objecty,objectz,VUPx,VUPy,VUPz)yzxDefine Projectionvoid renderScene(){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );// Draw the geometric primitives{glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(90.0,1.0,0.50,6);glMatrixMode(GL_MODELVIEW);glLoadIdentity();//Set up view w/ camera position & orientationgluLookAt(3,3,-3.0,3,3,0.0,0.0,1.0,0.0);// DRAW CUBE 1glPushMatrix();glTranslatef(1,4,2);glRotated(45.0,0,1,0);drawCube( color1);glPopMatrix();//DRAW CUBE 2glPushMatrix();glTranslatef(5,2,1);glScalef(1.0,2.0,1.0);drawCube( color2);glPopMatrix();}glutSwapBuffers();}zxyzxyzxyzxynearfarField of view angle along VUPAspect ratio perpendicular to VUPProjection• Specify viewing volume shape & extents (clipping planes)• Choose between perspective and orthographic • (glPerspective(field_of_view,aspect_ratio, near,far) or glOrtho(left,right,bottom,top,near,far))Screen windowViewplane to Windowzxyzxyzxyzxynearfarviewplanevoid reshapeCB(int width, int height){double aspect_ratio=(double)width/(double)height;glViewport(0,0,width,height);}void renderScene(){{glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(90.0,aspect_ratio,0.50,6);Viewport Transformation• Defines the region on screen within which graphics will be rendered (glViewport())• Measured in window coordinates• Corresponds to pixels on screenviewplaneScreen


View Full Document

UCSD CSE 167 - Rendering in Open GL

Documents in this Course
Lighting

Lighting

38 pages

Review

Review

59 pages

Surfaces

Surfaces

22 pages

Review

Review

110 pages

Midterm

Midterm

4 pages

Lighting

Lighting

38 pages

Lighting

Lighting

71 pages

Review

Review

110 pages

Lighting

Lighting

71 pages

Load more
Download Rendering in Open GL
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Rendering in Open GL and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Rendering in Open GL 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?