Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

andyg

Lighting with SDL?

This topic is 5366 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Having problems getting lighting to work properly with OpenGL / SDL (1.2.6) on Linux. I''m using the latest Nvidia driver and GL libs with a Geforce 2. The code I am using worked fine under GLUT, but just does weird stuff under SDL... I''m not sure if i''m missing anything out - most of the tutorials i''ve seen don''t really cover lighting in much depth. Also whenever I call glLoadIdentity(), I get no display at all...
void glInit()
{
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glClearDepth(1.0);
    glShadeModel(GL_SMOOTH);
    glOrtho(-100.0, 100.0, -100.0, 100.0, 100.0, -100.0);
    glMatrixMode(GL_MODELVIEW);
    // glLoadIdentity(); -- fubar
    glEnableClientState(GL_VERTEX_ARRAY);

    // These seem to make some difference, but hard to say what
    glFrontFace(GL_CCW);
    glCullFace(GL_BACK);
    glEnable(GL_CULL_FACE);
}

void initLights()
{
    GLfloat specular[4] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat shininess[1] = { 100.0 };
    GLfloat l1Pos[4] = { 1.0, 1.0, 1.0, 0.0 };
    GLfloat lModelAmbient[] = { 0.5, 0.5, 0.5, 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 };
    GLfloat red[4] = { 1.0, 0.0, 0.0, 1.0 };
    GLfloat lRed[4] = { 1.0, 0.7, 0.7, 1.0 };

    glLightfv(GL_LIGHT1, GL_POSITION, l1Pos);
    glLightfv(GL_LIGHT1, GL_AMBIENT, red);
    glLightfv(GL_LIGHT1, GL_DIFFUSE, lRed);
    glLightfv(GL_LIGHT1, GL_SPECULAR, white);

    //glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
    //glMaterialfv(GL_FRONT, GL_SHININESS, shininess);
    //glMaterialfv(GL_FRONT, GL_DIFFUSE, lilac);

    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lModelAmbient);

    glEnable(GL_LIGHT1);
    glEnable(GL_LIGHTING);
}
 

Share this post


Link to post
Share on other sites
Advertisement
I Don''t think the problem is with SDL, but check your SDL setup code, it does occasionally produce odd results with the wrong bpp.

-------------------------------------------
Here''s to the crazy ones, the misfits, the rebels, the troublemakers, the round pegs in the square holes, the ones who see things differently.
-------------------------------------------

Share this post


Link to post
Share on other sites
Actually, changing the bpp of X or my program doesn''t seem to make a diff.

However if I move the light about, it looks like the right faces are getting lit (the program is to display polyhedrons) but they switch from unlit to fully lit, without any transitional shading. If I set material diffuse colour, thats the colour that will appear on the lit faces, else I get the light''s diffuse colour... To add to the weirdness every now and again a face will randomly get properly shading...

I''m completely bemused... Any ideas whats going on here?

BTW, heres the SDL setup calls i''m using:


GLint videoFlags = SDL_OPENGL;
videoFlags |= SDL_GL_DOUBLEBUFFER;
videoFlags |= SDL_HWPALETTE;
videoFlags |= SDL_RESIZABLE;

if ( videoInfo->blit_hw ) {
printf("Using hardware blit\n");
videoFlags |= SDL_HWACCEL;
}

SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

screen = SDL_SetVideoMode(resX, resY, bpp, videoFlags);


Share this post


Link to post
Share on other sites
You have to enable smooth shading

-------------------------------------------
Here''s to the crazy ones, the misfits, the rebels, the troublemakers, the round pegs in the square holes, the ones who see things differently.
-------------------------------------------

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!