Advertisement

Cel-Shading Help !

Started by October 28, 2003 08:56 PM
1 comment, last by EonStrife 21Β years, 4Β months ago
Hi, I make a little project, which combine lesson 31(Model Loading) and lesson 37(Cel-Shading), which Cel-shade objects loaded in Milkshape format. In this, I use multitexturing, with the first texture as object''s texture, and the second texture is 1D shading texture(from lesson 37), and it works. The problem is, when I put the outline code, all objects appears black ! If I set the initial value of outline as false, the objects appear cel-shaded(of course without outline) just as when I haven''t put outline code. If I press ''1''(which is outline=!outline), the objects turn black, If I press ''1'' again(to disable outline) the objects still black. Can anyone help me fix this ? Thanks(I put the code below) : void Model::draw(GLuint shaderTexture[1], VECTOR lightAngle, bool outlineDraw, MATRIX TmpMatrix, PFNGLACTIVETEXTUREARBPROC glActiveTextureARB, PFNGLMULTITEXCOORD1FARBPROC glMultiTexCoord1fARB, PFNGLMULTITEXCOORD2FARBPROC glMultiTexCoord2fARB, PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTextureARB ) { GLboolean texEnabled = glIsEnabled( GL_TEXTURE_2D ); int i, j; // Looping Variables ( NEW ) float TmpShade; // Temporary Shader Value ( NEW ) float outlineWidth = 3.0f; // Width Of The Lines ( NEW ) float outlineColor[3] = { 0.0f, 0.0f, 0.0f }; VECTOR TmpVector, TmpNormal, light; // Temporary VECTOR Structures ( NEW ) // Draw by group for (i = 0; i < m_numMeshes; i++ ) { int materialIndex = m_pMeshes.m_materialIndex; if ( materialIndex >= 0 ) { glMaterialfv( GL_FRONT, GL_AMBIENT, m_pMaterials[materialIndex].m_ambient ); glMaterialfv( GL_FRONT, GL_DIFFUSE, m_pMaterials[materialIndex].m_diffuse ); glMaterialfv( GL_FRONT, GL_SPECULAR, m_pMaterials[materialIndex].m_specular ); glMaterialfv( GL_FRONT, GL_EMISSION, m_pMaterials[materialIndex].m_emissive ); glMaterialf( GL_FRONT, GL_SHININESS, m_pMaterials[materialIndex].m_shininess ); if ( m_pMaterials[materialIndex].m_texture > 0 ) { glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture( GL_TEXTURE_2D, m_pMaterials[materialIndex].m_texture ); glEnable( GL_TEXTURE_2D ); } else glDisable( GL_TEXTURE_2D ); } else { // Material properties? glDisable( GL_TEXTURE_2D ); } glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture (GL_TEXTURE_1D, shaderTexture[0]); glEnable (GL_TEXTURE_1D); // Enable 1D Texturing ( NEW ) glBegin( GL_TRIANGLES ); { for ( int j = 0; j < m_pMeshes.m_numTriangles; j++ ) { int triangleIndex = m_pMeshes.m_pTriangleIndices[j]; const Triangle* pTri = &m_pTriangles[triangleIndex]; for ( int k = 0; k < 3; k++ ) { int index = pTri->m_vertexIndices[k]; TmpNormal.X = pTri->m_vertexNormals[k][0]; TmpNormal.Y = pTri->m_vertexNormals[k][1]; TmpNormal.Z = pTri->m_vertexNormals[k][2]; RotateVector (TmpMatrix, TmpNormal, TmpVector); Normalize (TmpVector); TmpShade = DotProduct (TmpVector, lightAngle); if (TmpShade < 0.0f) TmpShade = 0.0f; glMultiTexCoord2fARB(GL_TEXTURE0_ARB, pTri->m_s[k], pTri->m_t[k]); glMultiTexCoord1fARB(GL_TEXTURE1_ARB, TmpShade); glVertex3fv( m_pVertices[index].m_location ); } } } glEnd(); glDisable (GL_TEXTURE_1D); //——————————————————– if (outlineDraw) // Check To See If We Want To Draw The Outline ( NEW ) { glEnable (GL_BLEND); // Enable Blending ( NEW ) glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // Set The Blend Mode ( NEW ) glPolygonMode (GL_BACK, GL_LINE); // Draw Backfacing Polygons As Wireframes ( NEW ) glLineWidth (outlineWidth); // Set The Line Width ( NEW ) glCullFace (GL_FRONT); // Don''t Draw Any Front-Facing Polygons ( NEW ) glDepthFunc (GL_LEQUAL); // Change The Depth Mode ( NEW ) glColor3fv (&outlineColor[0]); // Set The Outline Color ( NEW ) glBegin (GL_TRIANGLES); // Tell OpenGL What We Want To Draw for ( int j = 0; j < m_pMeshes.m_numTriangles; j++ )// Loop Through Each Polygon ( NEW ) { int triangleIndex = m_pMeshes.m_pTriangleIndices[j]; Triangle* pTri = &m_pTriangles[triangleIndex]; for (int k = 0; k < 3; k++) // Loop Through Each Vertex ( NEW ) { int index = pTri->m_vertexIndices[k]; glVertex3fv( m_pVertices[index].m_location );// Send The Vertex Position ( NEW ) } } glEnd (); // Tell OpenGL We''ve Finished glDepthFunc (GL_LESS); // Reset The Depth-Testing Mode ( NEW ) glCullFace (GL_BACK); // Reset The Face To Be Culled ( NEW ) glPolygonMode (GL_BACK, GL_FILL); // Reset Back-Facing Polygon Drawing Mode ( NEW ) glDisable (GL_BLEND); // Disable Blending ( NEW ) } } if ( texEnabled ) glEnable( GL_TEXTURE_2D ); else glDisable( GL_TEXTURE_2D ); } </i>
When you start rendering outlines, you call :
glColor3fv (&outlineColor[0]);
Because you color the outlines in the above call, you may restore the color just after rendering the outlines (after the glEnd() call for instance) :
glColor3f (1.f, 1.f, 1.f);

[edited by - vincoof on October 29, 2003 5:47:17 PM]
Advertisement
It works now !
Thanks you very much, vincoof

This topic is closed to new replies.

Advertisement