Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have some problem with lights in my opengl "game". I have board with is square (-50,50), (50, 50), (50, -50), (-50,-50) x and z since y doesn't matter at all.

I tried to make something like flashlight its moving and rotating with camera (me), but when i try to rotate more then 90 degree to left or right it just give diffrend light: http://imageshack.us/photo/my-images/688/lightij.jpg/

(left is spotlight, right point light) There is also a point light in the middle, but its working strange(not like a pointlight) it shines only on half of the board from (-50,50), (50, 50), (50, 0), (-50,-0) x and y:

Link to my repo where u can find game exe in download and full code in source: https://bitbucket.org/mlodziaszka/my_game

All more fragments of light:

float gl_amb[] = { 0.2f, 0.2f, 0.2f, 1.0f };
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, gl_amb);

glEnable(GL_LIGHTING); // Wlaczenie oswietlenia
glShadeModel(GL_SMOOTH); // Wybor techniki cieniowania
glEnable(GL_LIGHT0); // Wlaczenie 0-go zrodla swiatla
glEnable(GL_LIGHT1);

Cubes parametri:

float m1_amb[] = { 1.0f, 0.0f, 0.0f, 1.0f };
float m1_dif[] = { 1.0f, 0.0f, 0.0f, 1.0f };
float m1_spe[] = { 1.0f, 0.0f, 0.0f, 1.0f };
glMaterialfv(GL_FRONT, GL_AMBIENT, m1_amb);
glMaterialfv(GL_FRONT, GL_DIFFUSE, m1_dif);
glMaterialfv(GL_FRONT, GL_SPECULAR, m1_spe);
glMaterialf(GL_FRONT, GL_SHININESS, 50.0f);

Texture parametri:

float m1_amb[] = { 1.0f, 1.0f, 1.0f, 1.0f };
float m1_dif[] = { 1.0f, 1.0f, 1.0f, 1.0f };
float m1_spe[] = { 1.0f, 1.0f, 1.0f, 1.0f };
glMaterialfv(GL_FRONT, GL_AMBIENT, m1_amb);
glMaterialfv(GL_FRONT, GL_DIFFUSE, m1_dif);
glMaterialfv(GL_FRONT, GL_SPECULAR, m1_spe);
glMaterialf(GL_FRONT, GL_SHININESS, 0.0f);
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

Light0: //with some magic sn't working anyway

float l0_amb[] = { 0.2f, 0.2f, 0.2f, 1.0f };
float l0_dif[] = { 1.0f, 1.0f, 1.0f, 1.0f };
float l0_spe[] = { 1.0f, 1.0f, 1.0f, 1.0f };

float l0_pos[] = { g_Camera.m_vPosition.x, g_Camera.m_vPosition.y,        g_Camera.m_vPosition.z, 1.0f };

float temp = 0.0f, temp2 = 0.0f, temp3 = 0.0f;

if(g_Camera.m_vView.z < g_Camera.m_vPosition.z)
{
    temp = g_Camera.m_vView.x - g_Camera.m_vPosition.x;
temp2 = g_Camera.m_vView.z - g_Camera.m_vPosition.z;
 }
else
{
temp = g_Camera.m_vView.x - g_Camera.m_vPosition.x;
temp2 = g_Camera.m_vView.z - g_Camera.m_vPosition.z;
}

float l0_pos1[] = {temp, 0.0f, temp2};
//float l0_pos1[] = {-1.0f, 0.0f, -1.0f};

glLightfv(GL_LIGHT0, GL_AMBIENT, l0_amb);
glLightfv(GL_LIGHT0, GL_DIFFUSE, l0_dif);
glLightfv(GL_LIGHT0, GL_SPECULAR, l0_spe);
glLightfv(GL_LIGHT0, GL_POSITION, l0_pos);

glLightf (GL_LIGHT0, GL_SPOT_CUTOFF, 15.0f);
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, l0_pos1);

Light1:

float l1_amb[] = { 0.2f, 0.2f, 0.2f, 1.0f };
float l1_dif[] = { 1.0f, 1.0f, 1.0f, 1.0f };
float l1_spe[] = { 1.0f, 1.0f, 1.0f, 1.0f };
float l1_pos[] = { 0.0f, 0.0f, 0.0f, 1.0f };
glLightfv(GL_LIGHT1, GL_AMBIENT, l1_amb);
glLightfv(GL_LIGHT1, GL_DIFFUSE, l1_dif);
glLightfv(GL_LIGHT1, GL_SPECULAR, l1_spe);
glLightfv(GL_LIGHT1, GL_POSITION, l1_pos);

I know that way I made this very old, but for now i want to keep this like that.

I wouldbe realy gratefull if someone can tell me what is wrong with my lights xD

full code: link up ^^

share|improve this question

closed as too localized by Byte56, Trevor Powell, Josh Petrie, bummzack, Sean Middleditch Dec 28 '12 at 7:04

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

up vote 3 down vote accepted

You haven't set normals on the vertices of the meshes you're drawing. You'll need normals, for lighting to be calculated.

share|improve this answer
    
shouldn't fixed pipeline do this automatic? –  mlodziaszka Nov 25 '12 at 12:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.