1 / 11

OPEN GL

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.

yorick
Télécharger la présentation

OPEN GL

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OPEN GL

  2. 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

  3. Membuat Project Baru • File->New->Project->Pilih tab Multimedia -> pilih glut -> tulisnama project • Cara compile dan run samasepertibiasa

  4. (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

  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 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

  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. 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); }

  8. 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) }

  9. 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.

  10. 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()

  11. Green Triangle

More Related