#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 GLenum rgb, doubleBuffer, windType; 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++) { for (i = 0; i < windH; i++) { glVertex2i(i,i); glVertex2i(i, windH/2); glVertex2i(600-i, i); glVertex2i(windW/2, i); } 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(0.0f, windH, 0.0f, windH, 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(windW/2,windW/2 + 16, windH/2, windH/2 + 16, color); color[0] = 1.0; color[1] = 0.0; color[2] = 0.0; PointBox(0,30, 0,30, color); color[0] = 0.0; color[1] = 1.0; color[2] = 0.0; PointBox(0,30, 600 - 30, 600, color); color[0] = 0.0; color[1] = 0.0; color[2] = 1.0; PointBox(600 - 30, 600, 0, 30, color); color[0] = 1.0; color[1] = 1.0; color[2] = 0.0; PointBox(600-30, 600, 600-30, 600, color); glFlush(); if (doubleBuffer) { glutSwapBuffers(); } } // Function handles input arguments. Add handling of your input arguments here. static GLenum Args(int argc, char **argv) { GLint i; rgb = GL_TRUE; doubleBuffer = GL_FALSE; for (i = 1; i < argc; i++) { if (strcmp(argv[i], "-ci") == 0) { rgb = GL_FALSE; } else if (strcmp(argv[i], "-rgb") == 0) { rgb = GL_TRUE; } else if (strcmp(argv[i], "-sb") == 0) { doubleBuffer = GL_FALSE; } else if (strcmp(argv[i], "-db") == 0) { doubleBuffer = GL_TRUE; } 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 = 600; windH = 600; glutInitWindowPosition(0, 0); glutInitWindowSize( windW, windH); windType = (rgb) ? GLUT_RGB : GLUT_INDEX; windType |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE; glutInitDisplayMode(windType); 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; }