Comp Form: Week 1 Assignment
Drawing a portrait, landscape, and grid in C and openGL. . .
| Problem 1. Write a comment for every line in the main.cpp file. | |
| /* * main.cpp * CompFormApp * */#include <OpenGL/gl.h> //openGL lib #include <GLUT/glut.h> //glut lib#include <stdio.h> //input output lib #include <stdlib.h> //standard lib #include <math.h> //math libfloat mouseX = 0; //new variable, mouseX float mouseY = 0; //mouseY int windowW = 800; //window Width int windowH = 600; //window Height#define PI 3.14159265358979 //variable for pivoid displayFunc ( void ) { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //clears screen, color and depth, | binary OR// place your drawing code here glColor3f( 1,0,0 ); //pen color (r,g,b) //glColor4f(1,0,0,.5);//pen color + alpha glRectf( mouseX-5, mouseY-5, mouseX+5, mouseY+5 ); //draw rectangle (only built-in function), corner to cornerglutPostRedisplay(); //repeat, redraw glutSwapBuffers(); //swaps offscreen buffer, offscreen to onscreen }void reshapeFunc ( int w, int h ) { windowW = w; //window width windowH = h; //window height//camera setup glViewport( 0, 0, w, h ); //camera view, drawing region (x,y,x,y) glMatrixMode( GL_PROJECTION );//camera operations matrix glLoadIdentity();//load projection gluOrtho2D( 0,w,0,h ); //set camera to ortho, 2dglMatrixMode( GL_MODELVIEW );//drawing space matrix glLoadIdentity();//load model space }//mouse functions void mouseDownFunc ( int button, int state, int x, int y ) { mouseX = x; mouseY = windowH - y;//y=0 at bottom of screen printf(”%d %dn”,x,y);//print mouse x,y loc}void mouseMoveFunc ( int x, int y )//if mouse is moved { mouseX = x; mouseY = windowH - y; }void mouseDragFunc ( int x, int y )//if mouse is dragged { mouseX = x; mouseY = windowH - y; }//keyboard functions void keyboardFunc ( unsigned char key, int x, int y ) { }void arrowKeyFunc ( int a_keys, int x, int y ) { }void init ( GLvoid ) { glShadeModel( GL_SMOOTH ); // flat or smooth shading glClearColor( 1.0, 1.0, 1.0, 1.0 ); //specify clear values for the color buffers glEnable ( GL_COLOR_MATERIAL );//enable server side color material tracking glEnable( GL_BLEND );//enable server side blend of rgb values glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);//specify pixel rgb math } //main function at bottom glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE ); //display mode //callback functions init();//call void init func glutMainLoop( );//main event loop, calls custom functions when even occurs return 0; //returns main=0 |
|
- Published:
- 09.08.07 / 3pm
- Category:
- C, Comp Form, ITP, Work in Progress










No comments
Jump to comment form | comments rss [?] | trackback uri [?]