110 likes | 268 Views
OPEN GL. Install GLUT. Download package di sini http://nulis.net46.net/glut.3.7.6+.DevPak Dari devcpp , buka Tools-> PackageManager ->Install browse dan arahkan ke file package glut yang sudah didownload. Membuat Project Baru.
E N D
Install GLUT • Download package disinihttp://nulis.net46.net/glut.3.7.6+.DevPak • Dari devcpp, buka Tools->PackageManager->Install browse danarahkanke file package glut yang sudahdidownload
Membuat Project Baru • File->New->Project->Pilih tab Multimedia -> pilih glut -> tulisnama project • Cara compile dan run samasepertibiasa
(0,0.7) (-0.7,-0.7) (0.7,-0.7) 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 Green Triangle
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 glutwww.xmission.com/~nate/glut.html • The layout of a simple program OpenGL Utility Toolkit library for window operations #include <GL/glut.h> // glut.h includes gl.h and glu.h void display() { . . . } void init() { . . . } int main( intargc, char **argv) { . . . } An OpenGL utility library built on top of gl
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 }
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. 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); }
int main( intargc, char **argv) { glutInit( &argc, argv); // Initialize GLUT function callings // Set window size (width, height) in number of pixelsglutInitWindowSize( 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) }
Event Queue • 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 <stop> event is processed. Extract an event Process the event Event insertion: Window creation, moving, maximizing, closing, etc.
Clicking button glutInit(); Functions that specify a new window init(); glutDisplayFunc(display); Event Queue display() glutMainLoop() stop • Execution sequence At first, glutMainLoop() picks up a <window creation> event from the queue, creates the window, and calls display(). When the button of the window is clicked, a <stop> event is inserted in the queue. When this event is processed, the execution terminates start main()