int IGLUOBJReader::Draw( IGLUShaderProgram::Ptr &shader ) { // If the shader in question is not already enabled, enable it! bool wasShaderBound = shader->IsEnabled(); if (!wasShaderBound) shader->Enable(); // We may already have the vertex array setup to work with this shader. // Check that. If not, re-set up the vertex array. //if (m_shaderID != shader->GetProgramID()) if (m_shaderID == 0) { m_shaderID = shader->GetProgramID(); int err = SetupVertexArray( shader ); if (err != IGLU_NO_ERROR) return err; } m_vertArr->DrawElements( GL_TRIANGLES, 3* GetTriangleCount() ); // If we started with the shader disabled, disable it again now. if (!wasShaderBound) shader->Disable(); return IGLU_NO_ERROR; }
// Draw void display ( void ) { int j=0; glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glLineWidth( GLfloat(lineWidth) ); if (!useErrors) { // Bind and setup the shader draw->Enable(); draw["xRange"] = vec2( 330.0f, 843.0f ); draw["yRange"] = vec2( -0.13f, 2.05f ); draw["useXYZ"] = vec3( displayX ? 1.0f : 0.0f, displayY ? 1.0f : 0.0f, displayZ ? 1.0f : 0.0f ); // For each curve, check if it's selected to be display, if so, draw it for (uint i=0; i<drawableCurves.Size(); i++) { // Check if this curve was selected to be drawn if ( curveSelection[i]->GetValue() ) { draw["xColor"] = colorArr[j++]; draw["yColor"] = colorArr[j++]; draw["zColor"] = colorArr[j++]; drawableCurves[i]->DrawArrays( GL_LINE_STRIP, 0, 471 ); } } draw->Disable(); // After drawing the curve, draw the axes drawAxes->Enable(); axes->DrawArrays( GL_LINES, 0, 38 ); drawAxes->Disable(); } else { // Bind and setup the shader draw->Enable(); draw["xRange"] = vec2( 330.0f, 843.0f ); draw["yRange"] = vec2( -0.25f, 0.25f ); draw["useXYZ"] = vec3( displayX ? 1.0f : 0.0f, displayY ? 1.0f : 0.0f, displayZ ? 1.0f : 0.0f ); // For each curve, check if it's selected to be display, if so, draw it for (uint i=0; i<errorCurves.Size(); i++) { // Check if this curve was selected to be drawn if ( curveSelection[i]->GetValue() ) { draw["xColor"] = colorArr[j++]; draw["yColor"] = colorArr[j++]; draw["zColor"] = colorArr[j++]; errorCurves[i]->DrawArrays( GL_LINE_STRIP, 0, 471 ); } } draw->Disable(); } // Draw the labels for (int i=0; i<10; i++) IGLUDraw::DrawColorText( IGLU_FONT_VARIABLE, int(textOffsetFactor.X()*labels[i].x), int(textOffsetFactor.Y()*labels[i].y), color::Gray80, labels[i].name, textOffsetFactor.X() ); }