Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intro to OpenGL (Version 2) Geb Thomas. Setting Up GLUT You will need GLUT for opening windows We can use the version made by Nate Robins: –http://www.xmission.com/~nate/glut.htmlhttp://www.xmission.com/~nate/glut.html.

Similar presentations


Presentation on theme: "Intro to OpenGL (Version 2) Geb Thomas. Setting Up GLUT You will need GLUT for opening windows We can use the version made by Nate Robins: –http://www.xmission.com/~nate/glut.htmlhttp://www.xmission.com/~nate/glut.html."— Presentation transcript:

1 Intro to OpenGL (Version 2) Geb Thomas

2 Setting Up GLUT You will need GLUT for opening windows We can use the version made by Nate Robins: –http://www.xmission.com/~nate/glut.htmlhttp://www.xmission.com/~nate/glut.html Download the.zip file, unzip it and store it in a convenient directory on your drive I stored everything in h:/documents/glut

3 Setting up the Compiler You need to tell the compiler where the header file is. One way is instead of using #include, which assumes that the glut header file is in a standard location, you can use #include “h:/documents/glut/glut.h”. Then the compiler will look at this location. An easy way to handle the.dll file is to copy it to the location of your executable file, perhaps: H:\testProgram\debug

4 Setting up a Window with GLUT Learn about glut here: http://www.opengl.org/developers/documenta tion/glut/spec3/spec3.html glutInit(argc, argv); /* initialize glut */ glutInitWindowSize(int width, int height); –/* set the window size. 300x300 by default */ glutInitWindowPosition(x, y); –/* set the window position, default –1, -1, which means let the operating system decide */

5 glutInitDisplayMode Use glutInitDisplayMode( GLUT_RGBA | GLUT_SINGLE | GLUT_DEPTH ) Provides RGB color rather than indexed color A single frame buffer, rather than double buffering A depth buffer

6 Opening a Window int glutCreateWindow(char *name); Returns an integer identifier for the window No drawing is effective until glutMainLoop Several windows or subwindows may be opened. Windows may be resized or repositioned Window and display modes are system states that may be set and queried

7 The Main Loop Glut allows you to define callbacks: –void glutDisplayFunc(void (*func)(void)); –void glutReshapeFunc(void (*func)(int width, int height)); –void glutKeyboardFunc(void (*func)(unsigned char key, int x, int y)); –void glutMouseFunc(void (*func)(int button, int state, int x, int y)); void glutMainLoop(void);

8 Working with OpenGL Get information from here (as well as other sources) –http://ask.ii.uib.no/ebt-bin/nph- dweb/dynaweb/SGI_Developer/OpenGL_PG/http://ask.ii.uib.no/ebt-bin/nph- dweb/dynaweb/SGI_Developer/OpenGL_PG/

9 Clearing the Window To clear the color to black (in RGBA mode) –glClearColor(0.0, 0.0, 0.0, 0.0); –glClear(GL_COLOR_BUFFER_BIT); To also clear the depth buffer you might use: –glClearColor(0.0, 0.0, 0.0, 0.0); –glClearDepth(1.0); –glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

10 Drawing Colors The current drawing color is a state. Change the state with glColor3f commands such as: –glColor3f(0.0, 0.0, 0.0); // black –glColor3f(1.0, 0.0, 0.0); //red –glColor3f(0.0, 1.0, 0.0); //green –glColor3f(1.0, 1.0, 0.0); //yellow –glColor3f(0.0, 0.0, 1.0); //blue –glColor3f(1.0, 0.0, 1.0); //magenta –glColor3f(0.0, 1.0, 1.0); //cyan –glColor3f(1.0, 1.0, 1.0); //white

11 Flushing the Buffers void glFlush(void); Sends a command to flush out the pipeline and finish the drawing void glFinish(void); Waits until drawing is completed, then returns

12 Setting up a Coordinate Frame void reshape (int w, int h) { glViewport (0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluOrtho2D (0.0, (GLdouble) w, 0.0, (GLdouble) h); }


Download ppt "Intro to OpenGL (Version 2) Geb Thomas. Setting Up GLUT You will need GLUT for opening windows We can use the version made by Nate Robins: –http://www.xmission.com/~nate/glut.htmlhttp://www.xmission.com/~nate/glut.html."

Similar presentations


Ads by Google