nuclear@0: #include <assert.h>
nuclear@0: #include "gfxutil.h"
nuclear@0: #include "mesh.h"
nuclear@0: #include "meshgen.h"
nuclear@0: #include "texture.h"
nuclear@0: #include "shader.h"
nuclear@0: #include "sdrman.h"
nuclear@0: #include "opengl.h"
nuclear@0: #include "logger.h"
nuclear@0: 
nuclear@0: void draw_rect(const Vector3 &v1, const Vector3 &v2, Texture2D *tex, ShaderProg *sdr)
nuclear@0: {
nuclear@0: 	static ShaderProg *defsdr;
nuclear@0: 
nuclear@0: 	if(!defsdr) {
nuclear@0: 		if(!(defsdr = get_sdrprog("defpost.v.glsl", "defpost.p.glsl"))) {
nuclear@0: 			static bool didlog;
nuclear@0: 			if(!didlog) {
nuclear@0: 				error_log("draw_rect: failed to load default shader\n");
nuclear@0: 				didlog = true;
nuclear@0: 			}
nuclear@0: 			if(!sdr) {
nuclear@0: 				return;
nuclear@0: 			}
nuclear@0: 		}
nuclear@0: 	}
nuclear@0: 
nuclear@0: 
nuclear@0: 	if(tex) {
nuclear@0: 		set_texture(tex);
nuclear@0: 	}
nuclear@0: 	if(sdr) {
nuclear@0: 		sdr->bind();
nuclear@0: 	} else {
nuclear@0: 		defsdr->bind();
nuclear@0: 
nuclear@0: 		assert(defsdr->get_attrib_location("attr_vertex") == MESH_ATTR_VERTEX);
nuclear@0: 		assert(defsdr->get_attrib_location("attr_texcoord") == MESH_ATTR_TEXCOORD);
nuclear@0: 	}
nuclear@0: 
nuclear@0: 
nuclear@0: 	float varr[] = {
nuclear@0: 		v1.x, v1.y, v1.z, v2.x, v1.y, v2.z,
nuclear@0: 		v2.x, v2.y, v2.z, v1.x, v2.y, v1.z
nuclear@0: 	};
nuclear@0: 	static const float tarr[] = { 0, 0, 1, 0, 1, 1, 0, 1 };
nuclear@0: 	static const unsigned int idxarr[] = {0, 1, 2, 0, 2, 3};
nuclear@0: 
nuclear@0: 	// disable VBOs if they are enabled
nuclear@0: 	glBindBuffer(GL_ARRAY_BUFFER, 0);
nuclear@0: 	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
nuclear@0: 
nuclear@0: 	glEnableVertexAttribArray(MESH_ATTR_VERTEX);
nuclear@0: 	glVertexAttribPointer(MESH_ATTR_VERTEX, 3, GL_FLOAT, GL_FALSE, 0, varr);
nuclear@0: 	glEnableVertexAttribArray(MESH_ATTR_TEXCOORD);
nuclear@0: 	glVertexAttribPointer(MESH_ATTR_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, tarr);
nuclear@0: 
nuclear@0: 	glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, idxarr);
nuclear@0: 
nuclear@0: 	glDisableVertexAttribArray(MESH_ATTR_VERTEX);
nuclear@0: 	glDisableVertexAttribArray(MESH_ATTR_TEXCOORD);
nuclear@0: 
nuclear@0: 	set_texture(0);
nuclear@0: }