Introduction to GL Geb Thomas Example Code int
Introduction to GL Geb Thomas
Example Code int main(int argc, char **argv) { glut. Init(&argc, argv); glut. Init. Display. Mode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); void display(void) { gl. Clear( GL_COLOR_BUFFER_BIT); gl. Color 3 f(0. 0, 1. 0, 0. 0); glut. Init. Window. Position(100, 100); glut. Init. Window. Size(300, 300); glut. Create. Window ("square"); gl. Begin(GL_POLYGON); gl. Vertex 3 f(2. 0, 4. 0, 0. 0); gl. Vertex 3 f(8. 0, 4. 0, 0. 0); gl. Clear. Color(0. 0, 0. 0); gl. Matrix. Mode(GL_PROJECTION); gl. Load. Identity(); gl. Ortho(0. 0, 10. 0, -1. 0, 1. 0); glut. Display. Func(display); glut. Main. Loop(); return 0; gl. Vertex 3 f(8. 0, 6. 0, 0. 0); gl. Vertex 3 f(2. 0, 6. 0, 0. 0); gl. End(); gl. Flush(); }
What’s Going On? n Open. GL – The graphics calls n GLUT – Utility for opening windows n Both have header files and libraries n Opengl 32. dll, glut 32. dll n opengl. h, glut 32. h
Using GLUT To Initialize the Display glut. Init(&argc, argv); glut. Init. Display. Mode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
Setting Up and Opening the Window glut. Init. Window. Position(100, 100); glut. Init. Window. Size(300, 300); glut. Create. Window ("square");
Setting Up the Matrices gl. Clear. Color(0. 0, 0. 0); gl. Matrix. Mode(GL_PROJECTION); gl. Load. Identity(); gl. Ortho(0. 0, 10. 0, -1. 0, 1. 0);
Defining the Drawing Routine glut. Display. Func(display);
Drawing Some Stuff void display(void) { gl. Clear( GL_COLOR_BUFFER_BIT); gl. Color 3 f(0. 0, 1. 0, 0. 0); gl. Begin(GL_POLYGON); gl. Vertex 3 f(2. 0, 4. 0, 0. 0); gl. Vertex 3 f(8. 0, 6. 0, 0. 0); gl. Vertex 3 f(2. 0, 6. 0, 0. 0); gl. End(); gl. Flush(); }
Repeating the Loop glut. Main. Loop();
Details are Here www. opengl. org Good book: Open GL Programmer’s Guide
- Slides: 11