opengl belysning
Jeg har fået udleveret noget kode som jeg så skal rette til, men kan ikke helt få det til at stemme med det der bliver spurgt om. Jeg skal sætte lys på mit objekt som er et hus, men akserne og kontrolpunkterne skal ikke belyses, men det bliver de og jeg kan ikke rigtig se hvad jeg gør forkert håber nogen kan hjælpe mig her er det kode jeg arbejder med. Den er lidt lang men det er også det hele#include <GL/glut.h>
#include <stdlib.h>
GLfloat ctrlpoints [5][3] = {{0.,0.,0.},{0.,0.,5.},{5.,0.,10.},{10.,0.,5.},{10.,0.,0.} };
void ctrlpolygon (void);
void axis (void);
void house (void);
void curves (void);
void texture (void);
void init (void);
void display (void);
void reshape (int w, int h);
void keyboard(unsigned char key, int x, int y);
int main(int argc, char** argv);
void init(void) {
//phong equation indeholder følgende reflektioner: (diffuse,specular,ambient og emissive)
GLfloat diffuse[] = { 0.8, 0.0, 0.0, 1.0 };
GLfloat specular[] = { 0.8, 0.0, 0.0, 1.0 };
GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat emissive[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat shininess[] = { 20.0 };
GLfloat position[] = { 12.0, 10.0, 10.0, 0.0 };//lyskildens possition
GLfloat local_view[] = { 0.0 };
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
glLightfv(GL_LIGHT0, GL_EMISSION, emissive);
glMaterialfv(GL_FRONT, GL_SHININESS, shininess);
glLightfv(GL_LIGHT0, GL_POSITION, position);
glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view);
glShadeModel(GL_SMOOTH);
glEnable (GL_DEPTH_TEST);
glEnable (GL_NORMALIZE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glClearColor(1.0, 1.0, 1.0, 1.0);
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(0.0, 0.0, 0.0);
glLoadIdentity ();
gluLookAt (12., 10., 10., 5., 0., 5., 0., 0., 1.);
glPushMatrix ();
/* Draws the control points and the connecting control polygon */
ctrlpolygon ();
/* draw axis */
axis();
/* Draws the House */
house ();
/* Draw the curves - Part 4 - optional*/
curves ();
/*Draw the texture - Part 5 - optional*/
texture ();
glPopMatrix ();
glFlush();
}
void reshape(int w, int h) {
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho (-30.0, 30.0, -30.0*(GLfloat)h/(GLfloat)w,
30.0*(GLfloat)h/(GLfloat)w , -30., 30.);
else
glOrtho(-30.0*(GLfloat)w/(GLfloat)h,
30.0*(GLfloat)w/(GLfloat)h, -30.0, 30.0, -30., 30.);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void keyboard(unsigned char key, int x, int y) {
switch (key) {
case 27:
exit(0);
break;
}
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc (keyboard);
glutMainLoop();
return 0;
}
void ctrlpolygon (void) {
int i;
/* The following code displays the control points as dots ...*/
glPointSize(5.0);
glColor3f(0.0, 1.0, 1.0);
glBegin(GL_POINTS);
for (i = 0; i < 5; i++)
glVertex3fv(&ctrlpoints[i][0]);
glEnd();
/* ... and draws the Control Polygon as a line strip*/
glColor3f(0.0, 0.0, 0.0);
glBegin(GL_LINE_STRIP);
for (i = 0; i < 5; i++)
glVertex3fv(&ctrlpoints[i][0]);
glEnd();
}
void axis (void){
/* Red Xw-axis */
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINES);
glVertex3f(0.,0.,0.);
glVertex3f(15.,0.,0.);
glEnd();
/* Green Yw-axis*/
glColor3f(0.0, 1.0, 0.0);
glBegin(GL_LINES);
glVertex3f(0.,0.,0.);
glVertex3f(0.,15.,0.);
glEnd();
/* Blue Zw-axis */
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_LINES);
glVertex3f(0.,0.,0.);
glVertex3f(0.,0.,15.);
glEnd();
}
void house (void) {
int i;
/* This code draws the house.
The house consists of 6 polygon as defined below:
Two Ends: Ep and Ep2, Two Walls: Wp and Wp2, and Two Roofs: Rp and Rp2
The code also sets up the normals of the polygons.
*/
GLfloat Ep [5][3] = {{0.,0.,0.},{0.,0.,5.},{5.,0.,10.},{10.,0.,5.},{10.,0.,0.} };
GLfloat Wp[4][3] = {{0.,0.,0.},{0.,-10.0,0.},{0.,-10.,5.},{0.,0.,5.} };
GLfloat Rp [4][3] = {{0.,0.,5.},{0.,-10.,5.},{5.,-10.,10.},{5.,0.,10.} };
GLfloat Ep2 [5][3] = {{10.,-10.,0.},{10.,-10.,5.},{5.,-10.,10.},{0.,-10.,5.},{0.,-10.,0.}};
GLfloat Wp2 [4][3] = {{10.,0.,0.},{10.,0.,5.},{10.,-10.,5.},{10.,-10.,0.}};
GLfloat Rp2 [4][3] = {{10.,0.,5.},{5.,0.,10.},{5.,-10.,10.},{10.,-10.,5.} };
glPushMatrix ();
glColor3f (0.8, 0.0, 0.0);
glBegin(GL_POLYGON);
glNormal3f (0.0,1.0,0.0);
for (i = 0; i < 5; i++)
glVertex3fv(&Ep[i][0]);
glEnd();
glBegin(GL_POLYGON);
glNormal3f (-1.0,0.0,0.0);
for (i = 0; i < 4; i++)
glVertex3fv(&Wp[i][0]);
glEnd();
glBegin(GL_POLYGON);
glNormal3f (-1.0,0.0,1.0);
for (i = 0; i < 4; i++)
glVertex3fv(&Rp[i][0]);
glEnd();
glBegin(GL_POLYGON);
glNormal3f (0.0,-1.0,0.0);
for (i = 0; i < 5; i++)
glVertex3fv(&Ep2[i][0]);
glEnd();
glBegin(GL_POLYGON);
glNormal3f (1.0,0.0,0.0);
for (i = 0; i < 4; i++)
glVertex3fv(&Wp2[i][0]);
glEnd();
glBegin(GL_POLYGON);
glNormal3f (1.0,0.0,1.0);
for (i = 0; i < 4; i++)
glVertex3fv(&Rp2[i][0]);
glEnd();
glPopMatrix();
}