#ifdef __APPLE__ #include "OpenGL/gl.h" #include "OpenGL/glu.h" #include "GLUT/glut.h" #elif defined(_WIN32) #include #include "GL/glut.h" #else #include #include "GL/glut.h" #endif #include int main_window = 1; int position_x = 100; int position_y = 100; int width = 512; int height = 512; void idle(void) { if (glutGetWindow() != main_window) glutSetWindow(main_window); // just keep redrawing the scene over and over glutPostRedisplay(); } void keyboard(unsigned char key, int x, int y) { switch(key) { // quit case 27: case 'q': case 'Q': exit(0); break; } glutPostRedisplay(); } // the window has changed shapes, fix ourselves up void reshape(int x, int y) { width = x; height = y; printf("%d %d\n", x,y); glViewport(0,0,width,height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,width,0,height,-100,10000); glMatrixMode(GL_MODELVIEW); glutPostRedisplay(); } void drawPoint(int x, int y, float r, float g, float b) { //Set color glColor3f(r,g,b); //Set position glVertex3f(x,y,0); } void display( ) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //Clear background to black glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glBegin(GL_POINTS); for (int i=128; i<384; i++) { for (int j=128; j<384; j++) { //draw a white squared drawPoint(i,j, 1,1,1); } } glEnd(); glutSwapBuffers(); } int main(int argc, char* argv[]) { #ifdef __APPLE__ glutInit(&argc, argv); #endif // // create the glut window // glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH); glutInitWindowSize(width, height); glutInitWindowPosition(100,100); main_window = glutCreateWindow("Assignment 1"); glPointSize(1); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutReshapeFunc(reshape); glutIdleFunc(idle); glMatrixMode(GL_PROJECTION); glOrtho(0,width,0,height,-100,10000); glMatrixMode(GL_MODELVIEW); // give control over to glut glutMainLoop(); return 0; }