rev |
line source |
nuclear@0
|
1 #include <assert.h>
|
nuclear@0
|
2 #include "gfxutil.h"
|
nuclear@0
|
3 #include "mesh.h"
|
nuclear@0
|
4 #include "meshgen.h"
|
nuclear@0
|
5 #include "texture.h"
|
nuclear@0
|
6 #include "shader.h"
|
nuclear@0
|
7 #include "sdrman.h"
|
nuclear@0
|
8 #include "opengl.h"
|
nuclear@0
|
9 #include "logger.h"
|
nuclear@0
|
10
|
nuclear@0
|
11 void draw_rect(const Vector3 &v1, const Vector3 &v2, Texture2D *tex, ShaderProg *sdr)
|
nuclear@0
|
12 {
|
nuclear@0
|
13 static ShaderProg *defsdr;
|
nuclear@0
|
14
|
nuclear@0
|
15 if(!defsdr) {
|
nuclear@0
|
16 if(!(defsdr = get_sdrprog("defpost.v.glsl", "defpost.p.glsl"))) {
|
nuclear@0
|
17 static bool didlog;
|
nuclear@0
|
18 if(!didlog) {
|
nuclear@0
|
19 error_log("draw_rect: failed to load default shader\n");
|
nuclear@0
|
20 didlog = true;
|
nuclear@0
|
21 }
|
nuclear@0
|
22 if(!sdr) {
|
nuclear@0
|
23 return;
|
nuclear@0
|
24 }
|
nuclear@0
|
25 }
|
nuclear@0
|
26 }
|
nuclear@0
|
27
|
nuclear@0
|
28
|
nuclear@0
|
29 if(tex) {
|
nuclear@0
|
30 set_texture(tex);
|
nuclear@0
|
31 }
|
nuclear@0
|
32 if(sdr) {
|
nuclear@0
|
33 sdr->bind();
|
nuclear@0
|
34 } else {
|
nuclear@0
|
35 defsdr->bind();
|
nuclear@0
|
36
|
nuclear@0
|
37 assert(defsdr->get_attrib_location("attr_vertex") == MESH_ATTR_VERTEX);
|
nuclear@0
|
38 assert(defsdr->get_attrib_location("attr_texcoord") == MESH_ATTR_TEXCOORD);
|
nuclear@0
|
39 }
|
nuclear@0
|
40
|
nuclear@0
|
41
|
nuclear@0
|
42 float varr[] = {
|
nuclear@0
|
43 v1.x, v1.y, v1.z, v2.x, v1.y, v2.z,
|
nuclear@0
|
44 v2.x, v2.y, v2.z, v1.x, v2.y, v1.z
|
nuclear@0
|
45 };
|
nuclear@0
|
46 static const float tarr[] = { 0, 0, 1, 0, 1, 1, 0, 1 };
|
nuclear@0
|
47 static const unsigned int idxarr[] = {0, 1, 2, 0, 2, 3};
|
nuclear@0
|
48
|
nuclear@0
|
49 // disable VBOs if they are enabled
|
nuclear@0
|
50 glBindBuffer(GL_ARRAY_BUFFER, 0);
|
nuclear@0
|
51 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
|
nuclear@0
|
52
|
nuclear@0
|
53 glEnableVertexAttribArray(MESH_ATTR_VERTEX);
|
nuclear@0
|
54 glVertexAttribPointer(MESH_ATTR_VERTEX, 3, GL_FLOAT, GL_FALSE, 0, varr);
|
nuclear@0
|
55 glEnableVertexAttribArray(MESH_ATTR_TEXCOORD);
|
nuclear@0
|
56 glVertexAttribPointer(MESH_ATTR_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, tarr);
|
nuclear@0
|
57
|
nuclear@0
|
58 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, idxarr);
|
nuclear@0
|
59
|
nuclear@0
|
60 glDisableVertexAttribArray(MESH_ATTR_VERTEX);
|
nuclear@0
|
61 glDisableVertexAttribArray(MESH_ATTR_TEXCOORD);
|
nuclear@0
|
62
|
nuclear@0
|
63 set_texture(0);
|
nuclear@0
|
64 }
|