LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

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

Rep: Reputation: 30
OpenGL lighting with SDL


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


Reply


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 10:47 AM.

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