#include #include #include #include #define PIXEL_CENTER(x) ((long)(x) + 0.5) #define GAP 10 #define ROWS 3 #define COLS 4 #define OPENGL_WIDTH 48 #define OPENGL_HEIGHT 13 GLint windW, windH; GLint boxW, boxH; float color[3]; // Function called when window is resized. static void Reshape(int width, int height) { windW = (GLint)width; windH = (GLint)height; } // Function to catch keyboard input static void Key(unsigned char key, int x, int y) { switch (key) { case 27: exit(1); default: return; } glutPostRedisplay(); } // Function draws a series of points to the screen static void Point(void) { GLint i; glBegin(GL_POINTS); glColor3f(1.0,0.0,0.0); glVertex2i(0, 0); for (i = 1; i < windH/2; i++) { GLint j = i * 2; glVertex2i(-j, -j); glVertex2i(-j, 0); glVertex2i(-j, j); glVertex2i(0, j); glVertex2i(j, j); glVertex2i(j, 0); glVertex2i(j, -j); glVertex2i(0, -j); } glEnd(); } // Function draws a square to the screen static void PointBox(GLint xstart, GLint xend, GLint ystart, GLint yend, float* color) { GLint i,j; glBegin(GL_POINTS); glColor3f(color[0], color[1], color[2]); for (i = xstart; i <= xend; i++) { for (j = ystart; j <= yend; j++) { glVertex2i(i,j); } } glEnd(); } // Draw function is called to redraw the screen. This function // calls Point and PointBox to draw boxes of various colors, sizes, and locations. static void Draw(void) { // Create viewpoint specifications. glViewport(0, 0, windW, windH); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-windW/2, windW/2, -windH/2, windH/2, 0.0, 1.0); // Clear background color to black glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); // Call drawing functions Point(); color[0] = 1.0; color[1] = 1.0; color[2] = 1.0; PointBox(0,16,0,16,color); color[0] = 1.0; color[1] = 0.0; color[2] = 0.0; PointBox(-windW/2,-windW/2 + 30, -windH/2, -windH/2 + 30, color); color[0] = 0.0; color[1] = 1.0; color[2] = 0.0; PointBox(-windW/2,-windW/2 + 30, windH/2 - 30, windH/2, color); color[0] = 0.0; color[1] = 0.0; color[2] = 1.0; PointBox(windW/2 - 30, windW/2, -windH/2, -windH/2 + 30, color); color[0] = 1.0; color[1] = 1.0; color[2] = 0.0; PointBox(windW/2 - 30, windW/2, windH/2 - 30, windH/2, color); glFlush(); glutSwapBuffers(); } // Function handles input arguments. Add handling of your input arguments here. static GLenum Args(int argc, char **argv) { GLint i; for (i = 1; i < argc; i++) { // Add valid input arguments. /*if () { } else { printf("%s (Bad option).\n", argv[i]); return GL_FALSE; } */ } return GL_TRUE; } // Main function. int main(int argc, char **argv) { glutInit(&argc, argv); if (Args(argc, argv) == GL_FALSE) { exit(1); } // Initialize OpenGL window. windW = 512; windH = 512; glutInitWindowPosition(0, 0); glutInitWindowSize( windW, windH); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); if (glutCreateWindow("Primitive Test") == GL_FALSE) { exit(1); } // Set functions to be called when window is resized (Reshape), // for keyboard input (Key), and for drawing (Draw). glutReshapeFunc(Reshape); glutKeyboardFunc(Key); glutDisplayFunc(Draw); glutMainLoop(); return 0; }