/*
* main.cpp
* CompFormApp
*
*/
//includes the libraries tells the linker what to add
// allows for the use of any function from libs
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
float mouseX = 0; // float var
float mouseY = 0;
int windowW = 800; //int var
int windowH = 600;
int rectSize =40;
#define PI 3.14159265358979
//defines pi as 3.14ect strait replacement by compiler
void displayFunc ( void ) //arg void returns void
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );//clears buffers(what buffers?) by setting bit mask or.
glColor3f( 1,0,0 );//sets color can add a alpha on end 255,255,255,255
//glRectf( mouseX-rectSize, mouseY-rectSize, mouseX+rectSize, mouseY+rectSize); //two arguments cords of perp corners this case based on mouse
// place your drawing code here
// glBegin(GL_LINES);
//glVertex3f(100.0f, 100.0f, 0.0f); // origin of the line
//glVertex3f(200.0f, 140.0f, 5.0f); // ending point of the line
//glEnd( );
glutPostRedisplay(); //tags the current window to be redisplayed or shown through the
//next iteration loop.
glutSwapBuffers(); //calls for the display of a the current buffer for the curretn window
// i assume to cut down on jerky motion
}
void reshapeFunc ( int w, int h ) //interface method for glutReshapeFunc called when window size changes
{
windowW = w; //passed args
windowH = h;
glViewport( 0, 0, w, h );//scales in the image xy points to the windows xy points with a afine transform to retaine correct perspective.
glMatrixMode( GL_PROJECTION );// calls the GL_PROJECTION matrix to be operated on.
glLoadIdentity(); // replaces the current matrix with the unmodifide original matrix.
gluOrtho2D( 0,w,0,h ); //makes a orthographic projection which takes out perspective and makes everything parallel.
glMatrixMode( GL_MODELVIEW ); //calls the GL_MODELVIEW matrix to be operated on.
glLoadIdentity(); // replaces the current matrix with the unmodifide original matrix.
}
void mouseDownFunc ( int button, int state, int x, int y ) //interface method declaration for glutMouseFunc
{
mouseX = x; //mouse position x
mouseY = windowH - y; // window size - y pos flips position.
}
void mouseMoveFunc ( int x, int y ) //interface method declaration for glutMotionFunc
{
mouseX = x;//mouse position x
mouseY = windowH - y;// window size - y pos flips position.
}
void mouseDragFunc ( int x, int y ) // dosomthing with mousedrag calls
{
mouseX = x; // mouse pos in window
mouseY = windowH - y; //mouse pos in window inverted for cord
}
void keyboardFunc ( unsigned char key, int x, int y )// do somthing with ketboard calls
{
}
void arrowKeyFunc ( int a_keys, int x, int y ) // do something with arrow key calls
{
}
void init ( GLvoid )
{
glShadeModel( GL_SMOOTH );// sets the type of shading for object set to smooth
glClearColor( 1.0, 1.0, 1.0, 1.0 );// specified the color valuse that will be set when clear is called
glEnable ( GL_COLOR_MATERIAL ); //enables different capability (material parameters track the current color) not quite sure what that means?
glEnable( GL_BLEND ); // enables blending
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //blends the incoming colors against a color buffer (is also useful for rendering antialiased points and lines in arbitrary order)?
}
int main ( int argc, char** argv ) // main function
{
glutInit( &argc, argv ); // calls the windowed platform of the system links it with glut library.
glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE ); // sets the type of window to be displayed
glutInitWindowSize( windowW, windowH );// sets the window size must be called before create window.
glutCreateWindow( "CompFormApp" ); // creates a window set as current window nothing is done to it till glutMainLoop is called.
glutDisplayFunc( displayFunc ); // sets the display call back to operate and diplay in the current window, glut takes care of when to display.
glutReshapeFunc( reshapeFunc ); // called when window is resized transforms scale of image to fit new size
glutMouseFunc( mouseDownFunc ); // listens for a mouse event passes the event to mouseDownFunct runs that function.
glutMotionFunc( mouseDragFunc ); //listens for event when mouse is pressed and moved passes event to mouseDragFunc.
glutPassiveMotionFunc( mouseMoveFunc ); //listens for event when mouse is NOT pressed is moved passes event to mouseMoveFunc.
glutKeyboardFunc( keyboardFunc ); //listens for key board events passes them as ACII to the current window passes to keyboardFunc.
glutSpecialFunc( arrowKeyFunc );// listens for special keys (arrow) and you get window relative cords of mouse passes to arrowKeyFunc.
init(); //calls inint func
glutMainLoop( );// main function loop once it starts running the only other functions it calls are the event handelers (above)
// most likely always the last function call.
return 0; // return 0 to operating system;
}