/* * a1p2.cpp * CompFormApp * * Created by Matthew Parker on 9/7/07. * Copyright 2007 __MyCompanyName__. All rights reserved. * */ #include #include #include #include #include #include float mouseX = 0; float mouseY = 0; int windowW = 800; int windowH = 600; #define PI 3.14159265358979 void drawPortrait(void){ glColor3f(0,0,0); //sets color to red (red, green, blue) glBegin(GL_TRIANGLE_FAN); for(int i = 0; i < facePtsLength; i++){ glVertex2f(facePts[i][0],facePts[i][1]); } glEnd(); glColor3f(1,1,1); //sets color to red (red, green, blue) glBegin(GL_TRIANGLE_STRIP); for(int i = 0; i < eyePtsLength; i++){ glVertex2f(eyePts[i][0],eyePts[i][1]); } glEnd(); glColor3f(1,0,0); //sets color to red (red, green, blue) glLineWidth(3); //Draw "M" glBegin(GL_LINE_STRIP); glVertex2f(600, 50); glVertex2f(600,100); glVertex2f(625, 75); glVertex2f(650,100); glVertex2f(650,50); glEnd(); //Draw "P" glBegin(GL_LINE_STRIP); glVertex2f(670, 50); glVertex2f(670,100); glVertex2f(700, 90); glVertex2f(700, 80); glVertex2f(670, 70); glEnd(); } void displayFunc ( void ) //what to display on screen (only place to draw on screen) { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //clears the screen (clear color and depth) // place your drawing code here drawPortrait(); glColor3f( 1,0,1); //sets color to red (red, green, blue) // glColor4f( 1,0,0, 0.5); //sets color to red and transparent (red, green, blue, transparency) glRectf( mouseX-5, mouseY-5, mouseX+5, mouseY+5 ); //draw a rectangle (to opposite coordinates) glutPostRedisplay(); //redraw off screen buffer (allows for animation) glutSwapBuffers(); //switch from off screen buffer to on screen buffer } void reshapeFunc ( int w, int h ) //resize the window { windowW = w; //update global variables windowH = h; glViewport( 0, 0, w, h ); //window coords, drawing region of window glMatrixMode( GL_PROJECTION ); //how the camera operates glLoadIdentity(); // gluOrtho2D( 0,w,0,h ); // glMatrixMode( GL_MODELVIEW ); //defines what you're drawing glLoadIdentity(); } void mouseDownFunc ( int button, int state, int x, int y ) //called when mouse is pressed (button = which button, state = up or down, x/y = position) { mouseX = x; //set our global mouseX to x mouseY = windowH - y; //set our global mouseY to the invert of y if(state == 0){ printf(" glVertex2f(%d,%d); \n", x, windowH - y); //prints out x, y } } void mouseMoveFunc ( int x, int y ) { mouseX = x; mouseY = windowH - y; } void mouseDragFunc ( int x, int y ) { mouseX = x; mouseY = windowH - y; } void keyboardFunc ( unsigned char key, int x, int y ) //called when a keyboard button is pressed { } void arrowKeyFunc ( int a_keys, int x, int y ) //called when special keys are pressed (arrows, shift, etc) { } void init ( GLvoid ) //minimal amount of OpenGL initialization { glShadeModel( GL_SMOOTH ); glClearColor( 1.0, 1.0, 1.0, 1.0 ); glEnable ( GL_COLOR_MATERIAL ); glEnable( GL_BLEND ); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } int main ( int argc, char** argv ) // * = pointer (** double pointer) { glutInit( &argc, argv ); // & = take the address of glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE ); // double buffered glutInitWindowSize( windowW, windowH ); // take other functions = callback glutCreateWindow( "CompFormApp" ); glutDisplayFunc( displayFunc ); //display screen glutReshapeFunc( reshapeFunc ); //reshape window size glutMouseFunc( mouseDownFunc ); //mouse click glutMotionFunc( mouseDragFunc ); //dragging mouse glutPassiveMotionFunc( mouseMoveFunc ); //moving mouse glutKeyboardFunc( keyboardFunc ); //key down glutSpecialFunc( arrowKeyFunc ); //special case for arrow key presses/shift/etc. init(); glutMainLoop( ); //runs the glut environment, prevents program from reaching return return 0; //place holder return for main }