glColorMaterial

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

glColorMaterial

Postby The Crusher » Thu Jan 21, 2010 8:29 pm

Hi,

Is glColorMaterial supported? And if so, which APIs? I can't find it or get it to work. I'm trying to generate a terrain with lots of polygons in a grid, and I don't want them to all be the same color, but I can't imagine drawing this thing one polygon at a time. Surely there's some kind of solution available?

More generally, how do I find out what's supported in a particular API (either in terms of OpenGL, or just in general).

Thanks,

tom
The Crusher
Freshman
Freshman
 
Posts: 2
Joined: Thu Jan 21, 2010 8:22 pm
Location: Cambridge, Massachusetts

Top

Postby zorro » Fri Jan 22, 2010 10:35 pm

You don't have to use glColorMaterial to obtain a colorful terrain. You can define an array of colors, the same size as your vertex array. This way each vertex will have it's own color. At rendering tme, you must enable the color array (gl.glEnable(GL10.Gl_COLOR_ARRAY) and bind the color buffer (gl.glColorPointer(4, GL_FLOAT, 0, colorBuffer) and you should see the colors applied on the terrain. You can combine the color buffer with textures as well.
User avatar
zorro
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Mon Aug 10, 2009 3:11 pm
Location: Romania

Postby The Crusher » Sat Jan 23, 2010 3:18 am

It's my understanding that I can only do that with lighting disabled. As soon as I enable a light source color comes from material and. There is no material pointer or array command. But, if glColorMaterial is available, I can change the color part of the material with glColorPointer. But no joy there.

It looks like the only way to do it in Android is to put a texture across the mesh. Or forget about lighting.

tom
The Crusher
Freshman
Freshman
 
Posts: 2
Joined: Thu Jan 21, 2010 8:22 pm
Location: Cambridge, Massachusetts

Postby zorro » Sat Jan 23, 2010 2:08 pm

If I remember correctly, yes, you are right. You have to choose between the lighting or the color. It's a shame that Android does not support by default OpenGL ES 2.0, because the problem is solved very easy with shaders :(
User avatar
zorro
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Mon Aug 10, 2009 3:11 pm
Location: Romania

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 6 guests