Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

INTRO

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() {
    enableLighting();

    // 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;
}

PROBLEM

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

QUESTION

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.

CODE

this is my code so far:

gl.glEnable(GL.GL_LIGHTING);
gl.glEnable(GL.GL_LIGHT0);
gl.glEnable(GL.GL_COLOR_MATERIAL);
gl.glShadeModel(GL.GL_SMOOTH);
gl.glShadeModel(GL.GL_FLAT);

Vec3D l = new Vec3D(0,0,-10);
gl.glColor3f(0.8f,0f,0f);
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?
share|improve this question
    
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. –  Byte56 May 31 '12 at 16:45
    
thanks ok you're righrt –  nkint May 31 '12 at 16:51
    
Can you post your code for original geometry and new code with vbo? –  zacharmarz Jun 1 '12 at 5:26
    
ok i've added some code –  nkint Jun 1 '12 at 7:44
add comment

2 Answers

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.

share|improve this answer
    
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) –  nkint May 31 '12 at 16:41
    
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)". –  Grieverheart May 31 '12 at 16:52
    
Do you have specular enabled? The first picture you posted doesn't seem to havee any specular, just diffuse. –  Grieverheart Jun 1 '12 at 10:39
    
sorry.. how can can disable specular light? –  nkint Jun 1 '12 at 10:50
    
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. –  Grieverheart Jun 1 '12 at 11:25
show 1 more comment

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.

share|improve this answer
    
sounds quite weird that is a normal problem because i'm not calculating normals directly but i'm using only mesh.computeFaceNormals(); .. –  nkint Nov 29 '12 at 19:05
    
mesh.computeFaceNormals most likely computes like I said -- it takes the average of the normals of the faces a vertex is connected to. –  ccxvii Nov 29 '12 at 21:43
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.