Hello,
Im kinda confused and banging my head against a brick wall while working with lighting and materials in OpenGL…
I have a single light that may have an ambient/diffuse color, the material may also have an ambient/diffuse color. For some reason when i try to enable my light and model using the code below:
if(Mat.hasAmbient())
{
BaseColour bcAmbient = Mat.getAmbient();
float[] fColours = {bcAmbient.fR, bcAmbient.fG, bcAmbient.fB};
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT, fColours, 0);
}
if(Mat.hasDiffuse())
{
BaseColour bcDiffuse = Mat.getDiffuse();
float[] fColours = {bcDiffuse.fR, bcDiffuse.fG, bcDiffuse.fB};
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_DIFFUSE, fColours, 0);
}
the light is setup shown below:
float TempAmbient[] = {bcAmbient.fR, bcAmbient.fG, bcAmbient.fB, bcAmbient.fA};
gl.glLightfv(intLightID, GL.GL_AMBIENT, TempAmbient, 0);
float TempDiffuse[] = {bcDiffuse.fR, bcDiffuse.fG, bcDiffuse.fB, bcDiffuse.fA};
gl.glLightfv(intLightID, GL.GL_DIFFUSE, TempDiffuse, 0);
float TempSpecular[] = {bcSpecular.fR, bcSpecular.fG, bcSpecular.fB, bcSpecular.fA};
gl.glLightfv(intLightID, GL.GL_SPECULAR, TempSpecular, 0);
float TempPosition[] = {vPosition.fX, vPosition.fY, vPosition.fZ};
gl.glLightfv(intLightID, GL.GL_POSITION, TempPosition, 0);
The light setup is called during the init phase, then when i render i enable lighting and the given light, then i call the material code shown above. However i just get a model with no shading on, i have enabled gl.glShadeModel(GL.GL_SMOOTH); and im baffled…
Are you supposed to use EITHER the light or the material colors rather than using them both, if you cna use them both i thought the diffuse was the shading you have on the model and the ambient was like the base color, however when i enable diffuse color its like the ambient color vanishes and i just get a model in 1 color with no shading…
Any advice related to lighting and materials would be GREAT!