to do to do computer graphics fall 2004 computer graphics
play

To Do To Do Computer Graphics (Fall 2004) Computer Graphics (Fall - PDF document

To Do To Do Computer Graphics (Fall 2004) Computer Graphics (Fall 2004) Fill out survey Start thinking (now) about HW 3. Milestones are due COMS 4160, Lecture 10: OpenGL 1 in 2 weeks. http://www.cs.columbia.edu/~cs4160 Note that


  1. To Do To Do Computer Graphics (Fall 2004) Computer Graphics (Fall 2004) � Fill out survey � Start thinking (now) about HW 3. Milestones are due COMS 4160, Lecture 10: OpenGL 1 in 2 weeks. http://www.cs.columbia.edu/~cs4160 � Note that I’ll be showing programs in class Course Outline Course Outline Course Outline Course Outline � 3D Graphics Pipeline � 3D Graphics Pipeline Rendering Rendering Modeling Modeling (Creating, shading images from (Creating, shading images from (Creating 3D Geometry) (Creating 3D Geometry) geometry, lighting, materials) geometry, lighting, materials) Unit 1: Transformations Weeks 1,2. Ass 1 due Sep 23 Unit 3: OpenGL Weeks 5-7. Unit 2: Spline Curves Ass 3 due Nov 9 Weeks 3,4. Ass 2 due Oct 7 Midterm on units 1-3: Oct 27 Demo: Surreal (HW 3) Demo: Surreal (HW 3) Methodology for Lecture Methodology for Lecture � This unit different from others in course � Other units stress mathematical understanding � This stresses implementation details and programming � I am going to show (maybe write) actual code � Same code (with comments) available online to help you understand how to implement basic concepts � I hope the online code helps you understand HW 3 better � ASK QUESTIONS if confused!! � Simple demo opengl1\opengl1-orig.exe � This lecture deals with very basic OpenGL setup. Next 2 lectures will likely be more interesting

  2. Outline Introduction to OpenGL Outline Introduction to OpenGL � Basic idea about OpenGL � OpenGL is a graphics API � Software library � Basic setup and buffers � Layer between programmer and graphics hardware (and software) � Matrix modes � OpenGL can fit in many places � Window system interaction and callbacks � Between application and graphics system � Between higher level API and graphics system � Drawing basic OpenGL primitives Best source for OpenGL is the redbook. Of course, this is more a reference manual than a textbook, and you are better off implementing rather reading end to end. Though if you do have time, the book is actually quite readable Programmer’s View Programmer’s View OpenGL Rendering Pipeline OpenGL Rendering Pipeline Application Geometry Vertices Primitive Operations Fragment Scan Framebuffer Application Graphics Package Operations Conversion OpenGL Application Programming Interface Pixel Texture Images Operations Memory Hardware and software Many operations controlled by state (projection matrix, transformation matrix, color etc.) Output Device Input Device Input Device OpenGL is a large state machine Why OpenGL? Why OpenGL? Outline Outline � Fast � Basic idea about OpenGL � Simple � Basic setup and buffers � Window system independent � Matrix modes � Supports some high-end graphics features � Window system interaction and callbacks � Geometric and pixel processing � Drawing basic OpenGL primitives � Standard, available on many platforms

  3. Buffers and Window Interactions Buffers and Window Interactions Basic setup code (you will likely copy) Basic setup code (you will likely copy) int main(int argc, char** argv) { � Buffers: Color (front, back, left, right), depth (z), glutInit(&argc, argv); accumulation, stencil. When you draw, you right to // Requests the type of buffers (Single, RGB). some buffer (most simply, front and depth) // Think about what buffers you would need... glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); � No window system interactions (for portability) glutInitWindowSize (500, 500); � But can use GLUT (or Motif, GLX, Tcl/Tk) glutInitWindowPosition (100, 100); glutCreateWindow ("Simple Demo"); � Callbacks to implement mouse, keyboard interaction init (); // Always initialize first // Now, we define callbacks and functions for various tasks. glutDisplayFunc(display); glutReshapeFunc(reshape) ; glutKeyboardFunc(keyboard); glutMouseFunc(mouse) ; glutMotionFunc(mousedrag) ; glutMainLoop(); // Start the main code return 0; /* ANSI C requires main to return int. */ } Outline Outline Viewing in OpenGL Viewing in OpenGL � Basic idea about OpenGL � Viewing consists of two parts � Object positioning: model view transformation matrix � Basic setup and buffers � View projection: projection transformation matrix � OpenGL supports both perspective and orthographic viewing � Matrix modes transformations � Window system interaction and callbacks � OpenGL’s camera is always at the origin, pointing in the – z direction � Drawing basic OpenGL primitives � Transformations move objects relative to the camera Basic initialization code Basic initialization code Outline Outline #include <GL/glut.h> � Basic idea about OpenGL #include <stdlib.h> int mouseoldx, mouseoldy ; // For mouse motion � Basic setup and buffers GLdouble eyeloc = 2.0 ; // Where to look from; initially 0 -2, 2 � Matrix modes void init (void) { � Window system interaction and callbacks /* select clearing color */ glClearColor (0.0, 0.0, 0.0, 0.0); � Drawing basic OpenGL primitives /* initialize viewing values */ glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Think about this. Why is the up vector not normalized? glMatrixMode(GL_MODELVIEW) ; glLoadIdentity() ; gluLookAt(0,-eyeloc,eyeloc,0,0,0,0,1,1) ; }

  4. Window System Interaction Basic window interaction code Window System Interaction Basic window interaction code /* Defines what to do when various keys are pressed */ � Not part of OpenGL void keyboard (unsigned char key, int x, int y) { � Toolkits (GLUT) available switch (key) { case 27: // Escape to quit exit(0) ; � Callback functions for events break ; default: � Keyboard, Mouse, etc. break ; � Open, initialize, resize window } } � Similar to other systems (X, Java, etc.) /* Reshapes the window appropriately */ � Our main func included void reshape(int w, int h) { glutDisplayFunc(display); glViewport (0, 0, (GLsizei) w, (GLsizei) h); glutReshapeFunc(reshape) ; glMatrixMode(GL_PROJECTION); glutKeyboardFunc(keyboard); glLoadIdentity(); glutMouseFunc(mouse) ; glutMotionFunc(mousedrag) ; gluPerspective(30.0, (GLdouble)w/(GLdouble)h, 1.0, 10.0) ; } Mouse motion Mouse motion (demo Mouse drag (demo Mouse drag (demo opengl1 orig.exe ) ) (demo opengl1 orig.exe ) ) opengl1\ \opengl1 opengl1- -orig.exe opengl1\ \opengl1 opengl1- -orig.exe /* Defines a Mouse callback to zoom in and out */ /* This is done by modifying gluLookAt */ /* The actual motion is in mousedrag */ void mousedrag(int x, int y) { /* mouse simply sets state for mousedrag */ void mouse(int button, int state, int x, int y) int yloc = y - mouseoldy ; // We will use the y coord { to zoom in/out if (button == GLUT_LEFT_BUTTON) { eyeloc += 0.005*yloc ; // Where do we look from if (state == GLUT_UP) { if (eyeloc < 0) eyeloc = 0.0 ; // Do Nothing ; mouseoldy = y ; } else if (state == GLUT_DOWN) { /* Set the eye location */ mouseoldx = x ; mouseoldy = y ; // so we can move wrt x , y glMatrixMode(GL_MODELVIEW) ; } } glLoadIdentity() ; else if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) gluLookAt(0,-eyeloc,eyeloc,0,0,0,0,1,1) ; { // Reset gluLookAt eyeloc = 2.0 ; glutPostRedisplay() ; glMatrixMode(GL_MODELVIEW) ; } glLoadIdentity() ; gluLookAt(0,-eyeloc,eyeloc,0,0,0,0,1,1) ; glutPostRedisplay() ; } } Outline Outline OpenGL Primitives OpenGL Primitives � Basic idea about OpenGL � Basic setup and buffers Lines Points Polygon � Matrix modes � Window system interaction and callbacks Quad Triangle � Drawing basic OpenGL primitives Quad Strip Triangle Strip Triangle Fan

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend