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 08-02-2004, 05:21 PM   #1
poeta_boy
Member
 
Registered: Oct 2003
Location: Mexico
Distribution: Ubuntu
Posts: 223

Rep: Reputation: 31
openGL, glut and lights on C++


Hello everyone:

I have a simple scene in openGl, in my display() I have:

Code:
void renderScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);			
GLfloat lightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f };		
GLfloat ambientPosition[] = {50,50,50,1};		
glLightfv(GL_LIGHT1, GL_AMBIENT, lightAmbient);	
glLightfv(GL_LIGHT1, GL_POSITION, ambientPosition);
glEnable(GL_LIGHT1)

glColor3f(0, 0.9, 0);					
glBegin(GL_QUADS);				
glVertex3f(-100.0f, 0.0f, -100.0f);		
glVertex3f(-100.0f, 0.0f,  100.0f);
glVertex3f( 100.0f, 0.0f,  100.0f);
glVertex3f( 100.0f, 0.0f, -100.0f);
glEnd();

glPushMatrix();
glTranslatef(-40,40,-40);
drawSun();
glPopMatrix();

glPushMatrix();
glTranslatef(-40, 0, -40);
drawWindmill();		
glPopMatrix();

glPushMatrix();
glTranslatef(20, 0, 0);
drawBoy();	
walk();
glPopMatrix();
}
void drawSun()
{	
GLfloat light_position[] = {0,0,0,1};			
GLfloat light_color[] = {1,1,1,1};
glTranslatef(10,10,10);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_color);
glEnable(GL_LIGHT0);
	
glTranslatef(-10, -10, -10);
float size = 10;
glColor3f(1,1,0);
glutSolidSphere(size, 100, 100);
}

int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB);
	
	glShadeModel(GL_SMOOTH);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	
	glutInitWindowPosition(100, 10);
	glutInitWindowSize(700,700);
	glutCreateWindow("My World!");

	glutDisplayFunc(renderScene);
	glutIdleFunc(renderScene);

               glutMainLoop();
	return EXIT_SUCCESS;
}
As you can see drawSun() is just drawing an Sphere and then tries to put a light inside it. But I can't make it work, since if I only add GL_AMBIENT light (at renderScene() )I end up with a black screen, and if I add the light at the drawSun() there appears the light as intended, but everything else loses it's color, it gets only black and white (even tough I do get the light effect, shadows are black and light white).

Why doesn't the ambient light work? thanks

Poeta

Last edited by poeta_boy; 08-02-2004 at 05:23 PM.
 
  


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
where can i download GLUT for openGl resego Linux - Newbie 2 09-15-2005 06:52 PM
newbie to opengl/glut true_atlantis Programming 3 08-28-2005 08:39 PM
Linux WS, OpenGL, and glut? pbail Linux - Software 1 12-16-2004 09:35 AM
[opengl+glut]Please help me hylke Programming 2 05-10-2004 02:16 AM
glut/mesa/openGL gurra Programming 1 10-10-2001 03:36 PM


All times are GMT -5. The time now is 10:57 PM.

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