Hi

I am playing with OpenGL and especially light in OpenGL. I have tried
to set light in the GLSurfaceView application in ApiDemos (Under
Graphics / OpenGL ES).

I just try to set the light as simple as I can. Therefore I just add a
few lines to CubeRenderer.drawFrase so that it looks as shown below. I
get some light effect, but it does not look like the light is
constantly comming from one direction. I looks like the light source
is also flying around. Why is that?

    public void drawFrame(GL10 gl) {
        /*
         * Usually, the first thing one might want to do is to clear
         * the screen. The most efficient way of doing this is to use
         * glClear().
         */

        gl.glClear(GL10.GL_COLOR_BUFFER_BIT |
GL10.GL_DEPTH_BUFFER_BIT);

        /*
         * Now we're ready to draw some 3D objects
         */

        gl.glMatrixMode(GL10.GL_MODELVIEW);
        gl.glLoadIdentity();


        // Here start of lines I have added to get "light"
        gl.glEnable(gl.GL_LIGHTING);
        gl.glEnable(gl.GL_LIGHT0);

        float ambientLight[] = { 0.0f, 0.0f, 0.0f, 1.0f };
        float diffuseLight[] = { 1.0f, 1.0f, 1.0f, 1.0f };
        float specularLight[] = { 1.0f, 1.0f, 1.0f, 1.0f };
        float position[] = { 3.0f, 3.0f, 3.0f };

        gl.glLightfv(gl.GL_LIGHT0, gl.GL_POSITION, position, 0);
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_AMBIENT, ambientLight, 0);
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_DIFFUSE, diffuseLight, 0);
        gl.glLightfv(gl.GL_LIGHT0, gl.GL_SPECULAR, specularLight, 0);
        // Here end of lines I have added to get "light"

        gl.glTranslatef(0, 0, -3.0f);
        gl.glRotatef(mAngle,        0, 1, 0);
        gl.glRotatef(mAngle*0.25f,  1, 0, 0);

        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glEnableClientState(GL10.GL_COLOR_ARRAY);

        mCube.draw(gl);

        gl.glRotatef(mAngle*2.0f, 0, 1, 1);
        gl.glTranslatef(0.5f, 0.5f, 0.5f);

        mCube.draw(gl);

        mAngle += 1.2f;
    }

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to