Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics CS 385 February 7, 2005. Fundamentals of OpenGl and Glut Today we will go through the basics of a minimal OpenGl Glut project, explaining.

Similar presentations


Presentation on theme: "Computer Graphics CS 385 February 7, 2005. Fundamentals of OpenGl and Glut Today we will go through the basics of a minimal OpenGl Glut project, explaining."— Presentation transcript:

1 Computer Graphics CS 385 February 7, 2005

2 Fundamentals of OpenGl and Glut Today we will go through the basics of a minimal OpenGl Glut project, explaining the role of each piece of the code.

3 #include Includes gl.h and glu.h. Contains all the Glut constant definitions Contains all the Glut function declarations Put glut.h in the GL sub-directory of your compilers include directory

4 main The main function takes two (optional) parameters int argc char* argv[] or char** argv argc is the number of parameters passed to the main function argv[] is an array of strings containing those parameters

5 glutInit glutInit initializes the GLUT library. It takes two parameters from the main function. The declaration of glutInit is void glutInit(int *argcp, char **argv); In addition to initializing the GLUT library, glutInit will negociate a session with the window system.

6 glutCreateWindow Creates a top-level window Declaration: int glutCreateWindow(char *name); name is registered with the windowing system and also is used as a lable for the window. The integer returned is an id to identify the window in a multi-window situation.

7 glutDisplayFunc glutDisplayFunc sets the display callback for the current window. Declaration void glutDisplayFunc(void (*func)(void)); This might look odd to you. Let’s review function pointers.

8 Function Pointers In C++ you cannot pass a function in as a parameter to another function. Instead, C++ allows you to pass in a pointer to the function. Lets review function pointers. Here is and example:

9 #include using namespace std; void call(int (*func)(int i), int i) { cout << func(i) << endl; } int square(int i) { return i*i; } int main() { call(square, 3); return 0; }

10 init() The init() function is not a GLUT or GL function. It is our own customed made function which contains the code to set up the OpenGL environment. Typically, in this function we pu these lines like these glClearColor(1.0,1.0,1.0,1.0); glColor3f(1.0,0.0,0.0);

11 glutMainLoop() Declaration void glutMainLoop(void); glutMainLoop enters the GLUT event processing loop. This routine should be called at most once in a GLUT program. Once called, this routine will never return. It will call as necessary any callbacks that have been registered

12 glPointSize Declaration void glPointSize( GLfloat size ) specify the diameter of rasterized points in pixels

13 Lines A Simple line glBegin(GL_LINES); glVertex2f(-1.0,0.0); glVertex2f(-1.-1.0); glEnd();

14 Line Width Declaration void glLineWidth( GLfloat width ) Specifies the width of rasterized lines. The width is in pixels The default is one.

15 Lines GL_LINES works with pairs of consecutive points. If you give it three points, it will ignore the third. To connect three, use GL_LINE_STRIPS This has other properties too.

16 Line Strips glBegin(GL_LINE_STRIP); glVertex2f(-1.0,0.0); glVertex2f(0.0,-1.0); glVertex2f(1.0,0); glEnd();

17 Line Strips In general, GL_LINE_STRIP will start at the first point, draw a lines segment to the next point, then to the next all the way to the last point. It will NOT however, connect the last point back to the first point. For this you need GL_LINE_LOOP

18 Line Loops glBegin(GL_LINE_LOOP); glVertex2f(-.5.0,0.0); glVertex2f(0.0,-.5.0); glVertex2f(.5.0,0.0); glEnd();

19 Experiment glBegin( PARAMETER GOES HERE ); glVertex2f(-.5.0,0.0); glVertex2f(0.0,-.5.0); glVertex2f(.5.0,0.0); glEnd(); Try the above code with GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP AND GL_POLYGON

20 QUADS GL_QUADS takes points four at a time and makes quadrilaterals out of them.

21 TRIANGLES GL_TRIANGLES takes points three at a time and makes triangles out of them out of them.

22 Other Types Look in the book at GL_TRIANGLE_STRIP GL_QUAD_STRIP GL_TRIANGLE_FAN


Download ppt "Computer Graphics CS 385 February 7, 2005. Fundamentals of OpenGl and Glut Today we will go through the basics of a minimal OpenGl Glut project, explaining."

Similar presentations


Ads by Google