Jump to content
  • Advertisement
Sign in to follow this  
dalahimself

OpenGL ...another opengl newbie...

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

I am just starting to learn openGL and I have a problem which probably is very basic, but I am not sure what is going on. I am simply truing to make a red "floor" and add some lighting. My problem is that when I enable the lighting, ie. glEnable(GL_LIGHTING), the floor becomes white instead of red. If the lighting is disabled the floor is red. The code to draw the floor is given below. Its written in Java using JOGL... Again, if I remove the line "gl.glEnable(GL.GL_LIGHTING);" the floor is red, if I dont, the floor is white/grey... Does anyone know what I am doing wrong?? public void display(GLAutoDrawable gld) { final GL gl = gld.getGL(); float[] lightAmb = {0.5f, 0.5f, 0.5f, 1.0f}; float[] lightDiff = {1.0f, 1.0f, 1.0f, 1.0f}; float[] lightPos = {0.0f, 0.0f, 2.0f, 1.0f}; gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glShadeModel(GL.GL_SMOOTH); gl.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, lightAmb, 0); gl.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE, lightDiff, 0); gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, lightPos, 0); gl.glEnable(GL.GL_LIGHT1); gl.glEnable(GL.GL_LIGHTING); gl.glLoadIdentity(); gl.glTranslatef(0.0f, -1.0f, 0.0f); gl.glColor3f(1.0f, 0.0f, 0.0f); gl.glBegin(GL.GL_QUADS); gl.glVertex3f(10.0f, 0.0f, -10.0f); gl.glVertex3f(-10.0f, 0.0f, -10.0f); gl.glVertex3f(-10.0f, 0.0f, 10.0f); gl.glVertex3f(10.0f, 0.0f, 10.0f); gl.glEnd(); }

Share this post


Link to post
Share on other sites
Advertisement
Have you tried making these smaller values? For a start try to make sure that your ambient term is quite small and your diffuse should be less than 1. In fact you want to make sure that ambient+diffuse+specular <= 1.0

so:

float[] lightAmb = {0.2f, 0.2f, 0.2f, 1.0f};
float[] lightDiff = {0.8f, 0.8f, 0.8f, 1.0f};

to see if it works try making them less than 1.0 in total so that they can't over the top and fully saturate.

Andy

Share this post


Link to post
Share on other sites
Quote:
Original post by NineYearCycle
Have you tried making these smaller values? For a start try to make sure that your ambient term is quite small and your diffuse should be less than 1. In fact you want to make sure that ambient+diffuse+specular <= 1.0

so:

float[] lightAmb = {0.2f, 0.2f, 0.2f, 1.0f};
float[] lightDiff = {0.8f, 0.8f, 0.8f, 1.0f};

to see if it works try making them less than 1.0 in total so that they can't over the top and fully saturate.

Andy




Thanks for the tip but the problem is still there....

Share this post


Link to post
Share on other sites
do you have glColourMaterial enabled? If not, OpenGL will ignore the glColour3f call and use the current material settings, which you can set using glMaterialf.

You probably want to either enable glColourMaterial for front faces, or use glMaterial to set the diffuse component to red.

Share this post


Link to post
Share on other sites
Quote:
Original post by mrbastard
do you have glColourMaterial enabled? If not, OpenGL will ignore the glColour3f call and use the current material settings, which you can set using glMaterialf.

You probably want to either enable glColourMaterial for front faces, or use glMaterial to set the diffuse component to red.



Sorry for being so late to reply, but that fixed my problem... Thanks :)

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!