Week 1 Assignment

Maria Mendez

Problem 1. Write a comment for every line in the main.cpp file.

/*
* main.cpp
* CompFormApp
*
*/
// libraries

#include <OpenGL/gl.h>
#include <GLUT/glut.h>
//input and output functions
#include <stdio.h>
// memory allocation, rand, and other funtions
#include <stdlib.h>
// math functions
#include <math.h>

// global variables
float mouseX = 0;
float mouseY = 0;
int windowW = 800;
int windowH = 600;

//preprocesor directive, define an identifier and a character sequence that will be substituted for the indentifier each time that appears.
#define PI 3.14159265358979

void displayFunc ( void )
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );//Clear buffer within the viewport.

glColor3f( 1,0.5,0);//Sets a four-valued RGBA color, glColor3f set the alpha to 1.0
glRectf( mouseX-10, mouseY-10, mouseX+10, mouseY+10 );// Specification of a rectangle as two corner points

glBegin( GL_TRIANGLE_STRIP);//glBegin and glEnd delimit the vertices of a primitive or a group of like primitives. Accepts a single argument that specifies which of ten ways the vertices are interpreted
glVertex2f(100,100);//specify point, line, and polygon vertices
glVertex2f(200,200);
glVertex2f(300,100);
glEnd();


glutPostRedisplay();//marks the currentwindow as needing to be redisplayed
glutSwapBuffers();//swaps the buffers of the current window if double buffered
}

void reshapeFunc ( int w, int h )
{
windowW = w;
windowH = h;

glViewport( 0, 0, w, h );// Set the viewport
glMatrixMode( GL_PROJECTION );//Sets the current matrix mode to projection mode
glLoadIdentity();//Replaces the current matrix with the identity matrix???
gluOrtho2D( 0,w,0,h );//Define a 2-D orthographic projection matrix

glMatrixMode( GL_MODELVIEW );//Sets the current matrix mode to modelview mode
glLoadIdentity();
}

void mouseDownFunc ( int button, int state, int x, int y )
{
mouseX = x;
mouseY = windowH - 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 )
{
}

void arrowKeyFunc ( int a_keys, int x, int y )
{
}

void init ( GLvoid )
{
glShadeModel( GL_SMOOTH );//Select smooth shading technic
glClearColor( 1.0, 1.0, 1.0, 1.0 );//Clear values for the color buffers
glEnable ( GL_COLOR_MATERIAL );//Enable to have one or more material parameters track the current color
glEnable( GL_BLEND );//Blend the incoming RGBA color values with the values in the color buffers (transparency?)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);//Define the operation that blends the incoming RGBA with the values in the frame buffer

}

int main ( int argc, char** argv )
{
glutInit( &argc, argv );//initialize the GLUT library

glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );//sets the initial display mode RGBA mode or(?) double buffered window
glutInitWindowSize( windowW, windowH );// sets the size of the window
glutCreateWindow( "CompFormApp" );//creates a top-level window
// callback functions
glutDisplayFunc( displayFunc );//sets the display callback for the current window
glutReshapeFunc( reshapeFunc );//sets the reshape callback for the current window.
glutMouseFunc( mouseDownFunc );//sets the mouse callback for the current window.
glutMotionFunc( mouseDragFunc );//set the motion callback for the current window.
glutPassiveMotionFunc( mouseMoveFunc );//set the passive motion callback for the current window.
glutKeyboardFunc( keyboardFunc );//sets the keyboard callback for the current window.

glutSpecialFunc( arrowKeyFunc );//sets the special keyboard (directional keys) callback for the current window.

init();

glutMainLoop( );//enters the GLUT event processing loop
return 0;
}