aboutsummaryrefslogtreecommitdiff
path: root/src/libjin/Graphics/Shapes.cpp
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2018-09-10 19:47:21 +0800
committerchai <chaifix@163.com>2018-09-10 19:47:21 +0800
commitd5cda5fddc078fa5fdb93805785fc707f050d8e7 (patch)
tree46224cbddb79959cbc26f045c757a9dde7ebb23b /src/libjin/Graphics/Shapes.cpp
parent435e17c1a81fa74a45465829bd42d36e7fa24406 (diff)
*update
Diffstat (limited to 'src/libjin/Graphics/Shapes.cpp')
-rw-r--r--src/libjin/Graphics/Shapes.cpp29
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);
}
}