diff options
Diffstat (limited to 'src/libjin/Graphics/Shapes.cpp')
-rw-r--r-- | src/libjin/Graphics/Shapes.cpp | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/src/libjin/Graphics/Shapes.cpp b/src/libjin/Graphics/Shapes.cpp index 13935d2..6cf0af1 100644 --- a/src/libjin/Graphics/Shapes.cpp +++ b/src/libjin/Graphics/Shapes.cpp @@ -14,14 +14,18 @@ namespace graphics void point(int x, int y) { float vers[] = { x + 0.5f , y + 0.5f }; + glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_FLOAT, 0, (GLvoid*)vers); glDrawArrays(GL_POINTS, 0, 1); + glDisableClientState(GL_VERTEX_ARRAY); } void points(int n, GLshort* p) { + glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_SHORT, 0, (GLvoid*)p); glDrawArrays(GL_POINTS, 0, n); + glDisableClientState(GL_VERTEX_ARRAY); } void line(int x1, int y1, int x2, int y2) @@ -31,8 +35,10 @@ namespace graphics x2, y2 }; - glVertexPointer(2, GL_FLOAT, 0, (GLvoid*)verts); + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(2, GL_FLOAT, 0, (const GLvoid*)verts); glDrawArrays(GL_LINES, 0, 2); + glDisableClientState(GL_VERTEX_ARRAY); } void circle(RenderMode mode, int x, int y, int r) @@ -72,22 +78,13 @@ namespace graphics polygon(mode, coords, 3); } + /* TODO: 内存占用很多 */ void polygon_line(float* p, int count) { - float* verts = new float[count * 4]; - for (int i = 0; i < count; ++i) - { - // each line has two point n,n+1 - verts[i * 4] = p[i * 2]; - verts[i * 4 + 1] = p[i * 2 + 1]; - verts[i * 4 + 2] = p[(i + 1) % count * 2]; - verts[i * 4 + 3] = p[(i + 1) % count * 2 + 1]; - } - - glVertexPointer(2, GL_FLOAT, 0, (GLvoid*)verts); - glDrawArrays(GL_LINES, 0, count * 2); - - delete[] verts; + glEnableClientState(GL_VERTEX_ARRAY); + glVertexPointer(2, GL_FLOAT, 0, (const GLvoid*)p); + glDrawArrays(GL_LINE_LOOP, 0, count); + glDisableClientState(GL_VERTEX_ARRAY); } void polygon(RenderMode mode, float* p, int count) @@ -98,8 +95,10 @@ namespace graphics } else if (mode == FILL) { + glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(2, GL_FLOAT, 0, (const GLvoid*)p); glDrawArrays(GL_POLYGON, 0, count); + glDisableClientState(GL_VERTEX_ARRAY); } } |