OPEN GL Install GLUT Download package di sini

  • Slides: 11
Download presentation
OPEN GL

OPEN GL

Install GLUT • Download package di sini http: //nulis. net 46. net/glut. 3. 7.

Install GLUT • Download package di sini http: //nulis. net 46. net/glut. 3. 7. 6+. Dev. Pak • Dari devcpp, buka Tools->Package. Manager>Install browse dan arahkan ke file package glut yang sudah didownload

Membuat Project Baru • File->New->Project->Pilih tab Multimedia -> pilih glut -> tulis nama project

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

Open. GL programming • Open. GL ( gl ) is a common graphics library

Open. GL programming • Open. GL ( gl ) is a common graphics library which provides functions for drawings and interactive input. • Open. GL 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 (0, 0. 7) (-0. 7, -0. 7) (0. 7, -0. 7) 4

Interaction with the Window System • Our graphics C++ programs are executed on PC

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 www. xmission. com/~nate/glut. html • The layout of a simple program Open. GL Utility Toolkit library for window operations #include <GL/glut. h> // glut. h includes gl. h and glu. h void display() {. . . } An Open. GL utility library built on top of gl void init() {. . . } int main( int argc, char **argv) {. . . } 5

void display() { gl. Clear( GL_COLOR_BUFFER_BIT); // Clear the frame buffer gl. Color 3

void display() { gl. Clear( GL_COLOR_BUFFER_BIT); // Clear the frame buffer gl. Color 3 f( 0. 0, 1. 0, 0. 0); // Set current color to green gl. Begin( GL_POLYGON); gl. Vertex 2 f( -0. 7, -0. 7); gl. Vertex 2 f( 0, 0. 7); gl. End(); // Draw the triangle gl. Flush(); // Force to display the new drawings immediately } 6

 • In Window environment, display() is invoked when the output window is created,

• 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() { gl. Clear. Color( 0. 0, 0. 0); // Set the clear color to black // Specify the boundaries of the viewing window gl. Matrix. Mode(GL_PROJECTION); gl. Load. Identity(); glu. Ortho 2 D(-1. 0, 1. 0); // The para are: (left, right, bottom, top) } gl. Matrix. Mode(GL_MODELVIEW); 7

int main( int argc, char **argv) { glut. Init( &argc, argv); // Initialize GLUT

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

 • Event Processing glut. Main. Loop() is the function that drives the major

• Event Processing glut. Main. Loop() is the function that drives the major operations in all our graphics programs. The function iterates indefinitely. In each iteration, it check whethere 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 Queue Event insertion: Window creation, moving, maximizing, closing, etc. 9

 • Execution sequence At first, glut. Main. Loop() picks up a <window creation>

• Execution sequence At first, glut. Main. Loop() 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 glut. Init(); Clicking button Functions that specify a new window start main() init(); glut. Display. Func( display); glut. Main. Loop() Event Queue display() stop 10

Green Triangle 11

Green Triangle 11