//////////////////////////////////////////////////////// // CSE 581: Lab 1 // Brandon Walters // walters.235@osu.edu // // Based off of Dr. Shen's "simple lab1" code // //////////////////////////////////////////////////////// #include #include #include #include #include #define DRAW_POINT 1 #define RED 1 #define BLUE 2 #define GREEN 3 #define CLEAR_SCREEN 4 #define DISTANCE 60 ///////////////////////////////////////////// void create_menu(); ///////////////////////////////////////////// int drawing_color = RED; int drawing_mode = 1; int menu_id = NULL; int width=500, height = 500; // display window width and height int press_x, press_y; int release_x, release_y; int rotate=0; int mouse_x=0, mouse_y=0; typedef struct { int x1, x2, y1, y2; int color; int rotate; }polyline; polyline *polylines; int polyline_count = 0; int type_list[200]; // primitive buffer // 200: max number of primitives allowed float vertex_list_x[1000]; // x buffer float vertex_list_y[1000]; // y buffer int color_list[200]; int nop = 0; // number of primitives int nov = 0; // number of vertices ///////////////////////////////////////////// void testDraw() { //glMatrixMode(GL_PROJECTION); //glLoadIdentity(); //gluOrtho2D(0, 499, 0, 499); // here I just hard-wire the world window glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //glPushMatrix(); glColor3f(1,0,0); glTranslatef(-width/2,-height/2,0); glRotatef(45,0,0,1); // rotate by rotate angle glTranslatef(width/2,height/2,0); glBegin(GL_LINES); glVertex2f(width/2,height/2); glVertex2f(width/2+DISTANCE,height/2+DISTANCE); glEnd(); glLoadIdentity(); glBegin(GL_LINES); glVertex2f(width/2,height/2); glVertex2f(width/2+DISTANCE,height/2); glEnd(); glFlush(); // force OpenGL to draw all the objects //glutPostRedisplay(); // now display everything in the buffers } void clear_screen() { nop = 0; nov = 0; free(polylines); polylines = NULL; polyline_count = 0; glutPostRedisplay(); // now display everything in the buffers } ///////////////////////////////////////////// void display_all() { float x, y; int p_idx, next_primitive; int v_idx = 0; glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //glPushMatrix(); for (int i=0; iRed", RED); else glutAddMenuEntry("Red", RED); if (drawing_color == GREEN) glutAddMenuEntry("->Green", RED); else glutAddMenuEntry("Green", GREEN); if (drawing_color == BLUE) glutAddMenuEntry("->Blue", RED); else glutAddMenuEntry("Blue", BLUE); glutAddMenuEntry("-----------------", CLEAR_SCREEN); glutAddMenuEntry("Clear Screen", CLEAR_SCREEN); glutAttachMenu(GLUT_RIGHT_BUTTON); } ///////////////////////////////////////////// void mykey(unsigned char key, int x, int y) { if (key =='q') exit(0); else if (key == 'f') { rotate = 0; create_line(0); } else if (key == 't') { rotate += 45; if (rotate > 360) rotate=0; create_line(rotate); } } //////////////////////////////////////////////////// void resize(int w, int h) { // this is really just the default GLUT behavior. you should change it for the lab1 //glViewport(0,0,w,h); //glutPostRedisplay(); width = w; height = h; glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(65.0, (float)width / height, 1, 1000); glMatrixMode(GL_MODELVIEW); } //////////////////////////////////////////////////// void myInit() { // did not really do much here // set the viewport glViewport(0,0,width, height); } ////////////////////////////////////////////////////////// int main(int argc, char** argv) { // init glut drawing window glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE); glutInitWindowSize(width,height); glutCreateWindow("Brandon Walters' Lab 1"); myInit(); // my own OpenGL initialization // register callbacks glutDisplayFunc(display); glutReshapeFunc(resize); glutMouseFunc(mymouse); glutKeyboardFunc(mykey); // create menu create_menu(); // enter the event loop glutMainLoop(); }