Jump to content
  • Advertisement
Sign in to follow this  
iSina

Shading and Lighting

This topic is 3621 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

Greetins again, Since the question has changed I have advised to open a new thread. This time my problem is with lighting and shading. I have gone through several tutorials to see how it works but I havent been able to give shades to my materials (I also tried to move lightfv and materialfv into the drawGL body but that didnt work either This is the initGL function which creates the perspective, light and materials effects
sub InitGL {              

    my ($width, $height) = @_; 
							
	glShadeModel(GL_SMOOTH);						
	glClearColor(0.0, 0.0, 0.0, 0.5);				
	glClearDepth(1.0);							
	glEnable(GL_DEPTH_TEST);						
	glDepthFunc(GL_LEQUAL);						
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	
	
	glLightfv_p(GL_LIGHT0, GL_POSITION, @Light_Position);
	glLightfv_p(GL_LIGHT0, GL_SPECULAR, @Light_Specular);
	glLightfv_p(GL_LIGHT0, GL_AMBIENT,  @Light_Ambient);
	glLightfv_p(GL_LIGHT0, GL_DIFFUSE,  @Light_Diffuse);
	glLightfv_p(GL_LIGHT0, GL_SPOT_DIRECTION, @Spot_Light_Position);
	glLightfv_p(GL_LIGHT0, GL_SPOT_CUTOFF, 45.0);
	glLightfv_p(GL_LIGHT0, GL_SPOT_EXPONENT, 2.0);
	
	glMaterialfv_p (GL_FRONT, GL_AMBIENT, @Ambient_Material);
	glMaterialfv_p (GL_FRONT, GL_SPECULAR, @Specular_Material);
	glMaterialfv_p (GL_FRONT, GL_SHININESS, @Shiny_Material);
	
	glEnable(GL_LIGHT0);
	glEnable(GL_LIGHTING);
	glShadeModel(GL_SMOOTH);
	glEnable(GL_COLOR_MATERIAL);
	glColorMaterial(GL_FRONT, GL_DIFFUSE);
	
	glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
	glEnable(GL_COLOR_MATERIAL);

    gluPerspective(45.0, $width/$height, 0.1, 100.0);

}
These are the relevant arrays
our @Light_Ambient  = (0.2, 0.2, 0.2, 1.0);
our @Light_Diffuse  = (1.0, 1.0, 1.0, 1.0);
our @Light_Specular = (1.0, 1.0, 1.0, 1.0);
our @Light_Position = ( 0.0, 0.0, 1.0, 1.0 );
our @Spot_Light_Position = (-1.0, -1.0, 0.0);
our @Ambient_Material = (0.1, 0.5, 0.8, 1.0);
our @Specular_Material = (1.0, 1.0, 1.0, 1.0);
our @Shiny_Material = (5.0);
And this is the start of the draw scene (the rest only draws the shapes) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glColor4f(0.2,0.8,0.6,.95);

Share this post


Link to post
Share on other sites
Advertisement
Try to include this between your other glMaterialfv calls:

glMaterialfv_p (GL_FRONT, GL_DIFFUSE, @Diffuse_Material);

Where (values - modify to whatever color you'd like)

our @Diffuse_Material = (0.1, 1.0, 1.0, 1.0);


You're not setting diffuse paramter - that might cause issues when drawing.

Share this post


Link to post
Share on other sites
http://www.opengl.org/resources/code/samples/redbook/

This has a lot of good lighting examples, especially the teapots.c and material.c examples. Look through that and other to see if it helps.

Share this post


Link to post
Share on other sites
I added it and it didnt work. Does it matter whether I set these values while drawing the scene or anywhere else in the program? It doesnt work either way but I am just asking

Share this post


Link to post
Share on other sites
Thanks for the tutorials. I have gone through the ones you mentioned, they seem to add nothing else extra. I changed my light settings completely as to one of the examples there. And it still won't be, I wonder what is the problem sigh... Is it possible that it is a problem with my computer? The perl opengl display systems are shown as:

nVidia (Quadro-110M,5200,6600,6800,7300,7800,7950,8600,8800)
ATI (Radeon X1900/9000/9200, FireGL)
Cygwin/X (Mesa)

but I have ATI radeon X300. I will try updating my screen card drivers if there is a newer version.


sub InitGL {

my ($width, $height) = @_;
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH);
glMaterialfv(GL_FRONT, GL_SPECULAR, @Specular_Material);
glMaterialfv(GL_FRONT, GL_SHININESS, @Shiny_Material);
glLightfv(GL_LIGHT1, GL_POSITION, @Light_Position);

glEnable(GL_LIGHTING);
glEnable(GL_LIGHT1);



#setScene();
gluPerspective(45.0, $width/$height, 0.1, 100.0);

}



our @Light_Position = ( 0.0, 0.0, 1.0, 1.0 );
our @Specular_Material = (1.0, 1.0, 1.0, 1.0);
our @Shiny_Material = (50.0 );



sub DrawGLScene {

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.5, 0.0, -6.0);

glColor4f(0.9,0.2,0.2,.75);


glTranslatef(0.0,0.0,$Z_Off);
glRotatef($Y_Speed,0.0,1.0,0.0);
glRotatef($X_Speed,1.0,0.0,0.0);

## drawing part here



[Edited by - iSina on July 19, 2008 6:05:15 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!