LIGHTING On the Earth model

classic Classic list List threaded Threaded
3 messages Options
ahn
Reply | Threaded
Open this post in threaded view
|

LIGHTING On the Earth model

ahn
Hi. I am trying to implement the Earth model.
I have already rendered the Earth model with texture.

now, I want to put lighting effect on the Earth but It never works.

Could anybody comment on my source code??

below is source code and screen shot for the result

public void display(GLAutoDrawable drawable) {
        //***************TEXTURE MAPPING***************//
        // Enables this texture's target in the current GL context's state.
        gl.glBegin(GL2.GL_TRIANGLES);
        for (Triangle t: theEarth.triangles) {
        gl.glNormal3d(t.a, t.b, t.c);        //surface normal of the triangle
       
        Vertex p0, p1, p2;
        p0 = theEarth.vertices[t.v0];
        p1 = theEarth.vertices[t.v1];
        p2 = theEarth.vertices[t.v2];
       
        gl.glTexCoord2d(p0.u, p0.v);
        gl.glVertex3d(p0.x, p0.y, p0.z);
       
        gl.glTexCoord2d(p1.u, p1.v);
        gl.glVertex3d(p1.x, p1.y, p1.z);
       
        gl.glTexCoord2d(p2.u, p2.v);
        gl.glVertex3d(p2.x, p2.y, p2.z);
       
        }
        gl.glEnd(); // of the tessellated sphere
      //***************TEXTURE MAPPING***************//

      //***************LIGHTING***************//                  <------- this part is not working :(
        // light to light up the scene. Ambient's value in RGBA
        float[] lightAmbientValue = {0.1f, 0.1f, 0.1f, 1.0f};
        // Diffuse light comes from a particular location. Diffuse's value in RGBA
        float[] lightDiffuseValue = {1.0f, 1.0f, 1.0f, 1.0f};
        // Diffuse light location xyz (in front of the screen).
        float lightDiffusePosition[] = {0.0f, 2.0f, 2.0f, 1.0f};
        gl.glLightfv(GL2.GL_LIGHT0, GL_AMBIENT, lightAmbientValue, 0);
        gl.glLightfv(GL2.GL_LIGHT0, GL_DIFFUSE, lightDiffuseValue, 0);
        gl.glLightfv(GL2.GL_LIGHT0, GL_POSITION, lightDiffusePosition, 0);
        gl.glEnable(GL2.GL_LIGHT0);
      //***************LIGHTING***************//

      //***************CAMERA MOVEMENT***************//
        gl.glLoadIdentity();  // reset the model-view matrix
        glu.gluLookAt(posX, posY, posZ, posX, 0, 0, 0, 1, 0);
      //***************CAMERA MOVEMENT***************//
}






Thanks for reading my message :)
Reply | Threaded
Open this post in threaded view
|

Re: LIGHTING On the Earth model

gouessej
Administrator
Hi

Which kind of lighting do you want to put on your Earth model?

You have to call glNormal3f for each vertex to pass the normal, use glShadeModel to choose your shading model, call GL2.glEnable(GL2.GL_LIGHTING), call glLight to set the light parameters and glEnable(GL2.GL_LIGHT1) to enable the first light for example. If you don't know these methods, look at the OpenGL SDK documentation.

It's possible to implement it with shaders but it's harder.

By the way, you should switch to vertex arrays or VBOs instead of using immediate mode (glBegin/glEnd, ...).

Look at jogl-demos on Github if you need some examples. Good luck.
Julien Gouesse | Personal blog | Website
ahn
Reply | Threaded
Open this post in threaded view
|

Re: LIGHTING On the Earth model

ahn
Thanks a million! :)