simple basic examples and skeleton programs for opengl n.
Skip this Video
Loading SlideShow in 5 Seconds..
Simple Basic Examples and Skeleton Programs for OpenGL PowerPoint Presentation
Download Presentation
Simple Basic Examples and Skeleton Programs for OpenGL

Simple Basic Examples and Skeleton Programs for OpenGL

251 Vues Download Presentation
Télécharger la présentation

Simple Basic Examples and Skeleton Programs for OpenGL

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Simple Basic Examples and Skeleton Programs for OpenGL

  2. OpenGL Programming • OpenGL handles 2D and 3D rendering • The native windowing system handles the management of windows. These operations consist of Opening, closing, and displaying User interface components and widgets Event Handling • The GLUT library provides a portable mechanism for window management with OpenGL programs • Non-portable mechanisms include GLX for X Windows implementations and WGL for Windows NT.

  3. OpenGL Programming #ifdef __FLAT__ #include <windows.h> #endif #include <gl/glut.h> // The initialization function void init(void) { // initialization code goes here // examples of initialization include: setting window size, display modes // color mode, shade model etc. }

  4. OpenGL Programming // The display callback function void display(void) { // display callback called by the OpenGL event handler goes here. // This callback is called every time the main window requires redrawing } // The main function int main(int argc, char** argv) { glutInit(&argc, argv) ; // initialize the glut library init(); // perform all other initialization glutDisplayFunc(display) ; // register the display callback function glutMainLoop() ; // enter the GLUT event processing loop return 0 ; }

  5. Mainline Routine Functions • int glutInit( int *argcp, char **argv) - Initializes the Glut library and parses command line for GLUT library options. • void glutDisplayFunc( void (*func)(void)) - Registers the display function with the glut event handler. The specified display function is called when the window is exposed or redisplayed. • void glutMainLoop(GLvoid) - Places the program in the GLUT event processing loop from which the program can invoke callback functions. This must be the last runction in the mainline program precedding the return().

  6. Initialization Functions • void glutInitWindowSize( int width, int height) • Controls and sets the width and height of the window in pixels. Window borders are not counted. • void glutInitWindowPosition(int x, int y) • Sets the position of the window to x and y which are specified in pixels relative to the upper-left hand corner of the screen. • int glutGet( GLenum state ) • Retrieves state information about the GLUT library. • For our example, we are interested in obtaining the size of the display (GLUT_SCREEN_WIDTH and GLUT_SCREEN_HEIGHT)

  7. Initialization Functions • void glutInitDisplay Mode(GLenum mode) • Configure a windows display mode. Display modes define the type of buffer utilized. Examples are • GLUT_RGBA Request RGBA window (default) • GLUT_RGB An alias for GLUT-RGBA • GLUT_INDEX Request color-index window • GLUT_SINGLE Request signle-buffered window (default) • GLUT_DOUBLE Request double-buffered window • GLUT_DEPTH Request accompanying depth buffer (deafult) • GLUT_STENCEL Request accompanying stencil buffer • GLUT_ACCUM Request accompanying accumulation buffer • GLUT_ALPHA Request accompanying alpha destination buffer • GLUT_MULTISAMPLE Request a window with multi-sampling support • GLUT_STEREO Request a window with stereo support • GLUT_LUMINANCE Request a window with luminance color model

  8. Initialization Functions • int glutCreateWindow( char *title) • Creates a window a returns a unique identifier for the new window. Title is displayed in the window's title bar. • GLvoid glClearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) • Sets the current clear color which is used to clear the collor buffer when glClear() is called with an argument of GL_COLOR_BUFFER_BIT • void glShadeModel(eGLenum mode) • Sets the current shading model to either GL_SMOOTH or GL_FLAT. GL_FLAT has only a single color per polygon used. GL_SMOOTH the color of a polygon is interpolated among the colors of its vertices. • GLvoid glClear(GL_bitfield mask) • Called whenever the window is to be cleared. The mask is usually set to GL_COLOR_BUFFER_BIT. This function will paint the entire window with the current clear color.

  9. First Complete OpenGL Program • Creates a graphics window whose height and width are a third of the total display screen's height and width, places the upper left-hand corner of the window at the very upper left hand corner of the display, requests a double-buffered, RGBA color mode window, sets the clear color to magenta and the shade model to flat. • Displays a wire cube in the window.

  10. First Complete OpenGL Program ifdef __FLAT__ #include <windows.h> #endif #include <gl/glut.h> // The initialization function void init(void) { glutInitWindowSize( glutGet( GLUT_SCREEN_WIDTH)/3, glutGet( GLUT_SCREEN_HEIGHT)/3 ); glutInitWindowPosition( 0, 0 ); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutCreateWindow("Second Chapter - Opening an OpenGL Window") ; glClearColor(1.0, 0.0, 1.0, 0.0) ; glShadeModel(GL_FLAT) ; }

  11. First Complete OpenGL Program // The display callback function void display(void) { glClear(GL_COLOR_BUFFER_BIT) ; glutWireCube(1.0); glutSwapBuffers(); } // The main function int main(int argc, char** argv) { glutInit(&argc, argv) ;   init(); glutDisplayFunc(display) ; glutMainLoop() ;   return 0 ; }

  12. First Complete OpenGL Program