goat3dgfx

view src/gfxutil.cc @ 9:25b911c7c35c

fixed some line endings fixed the cubemap2.jpg file in examples/cubemap/data which was resized improperly causing seams...
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 18 Nov 2013 04:10:19 +0200
parents
children 7d6b667821cf
line source
1 #include <assert.h>
2 #include "gfxutil.h"
3 #include "mesh.h"
4 #include "meshgen.h"
5 #include "texture.h"
6 #include "shader.h"
7 #include "sdrman.h"
8 #include "opengl.h"
9 #include "logger.h"
11 void draw_rect(const Vector3 &v1, const Vector3 &v2, Texture2D *tex, ShaderProg *sdr)
12 {
13 static ShaderProg *defsdr;
15 if(!defsdr) {
16 if(!(defsdr = get_sdrprog("defpost.v.glsl", "defpost.p.glsl"))) {
17 static bool didlog;
18 if(!didlog) {
19 error_log("draw_rect: failed to load default shader\n");
20 didlog = true;
21 }
22 if(!sdr) {
23 return;
24 }
25 }
26 }
29 if(tex) {
30 set_texture(tex);
31 }
32 if(sdr) {
33 sdr->bind();
34 } else {
35 defsdr->bind();
37 assert(defsdr->get_attrib_location("attr_vertex") == MESH_ATTR_VERTEX);
38 assert(defsdr->get_attrib_location("attr_texcoord") == MESH_ATTR_TEXCOORD);
39 }
42 float varr[] = {
43 v1.x, v1.y, v1.z, v2.x, v1.y, v2.z,
44 v2.x, v2.y, v2.z, v1.x, v2.y, v1.z
45 };
46 static const float tarr[] = { 0, 0, 1, 0, 1, 1, 0, 1 };
47 static const unsigned int idxarr[] = {0, 1, 2, 0, 2, 3};
49 // disable VBOs if they are enabled
50 glBindBuffer(GL_ARRAY_BUFFER, 0);
51 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
53 glEnableVertexAttribArray(MESH_ATTR_VERTEX);
54 glVertexAttribPointer(MESH_ATTR_VERTEX, 3, GL_FLOAT, GL_FALSE, 0, varr);
55 glEnableVertexAttribArray(MESH_ATTR_TEXCOORD);
56 glVertexAttribPointer(MESH_ATTR_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, tarr);
58 glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, idxarr);
60 glDisableVertexAttribArray(MESH_ATTR_VERTEX);
61 glDisableVertexAttribArray(MESH_ATTR_TEXCOORD);
63 set_texture(0);
64 }