I'm using a Java JOGL wrapper called processing.org and I have coded some environment on it and I'm quite proud of it even if it has some library stuff that I didn't know anything about it (==LIGHTS).

Now, for some geometry, I've decided to use a VBO. I had to pass in the hard way and recode all lights. But I can't achieve the same result.

With that environment if i use the standard lights i get this result:

3d object with processing's standard lights

This environment wrap the opengl functions and i don't manage to understand the pure OPENGL calls.

i know that the code for standard light in processing.org enviroment is:

public void lights() {

    // need to make sure colorMode is RGB 255 here
    int colorModeSaved = colorMode;
    colorMode = RGB;

    lightFalloff(1, 0, 0);
    lightSpecular(0, 0, 0);

    ambientLight(colorModeX * 0.5f, colorModeY * 0.5f, colorModeZ * 0.5f);
    directionalLight(colorModeX * 0.5f, colorModeY * 0.5f, colorModeZ * 0.5f, 0, 0, -1);

    colorMode = colorModeSaved;


I want to replicate this light system with pure openGL calls.

Now, i have done some trial with no succes.

ambient and spot lights:

ad-hoc ambient/spot lights

adding smooth and flat:

ad-hoc smooth and flat lighting


Now, i'd like for someone to help me in analysing the first picture and help me in understanding what kind (light or material or whatever) of OPENGL calls i can use to achieve a similar result.


this is my code so far:


Vec3D l = new Vec3D(0,0,-10);
gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, new float[] { l.x, l.y, l.z, 0 }, 0);
gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPOT_DIRECTION, new float[] { 1, 1, 1 }, 0);
//gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, new float[] { 1, 1, 1}, 0); // if i comment this line nothing change, why?

gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_AMBIENT,        new float[]{1f,0f,0f}, 0);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPOT_DIRECTION, new float[]{1f,0f,0f}, 0);
//gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL.GL_SPECULAR, new float[]{1f, 1f, 1f, 1.0f}, 0);  // if i comment this line nothing change, why?
  • \$\begingroup\$ Your second image said "and this is the FBO" I changed that to VBO since I thought it was a typo (since you don't mention FBOs anywhere else). Just letting you know so you can change it back if that's wrong. \$\endgroup\$
    – House
    Commented May 31, 2012 at 16:45
  • \$\begingroup\$ Can you post your code for original geometry and new code with vbo? \$\endgroup\$
    – zacharmarz
    Commented Jun 1, 2012 at 5:26
  • \$\begingroup\$ ok i've added some code \$\endgroup\$
    – nkint
    Commented Jun 1, 2012 at 7:44

2 Answers 2


It seems to me that you're either passing smooth normals or have smooth shading enabled in the 2nd picture compared to the first one, but I can't really tell with just what you have posted.

  • \$\begingroup\$ yeah i use normals but if i remove them i don't have any other light apart from ambiental (flat color no shadow like in the first pic) \$\endgroup\$
    – nkint
    Commented May 31, 2012 at 16:41
  • \$\begingroup\$ Of course you need normals, but you need to check if the vertices of a face have different normals. For the same shading as the first picture, the vertices of a given face need to have the same normals. Also check if you have "glShadeModel(GL_SMOOTH)" enabled by using "glShadeModel(GL_FLAT)". \$\endgroup\$ Commented May 31, 2012 at 16:52
  • \$\begingroup\$ Do you have specular enabled? The first picture you posted doesn't seem to havee any specular, just diffuse. \$\endgroup\$ Commented Jun 1, 2012 at 10:39
  • \$\begingroup\$ sorry.. how can can disable specular light? \$\endgroup\$
    – nkint
    Commented Jun 1, 2012 at 10:50
  • \$\begingroup\$ You set its color to 0. You should probably post your code or at least part of it. The post you linked is quite different from what you want to achieve. \$\endgroup\$ Commented Jun 1, 2012 at 11:25

Check your normals!

In the first image, each face has three vertices with the same normal as the face. These vertices are not shared between faces.

In your data, each vertex is shared by multiple faces. As such, it has a normal computed from the average of the normals of all the faces it's connected to.

You need to re-export your data, to get the normals you want. Either that, or re-compute normals per face. Just remember that you can't share vertices between faces.

  • \$\begingroup\$ sounds quite weird that is a normal problem because i'm not calculating normals directly but i'm using only mesh.computeFaceNormals(); .. \$\endgroup\$
    – nkint
    Commented Nov 29, 2012 at 19:05
  • \$\begingroup\$ mesh.computeFaceNormals most likely computes like I said -- it takes the average of the normals of the faces a vertex is connected to. \$\endgroup\$
    – ccxvii
    Commented Nov 29, 2012 at 21:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .