NeHe07 & Lighting problem

Hi,

Anybody are try the NeHe07 with the LWJGL V0.7 ?
When i turn on the lighting, anyone is displayed, the screen stay in black color! :-/

What’s wrong ??

I got the same problem… ???

My PC’s specs are:
AthlonXP, GeForce2Ti, win98se, nVidia Drivers 40.*

Is this with your own port of NeHe 7, or Ch*mans?

Cas :slight_smile:

With the demos in the LWJGL site…

Hi, ;D

what type of Light you use ?
Or is it to far away from any Object ?
For me the 0.7 Light ing works well.
Maybe some Colors are set to dark, empty buffers ?

I init some Scene like this:


          // create Colors
          float[] global_ambient = new float[]
                             {
                             0.0f , 0.0f , 0.0f , 1.0f} ; // Set Ambient Lighting To Fairly Dark Light (No Color)
          float[] light0pos = new float[]
                        {
                        0.0f , 5.0f , 10.0f , 1.0f} ; // Set The Light Position
          float[] light0ambien = new float[]
                           {
                           0.0f , 0.0f , 0.0f , 1.0f} ; // More Ambient Light
          float[] light0diffuse = new float[]
                            {
                            0.0f , 0.0f , 0.0f , 1.0f} ; // Set The Diffuse Light A Bit Brighter
          float[] light0specular = new float[]
                             {
                             0.0f , 0.0f , 0.0f , 1.0f} ; // Fairly Bright Specular Lighting

          // Create Buffer

          // warp Color Buffers
          global_ambientBuffer.put ( global_ambient ).flip () ;
          global_light0posBuffer.put ( light0pos ).flip () ;
          global_light0ambienBuffer.put ( light0ambien ).flip () ;
          global_light0diffuseBuffer.put ( light0diffuse ).flip () ;
          global_light0specularBuffer.put ( light0specular ).flip () ;

          GL.glLightModel ( GL.GL_LIGHT_MODEL_AMBIENT , global_ambientBuffer ) ; // Set The Ambient Light Model

          GL.glLightModel ( GL.GL_LIGHT_MODEL_AMBIENT , global_ambientBuffer ) ; // Set The Global Ambient Light Model
          GL.glLightfv ( GL.GL_LIGHT0 , GL.GL_POSITION ,
                     global_light0posBuffer ) ; // Set The Lights Position
          GL.glLightfv ( GL.GL_LIGHT0 , GL.GL_AMBIENT ,
                     global_light0ambienBuffer ) ; // Set The Ambient Light
          GL.glLightfv ( GL.GL_LIGHT0 , GL.GL_DIFFUSE ,
                     global_light0diffuseBuffer ) ; // Set The Diffuse Light
          GL.glLightfv ( GL.GL_LIGHT0 , GL.GL_SPECULAR ,
                     global_light0specularBuffer ) ; // Set Up Specular Lighting
          GL.glEnable ( GL.GL_LIGHTING ) ; // Enable Lighting
          GL.glEnable ( GL.GL_LIGHT0 ) ; // Enable Light0



Hope the snippet helps :wink:

  • Jens

Thanks Jens,

I found what was producing the error…
The code in Nehe07 example from LWJGL’s site says:

...
ByteBuffer temp = ByteBuffer.allocateDirect(16);
temp.order(ByteOrder.nativeOrder());
// Setup The Ambient Light
GL.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT,temp.asFloatBuffer().put(LightAmbient));
...

There aren’t calls to the flip() method. So I fixed this with:

...
ByteBuffer temp = ByteBuffer.allocateDirect(16);
temp.order(ByteOrder.nativeOrder());
// Setup The Ambient Light
FloatBuffer fb = temp.asFloatBuffer().put(LightAmbient);
fb.flip();
GL.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, fb);
...

And now works!!

Now I need to learn NIO…

Rafael