From: Ash Tyndall Date: Thu, 20 Oct 2011 13:46:24 +0000 (+0800) Subject: Played around with lighting, drew arrows, ran into issues X-Git-Url: https://git.ucc.asn.au/?p=atyndall%2Fcits2231.git;a=commitdiff_plain;h=84eea711e741871dfb6cc595a0989e1369998d7f Played around with lighting, drew arrows, ran into issues KNOWN ISSUES: * Teapot sides are being weird * drawSquare doesn't appear to be functioning correctly * Floor doesn't light correctly * Camera angle is all wrong (hold down 'w' to see scene) * windowReshape doesn't currently work outside of default parameters CHANGES: * Discovered I was using an orthographic projection instead of a perspective projection. glOrtho stuff needs to change to glFrustrum. I'm using gluPerspective in the mean time, but I can't seem to get it to angle properly. * Various changes and experimentation. --- diff --git a/globals.c b/globals.c index a5e70f4..6f7e985 100644 --- a/globals.c +++ b/globals.c @@ -82,6 +82,16 @@ GLfloat lineLength = 100; GLfloat diffuse0[]={1.0, 0.0, 0.0, 1.0}; GLfloat ambient0[]={1.0, 0.0, 0.0, 1.0}; GLfloat specular0[]={1.0, 0.0, 0.0, 1.0}; -GLfloat emission0[] = {1.0, 1.0, 1.0, 0.5}; +GLfloat emission0[] = {0.0, 0.3, 0.3, 1.0}; + +GLfloat direction0[] = {0.0, 0.0, 0.0}; GLfloat light0_pos[] ={1.0, 1.0, 0,0, 0.5}; -GLfloat glightmodel[] = {0.2,0.2,0.2,1}; \ No newline at end of file + +GLfloat shine = 100.0; + +GLfloat glightmodel[] = {0.2,0.2,0.2,1}; + +/* Material types */ +GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0}; +GLfloat diffuse[] = {1.0, 0.8, 0.0, 1.0}; +GLfloat specular[] = {1.0, 1.0, 1.0, 1.0}; \ No newline at end of file diff --git a/globals.h b/globals.h index 71a21c2..6f6a626 100644 --- a/globals.h +++ b/globals.h @@ -39,7 +39,7 @@ extern GLfloat lightPosition[]; extern int moving, startx, starty; extern int lightMoving, lightStartX, lightStartY; - +/* Time varying or user-controled variables. */ extern float jump; extern float lightAngle, lightHeight; extern GLfloat angle; @@ -73,8 +73,18 @@ extern GLfloat diffuse0[]; extern GLfloat ambient0[]; extern GLfloat specular0[]; extern GLfloat emission0[]; + +extern GLfloat direction0[]; extern GLfloat light0_pos[]; + +extern GLfloat shine; + extern GLfloat glightmodel[]; +/* Material types */ +extern GLfloat ambient[]; +extern GLfloat diffuse[]; +extern GLfloat specular[]; + #endif /* GLOBALS_H */ diff --git a/helper.c b/helper.c index 33799d5..0071af4 100644 --- a/helper.c +++ b/helper.c @@ -232,9 +232,7 @@ void drawSquare(int recurseLevel, float x1, float z1, float x2, float z2) { } else { // Draw square. - // **NOTE: Is the polygon facing in the right direction? - // **NOTE: We're drawing large strips, which might be a lighting problem - + // **NOTE: We're drawing large strips, instead of squares, which might cause a lighting problem glBegin(GL_QUADS); glNormal3f(0,1,0); glVertex3f(x1, 0.0, z1); @@ -256,24 +254,25 @@ void drawFloor() { * Draw x, z axis on floor */ void drawLine() { - // **NOTE: fix function - glDisable(GL_TEXTURE_2D); - glDisable(GL_LIGHTING); - //glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glColor3f( 0.0, 0.0, 0.0 ); - - glBegin(GL_LINES); + // **NOTE: Function does not currently draw arrow-heads + + glDisable(GL_TEXTURE_2D); + glDisable(GL_LIGHTING); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glColor3f( 0.0, 0.0, 0.0 ); + + glBegin(GL_LINES); glVertex3i( lineLength, 0.0, 0.0 ); glVertex3i( -lineLength, 0.0, 0.0 ); - glEnd(); + glEnd(); - glBegin(GL_LINES); + glBegin(GL_LINES); glVertex3i( 0.0, 0.0, lineLength ); glVertex3i( 0.0, 0.0, -lineLength ); - glEnd(); + glEnd(); - //glDisable(GL_BLEND); - glEnable(GL_LIGHTING); - glEnable(GL_TEXTURE_2D); + glDisable(GL_BLEND); + glEnable(GL_LIGHTING); + glEnable(GL_TEXTURE_2D); } \ No newline at end of file diff --git a/scene.c b/scene.c index 264d598..0c5329b 100644 --- a/scene.c +++ b/scene.c @@ -184,16 +184,7 @@ void makeMenu() { */ void windowReshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); - /*glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - if (w <= h) - glFrustum(near, far, near*(GLfloat)h/(GLfloat)w, - far*(GLfloat)h/(GLfloat)w, -100, 100); - else - glFrustum(near*(GLfloat)w/(GLfloat)h, - far*(GLfloat)w/(GLfloat)h, near, far, nearClip, farClip); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity();*/ + // **NOTE: windowReshape needs to be re-written using glFrustrum and perspective projection calculations } /** @@ -295,17 +286,6 @@ void motion(int x, int y) { void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); - //gluLookAt( - // 0.0, 0.0, 30.0, /* eye is at (x,y,z) */ - // 0.0, 0.0, 0.0, /* center is at (x,y,z) */ - // 0.0, 1.0, 0.0 /* up is in postivie Y direction */ - // ); - - glTranslatef(camx, camy, camz); - - // **NOTE: Currently this rotation function is all that moves the camera off - // the flat surface. Need to integrate function into gluLookAt - glRotatef(rot, 1.0, 0.0, 0.0); /* Reposition the light source. */ lightPosition[0] = 12*cos(lightAngle); @@ -315,9 +295,11 @@ void display() { glPushMatrix(); - /* Perform scene rotations based on user mouse input. */ + /* Perform scene rotations based on user mouse/keyboard input. */ glRotatef(angle, 0.0, 1.0, 0.0); - glRotatef(angle2, 1.0, 0.0, 0.0); //**NOTE: Only one degree of freedom + glRotatef(angle2, 1.0, 0.0, 0.0); + glTranslatef(camx, camy, camz); + glRotatef(rot, 1.0, 0.0, 0.0); glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); @@ -327,7 +309,7 @@ void display() { // Draw teapot for a test object glPushMatrix(); - glTranslatef(0.0, 0.5, 0.0); // **NOTE: Teapot does not rest on surface + glTranslatef(0.0, 0.5, 0.0); // **NOTE: Teapot currently does not rest on surface glColor3f(0.0, 0.0, 0.0); glutSolidTeapot(1); glPopMatrix(); @@ -350,50 +332,27 @@ void display() { * init function; sets initial OpenGL state */ void init() { - //glMatrixMode(GL_PROJECTION); - //glLoadIdentity(); - - //gluPerspective( - // 60.0, /* field of view in degree */ - // 1.0, /* aspect ratio */ - // nearClip, /* Z near */ - // farClip /* Z far */ - // ); - glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - // **NOTE: Needs tidy glLightfv(GL_LIGHT0, GL_POSITION, light0_pos); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0); glLightfv(GL_LIGHT0, GL_SPECULAR, specular0); - GLfloat direction0[] = {0.0, 0.0, 0.0}; glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, direction0); + glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 90.0); + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, glightmodel); - GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0}; - GLfloat diffuse[] = {1.0, 0.8, 0.0, 1.0}; - GLfloat specular[] = {1.0, 1.0, 1.0, 1.0}; - GLfloat shine = 100.0; glMaterialfv(GL_FRONT, GL_AMBIENT, ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, specular); + glMaterialfv(GL_FRONT, GL_EMISSION, emission0); glMaterialf(GL_FRONT, GL_SHININESS, shine); - GLfloat emission[] = {0.0, 0.3, 0.3, 1.0}; - glMaterialfv(GL_FRONT, GL_EMISSION, emission); - glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); - //glEnable(GL_COLOR_MATERIAL); - //glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); - //glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, specular0); - //glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, emission0); - - - } /** @@ -429,21 +388,21 @@ int main(int argc, char **argv) { glDepthFunc(GL_LEQUAL); // the type glEnable(GL_CULL_FACE); glEnable(GL_TEXTURE_2D); - glEnable(GL_BLEND); glLineWidth(1.0); + // **NOTE: Currently the perspective and look-at code is static, for testing purposes glMatrixMode(GL_PROJECTION); gluPerspective( 40.0, /* field of view in degree */ 1.0, /* aspect ratio */ - 1.0, /* Z near */ + 1.0, /* Z near */ // **NOTE: Seems to be issue with near < 0 causing invisible everything 100.0 /* Z far */ ); glMatrixMode(GL_MODELVIEW); gluLookAt( - 0.0, 35.0, -20.0, /* eye is at (0,8,60) */ - 0.0, 10.0, 0.0, /* center is at (0,8,0) */ + 0.0, 35.0, -20.0, /* eye is at (x,y,z) */ + 0.0, 10.0, 0.0, /* center is at (x,y,z) */ 0.0, 1.0, 0.0 /* up is in postivie Y direction */ ); @@ -460,4 +419,4 @@ int main(int argc, char **argv) { init(); glutMainLoop(); -} +} \ No newline at end of file