Hey
Have been trying to use SDL for something I did easily with GLUT, only prob is lighting doesn't work...
I used exactly the same code for initialising OpenGL and lighting but all I get is the buffer displayed in the diffuse material colour.
I noticed that the light is positioned at z -50.0, putting it behind the object i'm drawing. If I change this to +ve 50.0, I just get a dark shape in place of the object. Whats with this?
Do I need to use SDL_GL_SetAttribute() to set particular values for alpha, red-size etc?
Heres the functions:
Code:
void glInit()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glClearDepth(1.0);
glShadeModel(GL_SMOOTH);
glOrtho(-100.0, 100.0, -100.0, 100.0, 100.0, -100.0);
glMatrixMode(GL_MODELVIEW);
glEnableClientState(GL_VERTEX_ARRAY);
}
void initLights()
{
GLfloat specular[4] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat shininess[1] = { 100.0 };
GLfloat l0Pos[4] = { 1.0, 1.0, -50.0, 0.0 };
GLfloat lModelAmbient[] = { 0.1, 0.1, 0.1, 1.0 };
GLfloat white[4] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat lilac[4] = { 0.4, 0.0, 0.7, 1.0 };
GLfloat lLilac[4] = { 0.6, 0.0, 0.9, 1.0 };
glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
glMaterialfv(GL_FRONT, GL_SHININESS, shininess);
glMaterialfv(GL_FRONT, GL_DIFFUSE, lilac);
glLightfv(GL_LIGHT0, GL_POSITION, l0Pos);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lilac);
glLightfv(GL_LIGHT0, GL_SPECULAR, lLilac);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lModelAmbient);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}