Share your knowledge at the LQ Wiki.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-21-2003, 11:52 AM   #1
Registered: Jul 2003
Distribution: Slackware 9.1
Posts: 195

Rep: Reputation: 30
OpenGL lighting with SDL


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:

void glInit() 
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glOrtho(-100.0, 100.0, -100.0, 100.0, 100.0, -100.0);

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);



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using SDL/OpenGL, need help. kornerr Programming 33 11-19-2005 11:19 PM
sdl / opengl - cant press up and right atrain Linux - Games 2 03-27-2005 11:29 PM
lighting in OpenGL (with C language) sterrenkijker Programming 4 08-24-2004 03:20 AM
OpenGL and SDL programming with Slackware zsejk Slackware 13 08-03-2004 07:52 PM
Using OpenGL (+SDL) for 2D programs R00ts Programming 4 07-16-2004 12:33 PM

All times are GMT -5. The time now is 11:01 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration