DOC PREVIEW
UCSD CSE 167 - OpenGL Implementation & Project 2

This preview shows page 1-2-3-19-20-39-40-41 out of 41 pages.

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

Unformatted text preview:

#4: OpenGL Implementation& Project 2CSE167: Computer GraphicsTAs: Alex Kozlowski &Cameron ChrismanUCSD, Winter 20061How was Project 1? Too Hard? Too Easy? Not enough time? Not enough explanation? Goal of Project 1: Get comfortable withMatrices, Vectors, Points, and Order ofOperations2Outline for Today1. What is OpenGL?2. Program Layout and CommonCommands3. Stack Operations4. C++, Vectors, Matrices5. Project 23What is OpenGL? A low-level graphics library specification Provides a small set of geometricprimitives: points, lines, polygons, images, and bitmaps. Support for 2 and 3 dimensions Includes commands that control how theseobjects are rendered into the frame buffer4What is GLUT? Like OpenGL, it’s a library A windowing API for OpenGL Easy for the user to handle window events When to redraw the window Mouse Clicks Keyboard Commands Resizing the window Cross platform5Outline for Today1. What is OpenGL?2. Program Layout and CommonCommands3. Stack Operations4. C++, Vectors, Matrices5. Project 26Typical Graphics Programint main( int argc, char** argv ){ // Initialize glut glutInit(&argc,argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ); // Window position (from top corner), and size (width and height) glutInitWindowPosition( 20, 60 ); glutInitWindowSize( 360, 360 ); glutCreateWindow( "CSE167 Matrix Project" ); // Setup the OpenGL features we'd like to use initRendering(); // Set up callback functions for key presses glutKeyboardFunc( myKeyboardFunc ); // Handles "normal" ascii symbols // Set up the callback function for resizing windows glutReshapeFunc( resizeWindow ); // call this whenever window needs redrawing glutDisplayFunc( drawScene ); // Start the main loop. glutMainLoop never returns. glutMainLoop(); return(0); // This line is never reached.}7Typical Graphics Programvoid drawScene(void){ // This command clears the screen to the glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Setup our projection matrix glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60,g_Aspect,.1,80); // Switch to ModelView glMatrixMode(GL_MODELVIEW); // Camera transformations would typically go here // Draw stuff… // Swap the buffers glutSwapBuffers(); // Tell glut to immediately redraw the scene for the next frame glutPostRedisplay();}8Drawing Primitives in OpenGL Starts with glBegin(primitive_constant) andends with glEnd() 10 Primitive Types GL_POINTS, GL_LINES, GL_LINE_STRIP,GL_LINE_LOOP, GL_TRIANGLES,GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN,GL_QUADS, GL_QUAD_STRIP, andGL_POLYGON We’ll use GL_TRIANGLES most often inthis class9Drawing Primitives in OpenGL// 2 Triangles glBegin(GL_TRIANGLES); glColor3f(1,0,0); glVertex3f( 1, 1,0); glVertex3f(-1, 1,0); glVertex3f(-1,-1,0); glVertex3f(-1,-1,0); glVertex3f( 1,-1,0); glVertex3f( 1, 1,0); glEnd();// 1 Quad glBegin(GL_QUADS); glColor3f(1,0,0); glVertex3f( 1, 1,0); glVertex3f(-1, 1,0); glVertex3f(-1,-1,0); glVertex3f( 1,-1,0);glEnd();10Outline for Today1. What is OpenGL?2. Program Layout and CommonCommands3. Stack Operations4. C++, Vectors, Matrices5. Project 211Books on a TableLoadIdentity()PushMatrix() Translate(2,1) drawTable() PushMatrix() Translate(1,1) RotateZ(60) drawBook() PopMatrix() PushMatrix() Translate(-1,0) RotateZ(-45) drawBook() PopMatrix()PopMatrix()12Books on a TableLoadIdentity()PushMatrix() Translate(2,1) drawTable() PushMatrix() Translate(1,1) RotateZ(60) drawBook() PopMatrix() PushMatrix() Translate(-1,0) RotateZ(-45) drawBook() PopMatrix()PopMatrix() I13Books on a TableLoadIdentity()PushMatrix() Translate(2,1) drawTable() PushMatrix() Translate(1,1) RotateZ(60) drawBook() PopMatrix() PushMatrix() Translate(-1,0) RotateZ(-45) drawBook() PopMatrix()PopMatrix() I I14Books on a TableLoadIdentity()PushMatrix() Translate(2,1) drawTable() PushMatrix() Translate(1,1) RotateZ(60) drawBook() PopMatrix() PushMatrix() Translate(-1,0) RotateZ(-45) drawBook() PopMatrix()PopMatrix() I*T(2,1) I15Books on a TableLoadIdentity()PushMatrix() Translate(2,1) drawTable() PushMatrix() Translate(1,1) RotateZ(60) drawBook() PopMatrix() PushMatrix() Translate(-1,0) RotateZ(-45) drawBook() PopMatrix()PopMatrix() I*T(2,1) I16Books on a TableLoadIdentity()PushMatrix() Translate(2,1) drawTable() PushMatrix() Translate(1,1) RotateZ(60) drawBook() PopMatrix() PushMatrix() Translate(-1,0) RotateZ(-45) drawBook() PopMatrix()PopMatrix()I*T(2,1) I*T(2,1) I17Books on a TableLoadIdentity()PushMatrix() Translate(2,1) drawTable() PushMatrix() Translate(1,1) RotateZ(60) drawBook() PopMatrix() PushMatrix() Translate(-1,0) RotateZ(-45) drawBook() PopMatrix()PopMatrix()I*T(2,1)*T(1,1) I*T(2,1) I18Books on a TableLoadIdentity()PushMatrix() Translate(2,1) drawTable() PushMatrix() Translate(1,1) RotateZ(60) drawBook() PopMatrix() PushMatrix() Translate(-1,0) RotateZ(-45) drawBook() PopMatrix()PopMatrix()I*T(2,1)*T(1,1)*R(60) I*T(2,1) I19Books on a TableLoadIdentity()PushMatrix() Translate(2,1) drawTable() PushMatrix() Translate(1,1) RotateZ(60) drawBook() PopMatrix() PushMatrix() Translate(-1,0) RotateZ(-45) drawBook() PopMatrix()PopMatrix()I*T(2,1)*T(1,1)*R(60) I*T(2,1) I20Books on a TableLoadIdentity()PushMatrix() Translate(2,1) drawTable() PushMatrix() Translate(1,1) RotateZ(60) drawBook() PopMatrix() PushMatrix() Translate(-1,0) RotateZ(-45) drawBook() PopMatrix()PopMatrix()I*T(2,1)*T(1,1)*R(60) I*T(2,1) I21Books on a TableLoadIdentity()PushMatrix() Translate(2,1) drawTable() PushMatrix() Translate(1,1) RotateZ(60) drawBook() PopMatrix() PushMatrix() Translate(-1,0) RotateZ(-45) drawBook() PopMatrix()PopMatrix()I*T(2,1) I*T(2,1) I22Books on a TableLoadIdentity()PushMatrix() Translate(2,1) drawTable() PushMatrix() Translate(1,1) RotateZ(60) drawBook() PopMatrix() PushMatrix() Translate(-1,0) RotateZ(-45) drawBook() PopMatrix()PopMatrix()I*T(2,1)*T(-1,0)*R(45) I*T(2,1) I23Books on a TableLoadIdentity()PushMatrix() Translate(2,1) drawTable() PushMatrix() Translate(1,1) RotateZ(60) drawBook() PopMatrix() PushMatrix() Translate(-1,0) RotateZ(-45) drawBook() PopMatrix()PopMatrix()I*T(2,1)*T(-1,0)*R(45) I*T(2,1) I24Books on a TableLoadIdentity()PushMatrix() Translate(2,1) drawTable() PushMatrix() Translate(1,1) RotateZ(60) drawBook() PopMatrix() PushMatrix()


View Full Document

UCSD CSE 167 - OpenGL Implementation & Project 2

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 OpenGL Implementation & Project 2
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 OpenGL Implementation & Project 2 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 OpenGL Implementation & Project 2 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?