/* * a1p2.cpp * CompFormApp * * Created by Matthew Parker on 9/7/07. * Copyright 2007 __MyCompanyName__. All rights reserved. * */ #include #include #include #include #include void drawGrid(void){ glColor3f(0.75,0.75,0.75); glLineWidth(1); for(int x = 0; x < X_BORDER; x = x + 10){ glBegin(GL_LINES); glVertex2f(x, 0); glVertex2f(x, TOP); glEnd(); } for(int y = 0; y < TOP; y = y + 10){ glBegin(GL_LINES); glVertex2f(0, y); glVertex2f(X_BORDER, y); glEnd(); } glPointSize(3); glColor3f(0.25,0.25,0.25); for(int x = 0; x < X_BORDER; x = x + 10){ for(int y = 0; y < TOP; y = y + 10){ glLineWidth(3); glBegin(GL_POINTS); glVertex2f(x, y); 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 drawGrid(); 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("{%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 }