PROGRAM 7 SQUARE E Angel include GLglut h

  • Slides: 6
Download presentation
PROGRAM 7 SQUARE E. Angel

PROGRAM 7 SQUARE E. Angel

 • • • • #include <GL/glut. h> #include <stdlib. h> GLsizei wh =

• • • • #include <GL/glut. h> #include <stdlib. h> GLsizei wh = 500, ww = 500; GLfloat size = 3. 0; void draw. Square(int x, int y) { y=wh-y; gl. Color 3 ub( (char) rand()%256, (char) rand()%256); gl. Begin(GL_POLYGON); gl. Vertex 2 f(x+size, y+size); gl. Vertex 2 f(x-size, y-size); gl. Vertex 2 f(x+size, y-size); gl. End(); gl. Flush(); }

 • void myinit(void) • { • gl. Viewport(0, 0, ww, wh); • gl.

• void myinit(void) • { • gl. Viewport(0, 0, ww, wh); • gl. Matrix. Mode(GL_PROJECTION); • gl. Load. Identity(); • gl. Ortho(0. 0, (GLdouble) ww , 0. 0, (GLdouble) wh , 1. 0); • • • gl. Clear. Color (0. 0, 1. 0); gl. Clear(GL_COLOR_BUFFER_BIT); gl. Flush(); • • } glut. Reshape. Func(my. Reshape);

 • void mouse(int btn, int state, int x, int y) • { •

• void mouse(int btn, int state, int x, int y) • { • if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN) exit(0); • } • • • void display(void) {} int main(int argc, char** argv) { glut. Init(&argc, argv); glut. Init. Display. Mode (GLUT_SINGLE | GLUT_RGB); glut. Create. Window("square"); myinit (); glut. Reshape. Func (my. Reshape); glut. Mouse. Func (mouse); glut. Motion. Func(draw. Square); //當按住滑鼠按鍵在視窗內移動, 於是此函式 便會呼叫draw. Square這個函式 • glut. Display. Func(display); • glut. Main. Loop(); • }