Skip to content

Instantly share code, notes, and snippets.

@grrussel
Created December 30, 2016 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grrussel/12d59d987c4907a4f3ce42d75a97d37f to your computer and use it in GitHub Desktop.
Save grrussel/12d59d987c4907a4f3ce42d75a97d37f to your computer and use it in GitHub Desktop.
Simple DrawTriangles for Simple2D
From bc7c14df1c80e30307657e061c91b497309ddc17 Mon Sep 17 00:00:00 2001
From: George Russell <grrussel@gmail.com>
Date: Fri, 30 Dec 2016 12:45:59 +0100
Subject: [PATCH] Draw Triangles
---
include/simple2d.h | 9 +++++++++
src/gl.c | 16 ++++++++++++++++
src/gl3.c | 14 ++++++++++++++
src/shapes.c | 8 ++++++++
4 files changed, 47 insertions(+)
diff --git a/include/simple2d.h b/include/simple2d.h
index 302e667..a8c9dab 100644
--- a/include/simple2d.h
+++ b/include/simple2d.h
@@ -263,6 +263,13 @@ void S2D_DrawTriangle(
);
/*
+ * Draw many triangles
+ */
+void S2D_DrawTriangles(
+ GLfloat * arrayx, int64_t len
+);
+
+/*
* Draw a quad, using two triangles
*/
void S2D_DrawQuad(
@@ -450,6 +457,7 @@ void S2D_GL_DrawTriangle(
GLfloat c2r, GLfloat c2g, GLfloat c2b, GLfloat c2a,
GLfloat x3, GLfloat y3,
GLfloat c3r, GLfloat c3g, GLfloat c3b, GLfloat c3a);
+void S2D_GL_DrawTriangles(GLfloat *arr, int64_t len);
void S2D_GL_DrawImage(S2D_Image *img);
void S2D_GL_DrawSprite(S2D_Sprite *spr);
void S2D_GL_DrawText(S2D_Text *txt);
@@ -483,6 +491,7 @@ void S2D_GL_Clear(S2D_Color clr);
GLfloat c2r, GLfloat c2g, GLfloat c2b, GLfloat c2a,
GLfloat x3, GLfloat y3,
GLfloat c3r, GLfloat c3g, GLfloat c3b, GLfloat c3a);
+ void S2D_GL3_DrawTriangles(GLfloat *arr, int64_t len);
void S2D_GL3_DrawTriangle(
GLfloat x1, GLfloat y1,
GLfloat c1r, GLfloat c1g, GLfloat c1b, GLfloat c1a,
diff --git a/src/gl.c b/src/gl.c
index 0f0b0b7..c9e1eb1 100644
--- a/src/gl.c
+++ b/src/gl.c
@@ -359,6 +359,22 @@ void S2D_GL_DrawTriangle(GLfloat x1, GLfloat y1,
#endif
}
+/*
+ * Draw a triangle
+ */
+void S2D_GL_DrawTriangles(GLfloat * arr, int64_t len) {
+
+ #if GLES
+ // TODO
+ #else
+ if (S2D_GL2) {
+ // TODO
+ } else {
+ //printf("%p %lld\n",arr,len);
+ S2D_GL3_DrawTriangles(arr,len);
+ }
+ #endif
+}
/*
* Draw an image
diff --git a/src/gl3.c b/src/gl3.c
index ca2fdec..92ffb7b 100644
--- a/src/gl3.c
+++ b/src/gl3.c
@@ -188,6 +188,20 @@ void S2D_GL3_DrawTriangle(GLfloat x1, GLfloat y1,
glDrawArrays(GL_TRIANGLES, 0, 3);
}
+/*
+ * Draw triangles
+ */
+void S2D_GL3_DrawTriangles(GLfloat * array, int64_t len) {
+
+ //printf("S2D_GL3_DrawTriangles %lld ",len);
+ //for (int i = 0; i < 8; ++i)
+ // printf("%f ",array[i]);
+ //printf("\n");
+
+ glUseProgram(shaderProgram);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * len, array, GL_STATIC_DRAW);
+ glDrawArrays(GL_TRIANGLES, 0, len / 8);
+}
/*
* Draw a texture
diff --git a/src/shapes.c b/src/shapes.c
index a8121cd..87acf85 100644
--- a/src/shapes.c
+++ b/src/shapes.c
@@ -20,6 +20,14 @@ void S2D_DrawTriangle(GLfloat x1, GLfloat y1,
/*
+ * Draw triangles
+ */
+void S2D_DrawTriangles(GLfloat* array, int64_t len) {
+
+ S2D_GL_DrawTriangles(array,len);
+}
+
+/*
* Draw a quad, using two triangles
*/
void S2D_DrawQuad(GLfloat x1, GLfloat y1,
--
2.2.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment