glColorMaterial on OpenGL ES on Iphone
Hey Guys,
last night I tried to find some info about glColorMaterial(..,..) for the Iphone.
I want my Objects to be very simple shiny blocks that all have their color after the ColorPointer.
Since I'm having a lot of Blocks I use only one glElementsDraw to draw them all from one big interleaved array, so changing the color before I draw a single one is not an option.
Now since there's no glColorMaterial inside gl.h, I'm beginning to think that's maybe not possible on the Iphone.
How can I do it without glColorMaterial?
last night I tried to find some info about glColorMaterial(..,..) for the Iphone.
I want my Objects to be very simple shiny blocks that all have their color after the ColorPointer.
Since I'm having a lot of Blocks I use only one glElementsDraw to draw them all from one big interleaved array, so changing the color before I draw a single one is not an option.
Now since there's no glColorMaterial inside gl.h, I'm beginning to think that's maybe not possible on the Iphone.
How can I do it without glColorMaterial?
To make this clearer and bump up the thread.
I like to have several blocks that look the same except for their color.
They should all be shiny and glossy, with maybe a little light being emitted by themselves.
On the normal OpenGL I understand I would do that by glColorMaterial and its options.
On the Iphone that doesn't seem to be an option (or is it?). So is there another way to achieve this look, maybe using textures? (I was not particularly aiming at textures since my blocks should mainly look like glowing colorful plastic blocks but If I need to use some blank texture I'll go that way).
I like to have several blocks that look the same except for their color.
They should all be shiny and glossy, with maybe a little light being emitted by themselves.
On the normal OpenGL I understand I would do that by glColorMaterial and its options.
On the Iphone that doesn't seem to be an option (or is it?). So is there another way to achieve this look, maybe using textures? (I was not particularly aiming at textures since my blocks should mainly look like glowing colorful plastic blocks but If I need to use some blank texture I'll go that way).
The glColorMaterial API is not supported in ES1, but the default functionality of tracking the diffuse/ambient color is, via glEnable(GL_COLOR_MATERIAL). That's all you need here.
Of course I "glEnable(GL_COLOR_MATERIAL)" but only diffuse/ambient is sort of exactly what I don't want 
Those blocks should radiate some light via emissive and look kind'a shiny...

Those blocks should radiate some light via emissive and look kind'a shiny...
ColorMaterial only tracks a single attribute (i.e. GL_COLOR_ARRAY) to feed into the lighting equation. You said:
So the unique attribute is the diffuse color. That's the default state for ColorMaterial in ES1. You can set up the other parts of the lighting equation however you like.
Quote:I like to have several blocks that look the same except for their color.
They should all be shiny and glossy, with maybe a little light being emitted by themselves.
So the unique attribute is the diffuse color. That's the default state for ColorMaterial in ES1. You can set up the other parts of the lighting equation however you like.
I understood GL_Color_Material enables diffuse and ambient, and in the same value.
So can you tell me how to do that? Because thats the question I came here for
As I understand "glMaterialfv" is not an option since it would force me to change that Parameter each time I change the color and that would be far to many Api-Calls (I use more then 2000 vertices in an interleaved array).
Quote:So the unique attribute is the diffuse color. That's the default state for ColorMaterial in ES1. You can set up the other parts of the lighting equation however you like.
So can you tell me how to do that? Because thats the question I came here for

As I understand "glMaterialfv" is not an option since it would force me to change that Parameter each time I change the color and that would be far to many Api-Calls (I use more then 2000 vertices in an interleaved array).
Bersaelor Wrote:Of course I "glEnable(GL_COLOR_MATERIAL)" but only diffuse/ambient is sort of exactly what I don't want
Those blocks should radiate some light via emissive and look kind'a shiny...
You are not going to get any decent "light radiation" via emissive ... if you want something like glowing you will need to use some camera oriented quads with GL_ADD blending.
Bersaelor Wrote:As I understand "glMaterialfv" is not an option since it would force me to change that Parameter each time I change the color.
No, only each time you want to change values that are not being tracked by glColorMaterial (ambient/specular/shininess/emissive, etc.)
Again, from your original description, you said you only want the color to be unique for each cube. The default ColorMaterial state will do that. If you also want the ambient/specular/emissive colors, or the shininess exponent to be different for each cube, then yes, you'll have to call glMaterial a lot.
Perhaps you need to decide more precisely which state is constant, which state changes per object, and which state changes per vertex?
As warmi points out, the emissive term in GL's lighting equation is just going to make the overall colors brighter. It doesn't make objects into light sources that cast light onto each other. Unfortunately there's no glEnable(GL_RAYTRACING) in the API

