OpenGL conversion (glColorMaterial)

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Mobius
Posts: 14
Joined: Sun Dec 18, 2005 3:16 pm

OpenGL conversion (glColorMaterial)

Post by Mobius »

Hi,
I have this code (in OpenGL):

[...]
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);

glColorPointer(4, GL_FLOAT, 0, color_p);
glNormalPointer(GL_FLOAT, 0, normal_p);
glVertexPointer(3, GL_FLOAT, 0, vertex_p);
glDrawArrays(GL_TRIANGLES, 0, 3 * c);

glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
[...]


With GL_COLOR_MATERIAL/glColorMaterial enabled.
( http://www.opengl.org/documentation/spe ... erial.html )


In this way, I can change material's color for each vertex.

But... I don't understand how I can implement it with Irrlicht... =((
Baal Cadar
Posts: 377
Joined: Fri Oct 28, 2005 10:28 am
Contact:

Post by Baal Cadar »

This just changes the vertex colour and the code is more or less, what the Irrlicht OpenGL driver does too. You can define the colour on a per vertex base in Irrlicht easily. See API docs on SMesh, SMeshBuffer and S3DVertex.

If you got a specific question about them, ask.
Mobius
Posts: 14
Joined: Sun Dec 18, 2005 3:16 pm

Post by Mobius »

With glColorMaterial, I can change the material's color for each vertex and not only the vertex's color.

For example, if I enable lighting (and add some lights) in CustomSceneNode tutorial, the object appears "white and black":

Image

If I add glEnable(GL_COLOR_MATERIAL); in COpenGLDriver::drawIndexedTriangleList, the material's color changes at each vertex:

Image


But I don't know how I can implement it with Direct3D or Irrlicht methods =(


Thanx =)
Mobius
Posts: 14
Joined: Sun Dec 18, 2005 3:16 pm

Post by Mobius »

Well, I found how to implement it in D3D =)

I must add in CD3D9Driver::drawIndexedTriangleList these lines:

pID3DDevice->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1);
pID3DDevice->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1);
pID3DDevice->SetRenderState(D3DRS_SPECULARMATERIALSOURCE, D3DMCS_COLOR1);
pID3DDevice->SetRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_COLOR1);


But I still don't understand how to implement it without changing the Irrlicht code... =)
Post Reply