Presentation is loading. Please wait.

Presentation is loading. Please wait.

OPEN GL. Install GLUT Download package di sini Dari devcpp, buka Tools->PackageManager-

Similar presentations


Presentation on theme: "OPEN GL. Install GLUT Download package di sini Dari devcpp, buka Tools->PackageManager-"— Presentation transcript:

1 OPEN GL

2 Install GLUT Download package di sini Dari devcpp, buka Tools->PackageManager- >Install browse dan arahkan ke file package glut yang sudah didownload

3 Membuat Project Baru File->New->Project->Pilih tab Multimedia -> pilih glut -> tulis nama project Cara compile dan run sama seperti biasa

4 4 OpenGL programming OpenGL ( gl ) is a common graphics library which provides functions for drawings and interactive input. OpenGL is accessible via C++ programs The Visual C++ platform is used for program development in this course A function that draws a green triangle (0.7,-0.7)(-0.7,-0.7) (0,0.7) Green Triangle

5 5 Interaction with the Window System Our graphics C ++ programs are executed on PC and interact with the window OS using functions provided in the library glut The layout of a simple program #include // glut.h includes gl.h and glu.h void display() {... } void init() {... } int main( int argc, char **argv) {... } An OpenGL utility library built on top of gl OpenGL Utility Toolkit library for window operations

6 6 void display() { glClear( GL_COLOR_BUFFER_BIT); // Clear the frame buffer glColor3f( 0.0, 1.0, 0.0); // Set current color to green glBegin( GL_POLYGON); // Draw the triangle glVertex2f( -0.7, -0.7); glVertex2f( 0.7, -0.7); glVertex2f( 0, 0.7); glEnd(); glFlush(); // Force to display the new drawings immediately }

7 7 void init() { glClearColor( 0.0, 0.0, 0.0, 0.0); // Set the clear color to black // Specify the boundaries of the viewing window glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(-1.0, 1.0, -1.0, 1.0); // The para are: (left, right, bottom, top) glMatrixMode(GL_MODELVIEW); } In Window environment, display() is invoked when the output window is created, or is re-drew after moving or maximizing. Usually, we need another function, init(), that specifies permanent features of the drawings. This function is invoked only once in the beginning.

8 8 int main( int argc, char **argv) { glutInit( &argc, argv); // Initialize GLUT function callings // Set window size (width, height) in number of pixels glutInitWindowSize( 400, 400); // Set window position, from the left and top of the screen, glutInitWindowPosition( 200, 100); // in numbers of pixels // Specify a window creation event glutCreateWindow( "Green Triangle"); // Specify the drawing function that is called when the window glutDisplayFunc( display); // is created or re-drew init(); // Invoke this function for initialization glutMainLoop(); // Enter the event processing loop return 0; // Indicate normal termination // (Required by ANSI C) }

9 9 Event Processing glutMainLoop() is the function that drives the major operations in all our graphics programs. The function iterates indefinitely. In each iteration, it check whether there are any events in the queue. If yes, it removes and processes the first event. It terminates the execution of the program when a event is processed. Event Queue Extract an event Process the event Event insertion: Window creation, moving, maximizing, closing, etc.

10 10 Execution sequence At first, glutMainLoop() picks up a event from the queue, creates the window, and calls display(). When the  button of the window is clicked, a event is inserted in the queue. When this event is processed, the execution terminates main() start glutMainLoop() init(); glutDisplayFunc( display); glutInit(); Event Queue Functions that specify a new window display() Clicking  button stop

11 11 Green Triangle


Download ppt "OPEN GL. Install GLUT Download package di sini Dari devcpp, buka Tools->PackageManager-"

Similar presentations


Ads by Google