Personally, for making "shiny glowy" things on the iPhone in ES1, I would avoid using vertex lighting. Yes, it's easy, but the quality depends on high tesselation so the end result you get is slower and lower quality than doing TexEnv based effects, like fake phong, gloss maps, environment mapping, or anisotropic lighting.
Well thank you for the links 
For some of them one still needs settings on specular and glColorMaterial, so I guess they are no options for the Iphone.
And I'm pretty sure which states are changing for each block. For each new block I change the color (and the color should be responsible for ambient/diffuse and specular lighting).
Of course, for the 18 Vertex's that make up a Block nothing changes colorwise.
Calling glMaterialv seems not to make sense in any serious 3D-scene.
I mean I can draw 100 blocks, 1800 vertices with more then 6000 triangles and I get super fps. Splitting my one call to DrawElements in 2 to enable me to call glMaterial in between would halve my fps.
Anyway it doesn't look bad right now, it's just I wished for a little more shinyness
As I said before I am not keen Vertex-Lightning, if I can do something similar with textures, I'll just do that.

For some of them one still needs settings on specular and glColorMaterial, so I guess they are no options for the Iphone.
And I'm pretty sure which states are changing for each block. For each new block I change the color (and the color should be responsible for ambient/diffuse and specular lighting).
Of course, for the 18 Vertex's that make up a Block nothing changes colorwise.
Calling glMaterialv seems not to make sense in any serious 3D-scene.
I mean I can draw 100 blocks, 1800 vertices with more then 6000 triangles and I get super fps. Splitting my one call to DrawElements in 2 to enable me to call glMaterial in between would halve my fps.
Anyway it doesn't look bad right now, it's just I wished for a little more shinyness

As I said before I am not keen Vertex-Lightning, if I can do something similar with textures, I'll just do that.
Bersaelor Wrote:Well thank you for the links
For some of them one still needs settings on specular and glColorMaterial, so I guess they are no options for the Iphone.
And I'm pretty sure which states are changing for each block. For each new block I change the color (and the color should be responsible for ambient/diffuse and specular lighting).
Of course, for the 18 Vertex's that make up a Block nothing changes colorwise.
Calling glMaterialv seems not to make sense in any serious 3D-scene.
I mean I can draw 100 blocks, 1800 vertices with more then 6000 triangles and I get super fps. Splitting my one call to DrawElements in 2 to enable me to call glMaterial in between would halve my fps.
Anyway it doesn't look bad right now, it's just I wished for a little more shinyness
As I said before I am not keen Vertex-Lightning, if I can do something similar with textures, I'll just do that.
It all depends what kind of effect you want to achieve ...
Here is an old test using only texture combiners and fake env mapping ( on the cpu) as well as camera oriented glowing particles ( one per each gem - using GL_ADD) to get a passable glowing-shiny-gem look to my models.
http://www.warmi.net/tmp/AnigmaTest.mov
Hey, I finally found an easy and acceptable solution.
I made a greyscale color gradient and applied it as a texture to my blocks. They shine like they're ***ing radioactive
But there is another problem now, that I'm stuck at. I have a nice Texture Atlas, which has colorful components for other parts then the mentioned blocks.
These other Maps get drawn when I put them at my other objects but somehow only the brightness changed.
Is there a way to tell OpenGL to add or multiply the Colors of the ColorArray with the ones of the Texture? It just seems the change the brightness according to the brightness of the part in the texture.
Heres what I do:
I convert my texAtlas.jpg to a PVRTC:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/texturetool -e PVRTC -o atlas.pvrtc texAtlas2.jpg
I import into my app:
glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, 512, 512, 0, [texData length], [texData bytes]);
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Well I tried "glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );" but it didn't change anything. It should be the default setting.
I made a greyscale color gradient and applied it as a texture to my blocks. They shine like they're ***ing radioactive

But there is another problem now, that I'm stuck at. I have a nice Texture Atlas, which has colorful components for other parts then the mentioned blocks.
These other Maps get drawn when I put them at my other objects but somehow only the brightness changed.
Is there a way to tell OpenGL to add or multiply the Colors of the ColorArray with the ones of the Texture? It just seems the change the brightness according to the brightness of the part in the texture.
Heres what I do:
I convert my texAtlas.jpg to a PVRTC:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/texturetool -e PVRTC -o atlas.pvrtc texAtlas2.jpg
I import into my app:
glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, 512, 512, 0, [texData length], [texData bytes]);
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Well I tried "glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );" but it didn't change anything. It should be the default setting.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| OpenGL Differences between iPhone Sim and Real iPhone | SparkyNZ | 5 | 5,554 |
Apr 13, 2011 11:40 AM Last Post: SparkyNZ |
|

