LWJGL lighting

I’ve made a simple class that draws a line of specified color. At first everything seemed fine, but when navigating the scene, lines of the same specified color are different. Some darker and lighter than others. The scene uses default lighting.



When modifying the Line class to try and override JME default lighitng with hard coded LWJGL lighting the lines all turn out black. Does anyone see what I’m missing in the code below?



Thanks.



Lynn



package ZSMissionOverview;



import java.util.logging.Level;



import com.jme.math.Vector2f;

import com.jme.math.Vector3f;

import com.jme.renderer.ColorRGBA;

import com.jme.renderer.Renderer;

import com.jme.util.LoggingSystem;



import com.jme.scene.;

import com.jme.scene.state.
;

import com.jme.util.;

import com.jme.image.
;

import com.jme.light.;



import java.util.
;

import java.lang.Math;

import java.io.;

import java.nio.
;



import org.lwjgl.opengl.GL11;



public class ZSMOLine extends Spatial

{

private LinkedList _vertexList;

private ColorRGBA _color;

private ZSMOContext _zsMOContext;



public ZSMOLine(String name)

{

super(name);

}



public ZSMOLine(String name,LinkedList vertexList,ColorRGBA color,ZSMOContext zsMOContext)

{

super(name);

_vertexList = vertexList;

_color = color;

_zsMOContext = zsMOContext;



LoggingSystem.getLogger().log(Level.INFO, “Line created.”);

}



public void updateWorldBound(){}



public void drawBounds(Renderer r){}



public void draw(Renderer r)

{

GL11.glPushAttrib(GL11.GL_CURRENT_BIT | GL11.GL_LINE_BIT | GL11.GL_FOG_BIT);

{

GL11.glEnable(GL11.GL_LIGHTING);

GL11.glDisable(GL11.GL_FOG);

GL11.glDisable(GL11.GL_BLEND);



GL11.glLightModeli(GL11.GL_LIGHT_MODEL_LOCAL_VIEWER, GL11.GL_FALSE);

GL11.glLightModeli(GL11.GL_LIGHT_MODEL_TWO_SIDE, GL11.GL_FALSE);



float light_position[] = { 0.0f, 0.0f, 1.0f, 0.0f };

float light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };



FloatBuffer positionBuffer = ByteBuffer.allocateDirect(16)

.order(ByteOrder.nativeOrder()).asFloatBuffer();

positionBuffer.put(light_position);

positionBuffer.flip();



FloatBuffer ambientBuffer = ByteBuffer.allocateDirect(16)

.order(ByteOrder.nativeOrder()).asFloatBuffer();

ambientBuffer.put(light_ambient);

ambientBuffer.flip();



GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION,positionBuffer);

GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE,ambientBuffer);

GL11.glLightf(GL11.GL_LIGHT0, GL11.GL_CONSTANT_ATTENUATION, 0.0f);



GL11.glEnable(GL11.GL_LIGHT0);



GL11.glColor4f(_color.r,_color.g,_color.b,_color.a);

GL11.glLineWidth(0.5f);

GL11.glLineStipple(4, (short)0xAAAA);

GL11.glEnable(GL11.GL_LINE_STIPPLE);



GL11.glBegin(GL11.GL_LINE_STRIP);



for(int i = 0;i < _vertexList.size();i++)

{

Vector3f v2 = (Vector3f)_vertexList.get(i);

GL11.glVertex3f(v2.x,v2.y,v2.z);

}

GL11.glEnd();

}

GL11.glPopAttrib();

}



public void update(){}



public void updateVertices(LinkedList vertexList)

{

_vertexList = vertexList;

}

public void setColor(ColorRGBA color)

{

_color = color;

}

}

I don’t want them to be affected by lighting at alll.



Disabling the light state didn’t seem to have any effect. I think I’m just going to wait & revisit this after JME makes use of the next revision of LWJGL. Thanks for the response.



Lynn

Generic advice as I have not tried your posted code:



Set a default disabled lightstate on the lines and call setLightCombineMode(LightState.REPLACE) on your lines.



Also, make sure you aren’t passing down any textures to the lines via a parent.