Same coordinates? Easy question

If i put my lightsource in Glfloat lightpos0[]={12.0,10.0,10.0,0.0}; -> glLightfv(GL_LIGHT0,GL_POSITION,lightpos0), is that then the same point as if i put a vertex in glVertex(12.0,10.0,10.0); ? I am in doubt about that last lightcoordinat w=0.0. So are those the same positions?

No. {12.0, 10.0, 10.0, 1.0} would be the same position.

With w == 0 you’ll get a directional light. You can think of it as a point light that is infinitely far away, with the general direction being the given vector.

Hmm i kinda found out that 0.0 is set if i want directional light towards 0,0,0.

But what i dont understand then is how i can avoid illuminating the axes() and the controlpolygon() if i put my lighsource.

I only want to illuminate the house, What am i doing wrong here?

``````#include <GL/glut.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 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) {
glClearColor(1.0, 1.0, 1.0, 1.0);

GLfloat light_position[] = { 12.0, 10.0, 10.0, 0.0 };
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);//Der er op til 8 lyskilder

glEnable (GL_DEPTH_TEST);
glEnable (GL_NORMALIZE);
}

void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(0.0, 0.0, 0.0);
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 */
glPushMatrix();

GLfloat mat_specular_diffuse[] = { 0.8,0.0,0.0,1.0 };
GLfloat mat_shininess[] = { 20.0 };
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular_diffuse);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_specular_diffuse);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);

house ();
glPopMatrix();

glPointSize(5.0);
glColor3f(1.0,0.0,0.0);
glBegin(GL_POINTS);
glVertex3f(12.0,10.0, 10.0);
glEnd();
glPopMatrix ();
glFlush();
}

void reshape(int w, int h)  {
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
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);
}

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();
}
``````

If you want to light up only the house then it’s no more a math topic. Simply enable light only when drawing the house.