1 / 47

Today …

Today …. The rendering pipeline in detail What is OpenGL First OpenGL program Details about modeling. Rasterization & Clipping & Display. Illumination. Projection. . L. N. . 1 R. . 1 V. Basic Rendering Pipeline. ViewingTransformation (WS -> CS). Modeling Transformation

Download Presentation

Today …

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Today … • The rendering pipeline in detail • What is OpenGL • First OpenGL program • Details about modeling

  2. Rasterization & Clipping& Display Illumination Projection  L N  1R  1V Basic Rendering Pipeline ViewingTransformation (WS -> CS) Modeling Transformation (OS -> WS) Visibility Culling Database of 3D models

  3. OpenGL and GLUT Overview • What is OpenGL & what can it do for me? • OpenGL in windowing systems • Why GLUT • A GLUT program template

  4. What is a “library”. • Static • Dynamic

  5. Relationship between OpenGL GLU and windowing APIs. • OpenGL applications use the window system’s window, input, and event mechanism • GLU supports quadrics, NURBS, complex polygons, matrix utilities, and more

  6. What Is OpenGL? • Graphics rendering API • high-quality color images composed of geometric and image primitives • window system independent • operating system independent

  7. GLU GL GLUT OpenGL Library Functions GL library contains all primitive and attribute functions associated with OpenGL GLU library builds on the GL library to include more complex primitives (e.g. spheres) and convenience functions GLUT (GL Utility Toolkit) includes functions to interface with the native window system, including window creation, management of input devices

  8. Related APIs • AGL, GLX, WGL • glue between OpenGL and windowing systems • GLU (OpenGL Utility Library) • part of OpenGL • NURBS, tessellators, quadric shapes, etc. • GLUT (OpenGL Utility Toolkit) • portable windowing API • not officially part of OpenGL

  9. OpenGL and Related APIs application program OpenGL Motif widget or similar GLUT GLX, AGLor WGL GLU GL X, Win32, Mac O/S software and/or hardware

  10. Per Vertex Operations & Primitive Assembly Polynomial Evaluator DisplayList Per Fragment Operations Frame Buffer CPU Rasterization Texture Memory Pixel Operations OpenGL Architecture

  11. Features of OpenGL • Delivers fast and complete 3D hardware acceleration • makes real-time 3D effects possible • designed to support future innovations in software and hardware • Available on many platforms • Stable

  12. OpenGL as a Renderer • Geometric primitives • points, lines and polygons • Image Primitives • images and bitmaps • separate pipeline for images and geometry • linked through texture mapping • Rendering depends on state • colors, materials, light sources, etc.

  13. Other issues • Rendering acceleration (rasterization, texture map, spacial subdivision, collision detection, progressive rendering, view dependent rendering, image-based rendering,…) • Color, Texture, Anti-aliasing • Animation or simulation

  14. Student 007: “I am dying to see an OpenGL program !…” Prof: Be patient, it is only few more block(diagram)s away !!

  15. Block Diagram

  16. Preliminaries • Headers Files • #include <GL/gl.h> • #include <GL/glu.h> • #include <GL/glut.h> • Libraries • Enumerated Types • OpenGL defines numerous types for compatibility • GLfloat, GLint, GLenum, etc.

  17. GLUT Basics • Application Structure • Configure and open window • Initialize OpenGL state • Register input callback functions • render • resize • input: keyboard, mouse, etc. • Enter event processing loop

  18. Sample Program – draw()function void drawScene(void) { // Clear the rendering window glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Set drawing color to white glColor3f( 1.0, 1.0, 1.0 ); // Draw triangle glBegin(GL_TRIANGLES); glColor3f( 1.0, 0.0, 0.0 ); glVertex2f( 1.0, 1.0 ); glVertex2f( 2.0, 1.0 ); glVertex2f( 2.0, 2.0 ); glEnd(); // Flush the pipeline. (Not usually necessary.) glFlush(); }

  19. OpenGL Command Formats glVertex3fv( v ) Data Type Vector Number of components b - byte ub - unsigned byte s - short us - unsigned short i - int ui - unsigned int f - float d - double omit “v” for scalar form glVertex2f( x, y ) 2 - (x,y) 3 - (x,y,z) 4 - (x,y,z,w)

  20. Specifying Geometric Primitives • Primitives are specified using glBegin( primType ); glEnd(); • primType determines how vertices are combined • GLfloat red, greed, blue; • Glfloat coords[3]; • glBegin( primType ); • for ( i = 0; i < nVerts; ++i ) { • glColor3f( red, green, blue ); • glVertex3fv( coords ); • } • glEnd();

  21. OpenGL Command Syntax • Function calls: glXxxxx[type] ( [args] ) • Example: glVertex2f (1.0, 2.0); • Defined constants: GL_XXXXXXXXXX • Example: GL_COLOR_BUFFER_BIT • Type definition: GLxxxxxxx • Example: GLfloat

  22. Command Suffixes/ Argument Data Types

  23. O I Shared Namespace Model Model Application Function Calls } Run in same process Graphics Lib. OS glFlush(); unnecessary

  24. Client-Server Model: Model Application O Function Calls Graphics Server Graphics Lib. I OS OS Network Protocol glFlush(); May be necessary

  25. Per Vertex Operations & Primitive Assembly Polynomial Evaluator DisplayList Per Fragment Operations Frame Buffer CPU Rasterization Texture Memory Pixel Operations OpenGL Architecture

  26. State Management and Drawing in OpenGL

  27. OpenGL Initialization • Set up whatever state you’re going to use void init( void ) { glClearColor( 0.0, 0.0, 0.0, 1.0 ); glClearDepth( 1.0 ); glEnable( GL_LIGHT0 ); glEnable( GL_LIGHTING ); glEnable( GL_DEPTH_TEST ); }

  28. GLUT Callback Functions • Routine to call when something happens • window resize or redraw • user input • animation • “Register” callbacks with GLUT glutDisplayFunc( display ); glutIdleFunc( idle ); glutKeyboardFunc( keyboard );

  29. A Typical Event-Driven Program Initialization Main Loop Event Handler Background Processing Procedure Input Processing Procedures

  30. Route messages to the application

  31. GLUT Event Processing No Event in Queue Call Idle Function Yes Call Function n Pop Event From Queue Call Function n Call Function n Call Function n Call Function n Call Function n Switch on Event Type

  32. Callbacks Event Type “Registered” Function Event A m1, m2 function_A(m1, m2) Event B function_B( ) Event C function_C( ) Event D Event E Event F No Event Idle function( ) NB: Function parameters must match measures contained in associated event.

  33. Display Event Trigger: GLUT determines that the window needs to be redisplayed. A display event is generated when the window is first drawn. Callback function form: void display(); Registration: glutDisplayFunc(display); A display callback function must be registered for each window.

  34. GLUT Mouse Event Trigger: Any mouse button is depressed or released. Callback function form: void mouse_callback_func(int button, int state, int x, int y); Registration: glutMouseFunc(mouse_callback_function);

  35. GLUT Defined Mouse Constants GLUT_LEFT_BUTTON GLUT_MIDDLE_BUTTON GLUT_RIGHT_BUTTON GLUT_UP GLUT_DOWN Systems with only one mouse button can only generate a GLUT_LEFT_BUTTON callback.

  36. GLUT Reshape Event Trigger: Active window is resized Callback function form: void reshape_func(GLsizei w, GLsizei h); Registration: glutReshapeFunc(reshape_func);

  37. GLUT Move Event Trigger: The mouse is moved while one or more mouse buttons are pressed. Callback function form: void motion_func(int x, int y); Registration: glutMotionFunc(motion_func);

  38. GLUT Keyboard Event Trigger: Any key is depressed. Callback function form: void keyboard_function(unsigned char key, int x, int y); Registration: glutKeyboardFunc(keyboard_function);

  39. Idle Callbacks • Use for animation and continuous update glutIdleFunc( idle ); void idle( void ) { t += dt; glutPostRedisplay(); }

  40. Other Defined Events in GLUT glutPassiveMotionFunc glutVisibilityFunc glutEntryFunc glutSpecialFunc glutSpaceballMotionFunc glutSpaceballRotateFunc glutSpaceballButtonFunc glutButtonBoxFunc glutDialsFunc glutTabletMotionFunc glutTabletButtonFunc glutMenuStatusFunc

  41. Simple GLUT Window Management Functions glutInit(int *argc, char** argv); Initializes a window session. glutCreateWindow(char *name); Creates a window with title *name. glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); Sets the display mode to single buffered and RGB color. glutInitWindowSize (GLsizei h, GLsizei w); Sets initial window size to h x w. glutInitWindowPosition(x,y); Sets initial window position to (x, y).

  42. TA help is there, but use “Help” and try to help yourselves !! • Show simple demo program

  43. OpenGL Lib GDI Processor OpenGL in MS Windows GL Commands Graphics Hardware GDI – Graphics Device Interface (Windows-specific)

  44. Basic Program Skeleton • Header files, Global variables • Rendering initialization • Keyboard / Mouse functions • Drawing / animation • Window resizing • Idle function • main()

  45. Try this … Draw a red line in a window with black background Try changing line thickness Change color combination What if you want a regular triangle as against a “filled” one Now try drawing various figures from the library Try modeling concave polygons

More Related