[Plib-users] Trouble making simple colored triangle
Brought to you by:
sjbaker
From: Ben D. <be...@wa...> - 2000-10-13 03:46:51
|
I'm in the process of porting my whole 3d project over to PLIB/SSG, and mostly it's great, but i'm having a lot of trouble trying to build some simple geometry with SSG. As an example, consider a plain green triangle. You might think that the following code would work: sgVec4 color; sgVec3 pos; ssgSimpleState *state = new ssgSimpleState(); sgSetVec4(color, 0.0f, 1.0f, 0.0f, 1.0f); state->setMaterial(GL_DIFFUSE, color); ssgVertexArray *vertices = new ssgVertexArray(3); ssgNormalArray *normals = new ssgNormalArray(3); ssgVtxTable *pVtx = new ssgVtxTable(GL_TRIANGLES, vertices, normals, NULL, NULL); for (int i = 0; i < 3; i++) { double a = i * PI2f / 3.0f; sgSetVec3(pos, cos(a), sin(a), 0); vertices->add(pos); sgSetVec3(pos, 0, 0, 1); normals->add(pos); } pVtx->setState(state); But, this makes a triangle which is white, not green. Stepping into the SSG code, i discovered that in the function ssgVtxTable::draw_geometry(), there is the line: if ( num_colours == 0 ) glColor4f ( 1.0f, 1.0f, 1.0f, 1.0f ) ; This forces all primitives to white if they don't have a color per vertex! I worked around this problem by making and using a subclass of ssgVtxTable with a draw_geometry that doesn't make this assumption. The triangle was still white, so i found the next problem. In ssgSimpleState::apply(), it uses glMaterialfv to set the diffuse color. However, GL is in "Color Material" mode by default, so the glMaterialfv calls have no effect, making the shape default white. I tried to solve this problem by adding a statement to the triangle code: state->disable(GL_COLOR_MATERIAL); But, another problem (bug?) in ssgSimpleState::apply() prevents this from working. The Enable/Disable state code, required to disable "Color Material", is called *after* the glMaterialfv code, but OGL requires the glMaterialfv call to come after! So, i tried to work around this by changing the order in ssgSimpleState.cxx. That worked, so i finally got a green triangle. Surely there is some way to do simple colored geometry without all the hacking i had to do? Please help, i would really love to be able to use SSG. Thanks, Ben Discoe http://vterrain.org/ |