...another opengl newbie...

Started by
3 comments, last by dalahimself 15 years, 5 months ago
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(); }
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

"Ars longa, vita brevis, occasio praeceps, experimentum periculosum, iudicium difficile"

"Life is short, [the] craft long, opportunity fleeting, experiment treacherous, judgement difficult."

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....
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.
[size="1"]
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 :)

This topic is closed to new replies.

Advertisement