MCPcopy Create free account
hub / github.com/WolfireGames/overgrowth / drawTexture

Method drawTexture

Source/Graphics/textures.cpp:1246–1326  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1244}
1245
1246void Textures::drawTexture(TextureRef id, vec3 where, float size, float rotation) {
1247 CHECK_GL_ERROR();
1248
1249 // no coloring
1250 Graphics* graphics = Graphics::Instance();
1251 Shaders* shaders = Shaders::Instance();
1252
1253 int shader_id = shaders->returnProgram("simple_2d #TEXTURE #FLIPPED");
1254 shaders->createProgram(shader_id);
1255 int shader_attrib_vert_coord = shaders->returnShaderAttrib("vert_coord", shader_id);
1256 int shader_attrib_tex_coord = shaders->returnShaderAttrib("tex_coord", shader_id);
1257 int uniform_mvp_mat = shaders->returnShaderVariable("mvp_mat", shader_id);
1258 int uniform_color = shaders->returnShaderVariable("color", shader_id);
1259 shaders->setProgram(shader_id);
1260 CHECK_GL_ERROR();
1261
1262 GLState gl_state;
1263 gl_state.blend = true;
1264 gl_state.cull_face = false;
1265 gl_state.depth_write = false;
1266 gl_state.depth_test = false;
1267 graphics->setGLState(gl_state);
1268 CHECK_GL_ERROR();
1269
1270 glm::mat4 proj_mat;
1271 proj_mat = glm::ortho(0.0f, (float)graphics->window_dims[0], 0.0f, (float)graphics->window_dims[1]);
1272 glm::mat4 modelview_mat(1.0f);
1273 modelview_mat = glm::translate(modelview_mat, glm::vec3(where[0] - size * 0.5f, where[1] - size * 0.5f, 0));
1274 modelview_mat = glm::scale(modelview_mat, glm::vec3(size, size, 1.0f));
1275 modelview_mat = glm::translate(modelview_mat, glm::vec3(0.5f, 0.5f, 0.5f));
1276 modelview_mat = glm::rotate(modelview_mat, rotation, glm::vec3(0.0f, 0.0f, 1.0f));
1277 modelview_mat = glm::translate(modelview_mat, glm::vec3(-0.5f, -0.5f, -0.5f));
1278 glm::mat4 mvp_mat = proj_mat * modelview_mat;
1279 CHECK_GL_ERROR();
1280
1281 graphics->EnableVertexAttribArray(shader_attrib_vert_coord);
1282 CHECK_GL_ERROR();
1283 graphics->EnableVertexAttribArray(shader_attrib_tex_coord);
1284 CHECK_GL_ERROR();
1285 static const GLfloat verts[] = {
1286 0, 0, 0, 0,
1287 1, 0, 1, 0,
1288 1, 1, 1, 1,
1289 0, 1, 0, 1};
1290 static const GLuint indices[] = {
1291 0, 1, 2,
1292 0, 2, 3};
1293 static VBOContainer vert_vbo;
1294 static VBOContainer index_vbo;
1295 static bool vbo_filled = false;
1296 if (!vbo_filled) {
1297 vert_vbo.Fill(kVBOFloat | kVBOStatic, sizeof(verts), (void*)verts);
1298 index_vbo.Fill(kVBOElement | kVBOStatic, sizeof(indices), (void*)indices);
1299 vbo_filled = true;
1300 }
1301 vert_vbo.Bind();
1302 index_vbo.Bind();
1303

Callers 2

DrawMethod · 0.80
DrawLoadScreenMethod · 0.80

Calls 15

returnProgramMethod · 0.80
returnShaderAttribMethod · 0.80
returnShaderVariableMethod · 0.80
setProgramMethod · 0.80
setGLStateMethod · 0.80
BindElementVBOMethod · 0.80
BindArrayVBOMethod · 0.80
vec3Class · 0.50
scaleFunction · 0.50
rotateFunction · 0.50

Tested by

no test coverage detected