Computer Graphics Practical Lesson 1- Introduction to OpenGL Ayal Stein
Contact Info Teaching Assistance: Ayal Stein Phone number: 08-6477866 Course Site: www.cs.bgu.ac.il/~graph112 Email: ayals@cs.bgu.ac.il Room -102/37 Office Hours: ????
OpenGL OpenGL (Open Graphics Library) is cross-platform library to produce 2d and 3d graphics. It was developed during the 80’s until the early 90’s
Installing OpenGL Open the page “Files and Links” in the course site. Under section “Direct Download” – download the zip file from link “GLUT Binaries” Extract zip file into your code folder.
Installing OpenGL(cont’) The include directive #include <gl/glut.h> in our sample code is used when OpenGl is installed on system. To easily start working, you can replace the include directive to #include “glut.h” and copy glut files into project page: glut32.dll , glut32.lib , glut.h
OpenGL events OpenGL is windows based application. The flow of the program is based on events. We define functions to handle events.
Initialize Functions glutInit – GL defined function initialize the GL environment. glutCreateWindow – open the window glutInitDisplayMode – definitions like transparency and depth test. glutMainLoop –GUI main loop.
Events Functions Init function – function that opens the GL window and define events. glutDisplayFunc and glutIdleFunc – Draw function for window. glutReshapeFunc - Event for window resize.
Events Functions(cont’) glutMouseFunc – event for mouse click glutMotionFunc – event for mouse movements. glutKeyboardFunc – events for keyboard.
Drawing Basic Shapes Drawing 2 points: glBegin() - declare the shape type. glEnd() – end of drawing. Drawing 2 points: glBegin(GL_POINTS); glVertex3f(0.2f,0.8f,0.0f); glVertex3f(0.8f,0.2f,0.0f); glEnd();
Drawing Basic Shapes Basic types of shapes: GL_POINTS – draw isolated points GL_LINES – draw lines GL_TRIANGLES – triangles GL_QUADS – squares. And many more….
Design Pattern – State machine When working with GUI, we have state. In the first example, the first state draws a triangle. The second stage is drawing a square.
State Machine Example – MP3 Player
Design Pattern – State machine By mouse click, we switch to next state. There is a base class for state with virtual functions defined in it. Each state is represented by its own class. Each successor define its own functions.
First Assignment Expand the first example to draw a sixth shape. Draw a new shape in a new color. This is a warm up mission should not take you more than an hour. Submission is on next lesson.