/*********************************************************************** * hello.cpp (C) Elie De Brauwer, elie@de-brauwer.be * * this file originated from http://mindfuck.de-brauwer.be * * * * Compile with: g++ -Wall -lglut hello.cpp * ***********************************************************************/ #include #include // for exit() #include // also includes GL/gl.h and GL/glu.h using namespace std; typedef unsigned char uchar; // callback prototypes void disp(void); void reshape(int x, int y); void reshape1(int x, int y); void reshape2(int x, int y); void keyb(uchar key, int x, int y); //////////////////////////////// // main int main(int argc, char **argv){ glutInit(&argc, argv); // no double buffering since we don't need no animations glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE); glutInitWindowSize(400,400); glutCreateWindow("hello world"); // clear to black glClearColor(0.0,0.0,0.0,0.0); glutDisplayFunc(disp); glutKeyboardFunc(keyb); glutReshapeFunc(reshape); glutMainLoop(); return 0; } //////////////// // disp void disp(void){ glClear(GL_COLOR_BUFFER_BIT); // draw a white rectangle (only 3 parameters, no alpha) glColor3d(1.0,1.0,1.0); glRectf(25,25,75,75); // update the screen, not needed when using double // buffering and glutSwapBuffers() glFlush(); } ////////////////////////// // reshape void reshape(int x,int y){ glViewport(0,0,x,y); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0,100,0,100); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* this reshape maps the coordinates of the screen to [0,100] and [0,100] this can take everything out of proportion when resized */ } /////////////////////////// // reshape1 void reshape1(int x,int y){ glViewport(0,0,x,y); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0,x,0,y); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* this won't take anything out of proportion but it won't scale the image either the height and width of the window in pixels determine the size of the square */ } ////////////////////////// // reshape2 void reshape2(int x,int y){ if(x