Cross-platform light issues
Posted by Al on Jul 22, 2015; 11:10am
URL: https://forum.jogamp.org/Cross-platform-light-issues-tp4034951.html
Hi,
I have some problems with the light of my applications. I create 5 different jar (for Linux 32/64, Win 32/64 et Mac) and for now, I just tested it on Linux 64 and Windows 64.
The problems is that, on Linux, everything works like in my IDE (Eclipse) but on Windows, there is no light displayed. This is not a very very problematic issues, all works fine, but the scene is not very beautiful without a little light..
Any ideas ? Do you already heard about light issues with some OS ? I don't test in Mac and 32bit Linux/ Windows yet.
This is some info to think with:
private void setLighting(GL2 gl) {
gl.glPushMatrix();
gl.glLoadIdentity();
float[] lightPos = new float[4];
// TODO Auto-generated method stub
lightPos[0] = 15;
lightPos[1] = 25;
lightPos[2] = 15;
lightPos[3] = 1;
gl.glEnable(GL2.GL_LIGHTING);
gl.glEnable(GL2.GL_LIGHT0);
float[] noAmbient ={ 0.8f, 0.8f, 0.8f, 1f }; // low ambient light
float[] spec = { 0.8f, 0.8f, 0.8f, 1f }; // low ambient light
float[] diffuse ={ 0.2f, 0.2f, 0.2f, 1f };
FloatBuffer Light1Dir = Buffers.newDirectFloatBuffer(new float[]{-1,-1,-1});
FloatBuffer exponent = Buffers.newDirectFloatBuffer(new float[]{5});
// properties of the light
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, noAmbient, 0);
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, spec, 0);
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, diffuse, 0);
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, lightPos, 0);
gl.glLighti(GL2.GL_LIGHT0, GL2.GL_SPOT_CUTOFF, 50);
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPOT_DIRECTION, Light1Dir);
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPOT_EXPONENT, exponent);
gl.glPopMatrix();
}
This last method is called in there :
@Override
public void display(GLAutoDrawable drawable) {
// TODO Auto-generated method stub
GL2 gl = drawable.getGL().getGL2();
if(justLine)
{
gl.glPolygonMode(GL.GL_BACK, GL2.GL_LINE);
gl.glPolygonMode(GL.GL_FRONT, GL2.GL_LINE);
}
else
{
gl.glPolygonMode(GL.GL_BACK, GL2.GL_FILL);
gl.glPolygonMode(GL.GL_FRONT, GL2.GL_FILL);
}
//camera.look(glu);
// définition de la matrice MODELVIEW à partir de la matrice camera
gl.glClear( GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT );
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadMatrixf(this.camera.getCameraMatrix());
gl.glEnable(GL2.GL_NORMALIZE);
gl.glEnable(GL2.GL_RESCALE_NORMAL);
setLighting(gl); //HERE
gl.glCullFace(GL.GL_FRONT);
gl.glLineWidth(2);
gl.glColor3d(1, 1, 1);
gl.glBegin(GL2.GL_LINES);
gl.glVertex3i(2,2,-2); gl.glVertex3i(-2,2,-2);
gl.glVertex3i(2,2,-2); gl.glVertex3i(2,-2,-2);
gl.glVertex3i(2,2,-2); gl.glVertex3i(2,2,2);
gl.glEnd();
gl.glColor3d(1, 0, 0);
gl.glPushMatrix();
gl.glTranslated(2, 2, 2);
glut.glutSolidCone(0.5, 1, 10, 10);
gl.glColor3d(0, 1, 0);
gl.glTranslated(-4, 0, -4);
gl.glRotated(-90, 0, 1, 0);
glut.glutSolidCone(0.5, 1, 10, 10);
gl.glColor3d(0, 0, 1);
gl.glTranslated(0, -4, -4);
gl.glRotated(90, 1, 0, 0);
glut.glutSolidCone(0.5, 1, 10, 10);
gl.glPopMatrix();
gl.glCullFace(GL.GL_BACK);
gl.glPopMatrix();
gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL2.GL_COLOR_ARRAY);
/**
* Voxels Drawing
*/
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo[0]);
gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vbo[1]);
gl.glColorPointer(4, GL.GL_FLOAT, 0, 0);
gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, vbo[2]);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
gl.glDrawElements(GL2.GL_QUADS, numberVertToDraw, GL.GL_UNSIGNED_INT, 0);
gl.glDisable(GL.GL_BLEND);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
}
and the init method:
@Override
public void init(GLAutoDrawable drawable) {
// TODO Auto-generated method stub
GLProfile.initSingleton();
GL2 gl = drawable.getGL().getGL2();
glu = GLU.createGLU(gl);
glut = new GLUT();
gl.glClearColor(0.0f,0.0f,0.0f,0.0f);
gl.glClearDepth(1.0f);
gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);
gl.glHint(GL2.GL_POINT_SMOOTH_HINT, GL.GL_NICEST);
gl.glShadeModel(GL2.GL_SMOOTH);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity(); // reset
gl.glEnable(GL.GL_DEPTH_TEST);
// turn on backface culling
gl.glEnable(GL.GL_CULL_FACE);
gl.glEnable(GL2.GL_COLOR_MATERIAL);
}
Let me know if you want another infos. Thank you very much for reading that !
EDIT:
New clue: I tried making the light with a white material and, on Windows as on Linux, I see it. In consequences, it seems that the problem comes from attenuation because the light is well here. But I tried to put it manually with that:
gl.glLightf( GL2.GL_LIGHT0, GL2.GL_CONSTANT_ATTENUATION, 0.2f );
And that changes on Linux but nothing on Windows. Anyone already has this problems ?