开发者

GL_COLOR_MATERIAL with lighting on Android

开发者 https://www.devze.com 2022-12-28 05:23 出处:网络
It appears that glColorMaterial() is absent from OpenGL ES. According to this post (for iPhone), you may still enable GL_COLOR_MATERIAL in OpenGL ES 1.x, but you\'re stuck with the default settings of

It appears that glColorMaterial() is absent from OpenGL ES. According to this post (for iPhone), you may still enable GL_COLOR_MATERIAL in OpenGL ES 1.x, but you're stuck with the default settings of GL_FRONT_AND_BACK and GL_AMBIENT_AND_DIFFUSE that you would otherwise set with glColorMaterial(). I would be OK with this, but the diffuse lighting is not working correctly.

I set up my scene and tested it with one light, setting glMaterialfv() for GL_AMBIENT and GL_DIFFUSE once in the initialization. The normals have been set correctly, and lighting works the way it's supposed to. I see the Gouraud shading.

With GL_LIGHTING disabled, the flat colors I have set with glColor4f() appear on the various objects in the scene. This also functions as expected. However, when glEnable(GL_COLOR_MATERIAL) is called, the flat colors rema开发者_如何学编程in. I would expect to see the lighting effects.

glColorMaterial() is also mentioned on anddev.org, but I'm not sure if the information there is accurate.

I'm testing this on an Android 2.1 handset (Motorola Droid).

Edit: It works properly on my 1.6 handset (ADP1). I've filed Issue 8015. It does not work with the emulator for Android 1.6 or 2.1.

Here is a minimal testcase to reproduce the problem.

Screenshot on Android 1.6 (ADP1):

GL_COLOR_MATERIAL with lighting on Android

Screenshot of same code running on Android 2.1 (Motorola Droid):

GL_COLOR_MATERIAL with lighting on Android

Screenshot on Android 1.6 (Emulator):

GL_COLOR_MATERIAL with lighting on Android


This was a silly mistake on my part. Given a 32-bit integer Android color, I had forgotten to scale the color components to floats in the range [0, 1]:

    gl.glColor4f(Color.red(color), Color.green(color), Color.blue(color), Color.alpha(color));

It should have bee like this:

    gl.glColor4f(Color.red(color)/(float) 0xFF, Color.green(color)/(float) 0xFF, Color.blue(color)/(float) 0xFF, Color.alpha(color)/(float) 0xFF);

I'm not sure why the first way still worked on my G1.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号