diff options
Diffstat (limited to 'src/libjin/Graphics/Shapes.cpp')
-rw-r--r-- | src/libjin/Graphics/Shapes.cpp | 198 |
1 files changed, 99 insertions, 99 deletions
diff --git a/src/libjin/Graphics/Shapes.cpp b/src/libjin/Graphics/Shapes.cpp index f5aedd4..5e87473 100644 --- a/src/libjin/Graphics/Shapes.cpp +++ b/src/libjin/Graphics/Shapes.cpp @@ -9,118 +9,118 @@ namespace jin { -namespace graphics -{ + namespace graphics + { - using namespace math; + using namespace math; - void point(int x, int y) - { - float verts[] = { x + 0.5f , y + 0.5f }; + void point(int x, int y) + { + float verts[] = { x + 0.5f , y + 0.5f }; - Shader* shader = Shader::getCurrentShader(); - shader->bindVertexPointer(2, GL_FLOAT, 0, verts); - gl.ModelMatrix.setIdentity(); - shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix); - shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix); + Shader* shader = Shader::getCurrentShader(); + shader->bindVertexPointer(2, GL_FLOAT, 0, verts); + gl.ModelMatrix.setIdentity(); + shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix); + shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix); - glDrawArrays(GL_POINTS, 0, 1); - } + glDrawArrays(GL_POINTS, 0, 1); + } - void points(int n, GLshort* p) - { - Shader* shader = Shader::getCurrentShader(); - shader->bindVertexPointer(2, GL_SHORT, 0, p); - gl.ModelMatrix.setIdentity(); - shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix); - shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix); + void points(int n, GLshort* p) + { + Shader* shader = Shader::getCurrentShader(); + shader->bindVertexPointer(2, GL_SHORT, 0, p); + gl.ModelMatrix.setIdentity(); + shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix); + shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix); - glDrawArrays(GL_POINTS, 0, n); - } - - void line(int x1, int y1, int x2, int y2) - { - float verts[] = { - x1, y1, - x2, y2 - }; + glDrawArrays(GL_POINTS, 0, n); + } + + void line(int x1, int y1, int x2, int y2) + { + float verts[] = { + x1, y1, + x2, y2 + }; - Shader* shader = Shader::getCurrentShader(); - shader->bindVertexPointer(2, GL_FLOAT, 0, verts); - gl.ModelMatrix.setIdentity(); - shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix); - shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix); + Shader* shader = Shader::getCurrentShader(); + shader->bindVertexPointer(2, GL_FLOAT, 0, verts); + gl.ModelMatrix.setIdentity(); + shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix); + shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix); - glDrawArrays(GL_LINES, 0, 2); - } - - void circle(RenderMode mode, int x, int y, int r) - { - r = r < 0 ? 0 : r; - - int points = 40; - float two_pi = static_cast<float>(PI * 2); - if (points <= 0) points = 1; - float angle_shift = (two_pi / points); - float phi = .0f; - - float *coords = new float[2 * (points + 1)]; - for (int i = 0; i < points; ++i, phi += angle_shift) - { - coords[2 * i] = x + r * cos(phi); - coords[2 * i + 1] = y + r * sin(phi); - } - - coords[2 * points] = coords[0]; - coords[2 * points + 1] = coords[1]; - - polygon(mode, coords, points); - - delete[] coords; - } - - void rect(RenderMode mode, int x, int y, int w, int h) - { - float coords[] = { x, y, x + w, y, x + w, y + h, x, y + h }; - polygon(mode, coords, 4); - } - - void triangle(RenderMode mode, int x1, int y1, int x2, int y2, int x3, int y3) - { - float coords[] = { x1, y1, x2, y2, x3, y3 }; - polygon(mode, coords, 3); - } - - void polygon_line(float* p, int count) - { - Shader* shader = Shader::getCurrentShader(); - gl.ModelMatrix.setIdentity(); - shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix); - shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix); - shader->bindVertexPointer(2, GL_FLOAT, 0, p); - - glDrawArrays(GL_LINE_LOOP, 0, count); - } - - void polygon(RenderMode mode, float* p, int count) - { - if (mode == LINE) - { - polygon_line(p, count); - } - else if (mode == FILL) - { + glDrawArrays(GL_LINES, 0, 2); + } + + void circle(RenderMode mode, int x, int y, int r) + { + r = r < 0 ? 0 : r; + + int points = 40; + float two_pi = static_cast<float>(PI * 2); + if (points <= 0) points = 1; + float angle_shift = (two_pi / points); + float phi = .0f; + + float *coords = new float[2 * (points + 1)]; + for (int i = 0; i < points; ++i, phi += angle_shift) + { + coords[2 * i] = x + r * cos(phi); + coords[2 * i + 1] = y + r * sin(phi); + } + + coords[2 * points] = coords[0]; + coords[2 * points + 1] = coords[1]; + + polygon(mode, coords, points); + + delete[] coords; + } + + void rect(RenderMode mode, int x, int y, int w, int h) + { + float coords[] = { x, y, x + w, y, x + w, y + h, x, y + h }; + polygon(mode, coords, 4); + } + + void triangle(RenderMode mode, int x1, int y1, int x2, int y2, int x3, int y3) + { + float coords[] = { x1, y1, x2, y2, x3, y3 }; + polygon(mode, coords, 3); + } + + void polygon_line(float* p, int count) + { Shader* shader = Shader::getCurrentShader(); - gl.ModelMatrix.setIdentity(); + gl.ModelMatrix.setIdentity(); shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix); shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix); shader->bindVertexPointer(2, GL_FLOAT, 0, p); - glDrawArrays(GL_POLYGON, 0, count); - } - } - -} // graphics + glDrawArrays(GL_LINE_LOOP, 0, count); + } + + void polygon(RenderMode mode, float* p, int count) + { + if (mode == LINE) + { + polygon_line(p, count); + } + else if (mode == FILL) + { + Shader* shader = Shader::getCurrentShader(); + gl.ModelMatrix.setIdentity(); + shader->sendMatrix4(SHADER_MODEL_MATRIX, &gl.ModelMatrix); + shader->sendMatrix4(SHADER_PROJECTION_MATRIX, &gl.ProjectionMatrix); + shader->bindVertexPointer(2, GL_FLOAT, 0, p); + + glDrawArrays(GL_POLYGON, 0, count); + } + } + + } // graphics } // jin #endif // LIBJIN_MODULES_RENDER
\ No newline at end of file |