3 Replies - 1247 Views - Last Post: 01 July 2012 - 08:30 AM Rate Topic: -----

#1 teopp  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 06-March 11

OpenGL - Lighting in a maze

Posted 30 June 2012 - 07:28 PM

Hello there guys,

I need some help on something I'm trying to do, because I can't really figure out what's happening.

I have a maze where a player can walk. The player is the camera (it's a first person game).

So, now I want to do lighting like the player is carrying a lighter with him, which means, the player illuminates the scene as he walks.

Now, I'm having several troubles with this:

- Somehow light doesn't seem to be well positioned, although I'm placing it at camera's (players') position. Even if I call GL_SPOT_DIRECTION it does no effect.
- Some walls sometimes don't appear (walls are cubes).

What I've done so far:

- Depth test is enabled;
- Color material is enabled;
- Specular, diffuse and ambient light of the LIGHT0 (my "moving" light) are set, lighting and light0 are enabled;
- Position of the LIGHT0 is set;

Already tried to:

- Use GL_SPOT_DIRECTION (I didn't figure out if the direction is (x,y,z) of world cordinates or if it's a directional vector ??)
- Tried to define each QUAD normal vectors (heard of vertex normals, didn't figure it out aswell).

So, any lights you guys could give me on this?

Thanks in advance,
teopp

Is This A Good Question/Topic? 0
  • +

Replies To: OpenGL - Lighting in a maze

#2 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 0
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: OpenGL - Lighting in a maze

Posted 30 June 2012 - 09:47 PM

Without code it's near impossible to tell. You have told us about your settings but not your calculations (determining light position, etc.), I don't know how you can be so sure you got that right.
Was This Post Helpful? 0
  • +
  • -

#3 teopp  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 06-March 11

Re: OpenGL - Lighting in a maze

Posted 01 July 2012 - 06:20 AM

I'm sure because the light's position uses the same variables from camera's position. So, if camera's at the right place, light should be aswell, eheh.

Regarding code:

In the init func I set the following:

glShadeModel(GL_SMOOTH);
glEnable(GL_COLOR_MATERIAL);

GLfloat lmodel_ambient[] = {0.0, 0.0, 0.0, 1.0};
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);

GLfloat light_ambient[] = {0.0, 0.0, 0.0, 1.0};
GLfloat light_diffuse[] = {1.0, 1.0, 1.0, 1.0};
GLfloat light_specular[] = {1.0, 1.0, 1.0, 1.0};

glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);



Init materials:

GLfloat no_mat[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat mat_ambient[] = { 0.7, 0.7, 0.7, 1.0 };
GLfloat mat_ambient_color[] = { 0.9, 0.2, 0.2, 1.0 };
GLfloat mat_diffuse[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat no_shininess[] = { 0.0 };
GLfloat low_shininess[] = { 5.0 };
GLfloat high_shininess[] = { 100.0 };
GLfloat mat_emission[] = {0.0, 0.0, 0.0, 0.0};

glMaterialfv(GL_FRONT, GL_AMBIENT, no_mat);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, no_mat);
glMaterialfv(GL_FRONT, GL_SHININESS, no_shininess);
glMaterialfv(GL_FRONT, GL_EMISSION, mat_emission);



Then, in the draw function I do the following:

GLfloat light_position[]={camera.eyex,camera.eyey,camera.eyez,1.0};
glLightfv(GL_LIGHT0, GL_POSITION, light_position);

glEnable(GL_NORMALIZE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

// (... Here matrix operations, viewport, draw objects, etc. ...)

glDisable(GL_NORMALIZE);
glDisable(GL_LIGHTING);
glDisable(GL_LIGHT0);


Was This Post Helpful? 0
  • +
  • -

#4 teopp  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 34
  • Joined: 06-March 11

Re: OpenGL - Lighting in a maze

Posted 01 July 2012 - 08:30 AM

Managed to solve it. In fact, I was trying to set light position before defining the projection and modelview matrix, and the viewport. That's why it wasn't working.

Now I have just another trouble:

- I'm using glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 45.0), but the illumination doesn't work when I'm too too close to an object. Any ways to solve this? Has it to do with the normals?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1