diff options
author | drumsetmonkey <abelleisle@roadrunner.com> | 2016-05-10 11:53:49 -0400 |
---|---|---|
committer | drumsetmonkey <abelleisle@roadrunner.com> | 2016-05-10 11:53:49 -0400 |
commit | 7487b029fa110388e90fd092bf3c3b9a4dcee08b (patch) | |
tree | 1fd080c162bdefc6e3ab1709380f0e4753da8aaa /src/common.cpp | |
parent | 50bfb70e9a1788e6f64800001919e3d8386eb81d (diff) |
Draw Rect
Diffstat (limited to 'src/common.cpp')
-rw-r--r-- | src/common.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/common.cpp b/src/common.cpp index 77be098..05a5f35 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -34,6 +34,50 @@ std::vector<std::string> StringTokenizer(const std::string& str, char delim) return tokens; } +static GLuint *Gshader; +static GLint *tex_uni; +static GLint *coord_attrib; +static GLint *tex_attrib; + +void useShader(GLuint *sh, GLint *tu, GLint *ca, GLint *ta) +{ + Gshader = sh; + tex_uni = tu; + coord_attrib = ca; + tex_attrib = ta; +} + +void drawRect(vec2 ll, vec2 ur) +{ + GLfloat verts[] = {ll.x, ll.y, 1.0, + ur.x, ll.y, 1.0, + ur.x, ur.y, 1.0, + + ur.x, ur.y, 1.0, + ll.x, ur.y, 1.0, + ll.x, ll.y, 1.0}; + + GLfloat tex[] = {0.0, 0.0, + 1.0, 0.0, + 1.0, 1.0, + + 1.0, 1.0, + 0.0, 1.0, + 0.0, 0.0}; + + glUniform1i(*tex_uni, 0); + + glEnableVertexAttribArray(*coord_attrib); + glEnableVertexAttribArray(*tex_attrib); + + glVertexAttribPointer(*coord_attrib, 3, GL_FLOAT, GL_FALSE, 0, verts); + glVertexAttribPointer(*tex_attrib, 2, GL_FLOAT, GL_FALSE, 0, tex); + glDrawArrays(GL_TRIANGLES, 0, 6); + + glDisableVertexAttribArray(*tex_attrib); + glDisableVertexAttribArray(*coord_attrib); +} + void DEBUG_prints(const char* file, int line, const char *s,...) { va_list args; |