Cross-platform light issues

classic Classic list List threaded Threaded
2 messages Options
Al
Reply | Threaded
Open this post in threaded view
|

Cross-platform light issues

Al
This post was updated on .
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 ?
Reply | Threaded
Open this post in threaded view
|

Re: Cross-platform light issues

Xerxes Rånby
When you use "Fixed Function Pipeline", FFP, light is a feature that you enable or disable at the driver level.
You are likely able to expose many differences in OpenGL driver implementation when you are using the FFP.

If you check glError after each opengl call, you may discover that the Windows OpenGL driver returns an error that the light feature you tried to enable was not supported by the driver.
You can easily check glError after each opengl call without modifying your application by running your application with
 -Djogl.debug.DebugGL
http://jogamp.org/wiki/index.php/How_to_use_the_Debug_and_Trace_GL_Pipeline_and_Debug_GL_Context


If you want light inside your application to behave the same on all hardware and opengl drivers then it is highly recommend that you start using the programmable pipeline using shaders.
You are then in control how the light in your application should behave.
https://jogamp.org/jogl/doc/Overview-OpenGL-Evolution-And-JOGL.html


The default OpenGL driver shipped with Windows only implements OpenGL 1.1.
Thus it is expected that the default windows OpenGL driver is severely limited in functionality.

Most windows users workaround this limitation by installing an updated OpenGL driver from their GPU vendor such as nvidia or amd.
The only solution that Microsoft give to the driver situation is to ship your application with a precompiled opengl es -> direct3d translator that allow you to use programmabel shaders on all windows devices.
we have earmarked this as a potential future enhancement to bundle a precompiled opengl es -> direct 3d translator using lib ANGLE with jogl.
https://jogamp.org/bugzilla/show_bug.cgi?id=1179