DOC PREVIEW
UCSD CSE 167 - Lecture 19

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

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 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 10 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 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Introduction to Computer GraphicsFarhana Bandukwala, PhDLecture 19: Putting it all togetherOpenGL: glutInit() to glFlush()main(){ glutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB |GLUT_DEPTH);glutInitWindowSize(800, 800);glutCreateWindow(“Sample");glutDisplayFunc(renderScene);glutMainLoop();}Step 1: Initializing buffers2 (800x800) color buffersfront back1 (800x800) depth bufferStep 2: General parameter initialization & Light propertiesinitState() { glClearColor(0.0f,0.0f,0.0f,1.0f);glShadeModel(GL_SMOOTH);glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);glEnable(GL_DEPTH_TEST);glEnable(GL_NORMALIZE);GLfloat light_diffuse[]={1.0,1.0,0.50,1.0};GLfloat light_specular[]={1.00,1.00,1.00,1.0};GLfloat light_model_ambient[]={.7,.7,.7,1.0};glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular);glLightf(GL_LIGHT0,GL_LINEAR_ATTENUATION,0.5f);}lightStep 3: Define object(s) modelvoid drawCylinder1() {glBegin(GL_QUAD_STRIP);{for (int ii=0;ii<numPts;ii++){setMaterialProperties(&mat_shininess[ii], mat_specular[ii], mat_diffuse[ii], mat_ambient[ii] );glNormal3f(0.0f,(GLfloat)xvals[ii],(GLfloat)yvals[ii]);glVertex3f((GLfloat)0.f,(GLfloat)xvals[ii],(GLfloat)yvals[ii]);glVertex3f((GLfloat)0.5f,(GLfloat)xvals[ii],(GLfloat)yvals[ii]);}glNormal3f(0.0f,(GLfloat)xvals[0],(GLfloat)yvals[0]);glVertex3f((GLfloat)0.f,(GLfloat)xvals[0],(GLfloat)yvals[0]);glVertex3f((GLfloat)0.5f,(GLfloat)xvals[0],(GLfloat)yvals[0]);}glEnd();}drawSphere(){ … }World bounding boxStep 4: Place objects in worldvoid renderScene(void){glMatrixMode(GL_MODELVIEW);glLoadIdentity();glPushMatrix();drawCylinder1();glPopMatrix();glPushMatrix();glTranslatef(2.0,0,0);drawSphere();glPopMatrix();}10000100001000011000010000102001Model view matrixWorld bounding boxStep 5: Specify viewpointvoid renderScene(void){glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt( 0.0,2.0,-3,1.5,0,0,0,1,0);glPushMatrix();drawCylinder1();glPopMatrix();glPushMatrix();glTranslatef(2.0,0,0);drawSphere();glPopMatrix();}−10000100001000011000010000.8.600.6-.8 100000.83210.5547-000.5547 0.8321 000011ccTTModel view matrix−10000100001020011000010000.8.600.6-.8 100000.83210.5547-000.5547 0.8321 000011ccTTWorld frustumStep 6: Specify frustum and add light positionvoid renderScene(void){GLfloat light_position[]={ 1.0,4.0,0.0,1.0};glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(75.0, aspectRatio, -2.0,5.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt( 0.0,2.0,-3,1.5,0,0,0,1,0);glLightfv(GL_LIGHT0,GL_POSITION,light_position);glPushMatrix();drawCylinder1();glPopMatrix();glPushMatrix();glTranslatef(2.0,0,0);drawSphere();glPopMatrix();}0100000000000viewzviewzviewzProjection matrixWorld frustumStep 7: Normalize frustum void renderScene(void){GLfloat light_position[]={ 1.0,4.0,0.0,1.0};glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(75.0, aspectRatio, -2.0,5.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt( 0.0,2.0,-3,1.5,0,0,0,1,0);glLightfv(GL_LIGHT0,GL_POSITION,light_position);glPushMatrix();drawCylinder1();glPopMatrix();glPushMatrix();glTranslatef(2.0,0,0);drawSphere();glPopMatrix();}−−−−+−−+−−+−0100)(2000)()(2000)()(2minmaxmaxminminmaxminmaxminmaxminmaxminmaxminmaxminmaxminmaxzzzzzzzzyyyyyyviewzxxxxxxviewzNormalized Projection matrixStep 8: Scale to viewport coords & Rasterizevoid renderScene(void){GLfloat light_position[]={ 1.0,4.0,0.0,1.0};glViewport(0,0,width,height);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(75.0, aspectRatio, -2.0,5.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt( 0.0,2.0,-3,1.5,0,0,0,1,0);glLightfv(GL_LIGHT0,GL_POSITION,light_position);glPushMatrix();drawCylinder1();glPopMatrix();glPushMatrix();glTranslatef(2.0,0,0);drawSphere();glPopMatrix();glFlush();}World frustumdepthfrontbackStep 9: glutSwapBuffers() Æ switch front and back buffersvoid renderScene(void){GLfloat light_position[]={ 1.0,4.0,0.0,1.0};glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(75.0, aspectRatio, -2.0,5.0);glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt( 0.0,2.0,-3,1.5,0,0,0,1,0);glLightfv(GL_LIGHT0,GL_POSITION,light_position);glPushMatrix();drawCylinder1();glPopMatrix();glPushMatrix();glTranslatef(2.0,0,0);drawSphere();glPopMatrix();glFlush();glutSwapBuffers();}World


View Full Document

UCSD CSE 167 - Lecture 19

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 Lecture 19
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 Lecture 19 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 Lecture 19 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?