Question

i am tring to add a light. but when i try to modify the position netbeans highlights the gl.glLightfv method. its not just with the position its with diffuse and ambient too... what i am do wrong... here is my code.

all the hits say that:

no suitable method found for glLightfv(int,int,float[]) method javax.media.opengl.GL.glLightfv(int,int,float[],int) is not applicable (actual and formal argument lists differ in length) method javax.media.opengl.GL.glLightfv(int,int,java.nio.FloatBuffer) is not applicable (actual argument float[] cannot be converted to java.nio.FloatBuffer by method invocation conversion)

float pos[] = {-2.0f, 2.0f, -3.0f, 1.0f };
gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, pos); //underlinded red:
float dif[] = {1.0f,1.0f,1.0f,1.0f};
gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, dif);  //underlinded red:
float amb[] = {0.2f,0.2f, 0.2f, 1.0f};
gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, amb);  //underlinded red:
Était-ce utile?

La solution

If you want to use float array instead of FloatBuffer class, you'll have to add one more parameter, which says where (in the array) should OpenGL start look for your parameters -> array index offset value..

In your case

float pos[] = {-2.0f, 2.0f, -3.0f, 1.0f };
gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, pos, 0);
float dif[] = {1.0f,1.0f,1.0f,1.0f};
gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, dif, 0);
float amb[] = {0.2f,0.2f, 0.2f, 1.0f};
gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, amb, 0);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top