void Polygon::Draw() { //Safety check the shader if(m_Shader == nullptr) { return; } //If the model matrix is dirty, reset it if(IsModelMatrixDirty() == true) { ResetModelMatrix(); } //Use the shader m_Shader->Use(); //Set the point size attribute int pointSizeIndex = m_Shader->GetAttribute("a_pointSize"); glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); glVertexAttrib1f(pointSizeIndex, m_PointSize); //Cache the graphics service Graphics* graphics = ServiceLocator::GetGraphics(); //Bind the vertex array object graphics->BindVertexArray(m_VertexArrayObject); //Set the model view projection matrix mat4 mvp = graphics->GetProjectionMatrix() * graphics->GetViewMatrix() * m_ModelMatrix; glUniformMatrix4fv(m_Shader->GetModelViewProjectionUniform(), 1, 0, &mvp[0][0]); //Validate the shader if(m_Shader->Validate() == false) { Error(false, "Can't draw Polygon, shader failed to validate"); return; } //Disable blending, if we did in fact have it enabled if(m_Color.Alpha() != 1.0f) { graphics->EnableBlending(); } //Render the polygon glDrawArrays(m_RenderMode, 0, (GLsizei)m_Vertices.size()); //Disable blending, if we did in fact have it enabled if(m_Color.Alpha() != 1.0f) { graphics->DisableBlending(); } //Unbind the vertex array ServiceLocator::GetGraphics()->BindVertexArray(0); //Draw the debug anchor point #if DRAW_POLYGON_ANCHOR_POINT if(GetType() != "Point" && GetType() != "Line") { Line lineA(m_AnchorLocation, vec2(m_AnchorLocation.x, m_AnchorLocation.y + DRAW_POLYGON_ANCHOR_POINT_SIZE)); lineA.SetLocalAngle(GetWorldAngle()); lineA.SetColor(Color::RedColor()); lineA.Draw(); Line lineB(m_AnchorLocation, vec2(m_AnchorLocation.x + DRAW_POLYGON_ANCHOR_POINT_SIZE, m_AnchorLocation.y)); lineB.SetLocalAngle(GetWorldAngle()); lineB.SetColor(Color::GreenColor()); lineB.Draw(); } #endif //Call the GameObject's Draw() method, this will ensure that any children will also get drawn GameObject::Draw(); }