replace plane instance calls with calls from derived class instances

This commit is contained in:
frank 2021-10-29 22:53:48 -04:00
parent c461475ea6
commit aed8457874
1 changed files with 13 additions and 13 deletions

View File

@ -175,8 +175,8 @@ void Pudding::load_gl_context()
flat_program = glCreateProgram(); flat_program = glCreateProgram();
glAttachShader(flat_program, vertex_shader); glAttachShader(flat_program, vertex_shader);
glAttachShader(flat_program, fragment_shader); glAttachShader(flat_program, fragment_shader);
plane.attributes("position")->bind(0, flat_program, "in_position"); Plane::position->bind(0, flat_program, "in_position");
plane.attributes("uv")->bind(1, flat_program, "vertex_uv"); Plane::uv->bind(1, flat_program, "vertex_uv");
/* load, configure and link the 3D world program */ /* load, configure and link the 3D world program */
vertex_shader = load_shader("src/mvp.vert", GL_VERTEX_SHADER); vertex_shader = load_shader("src/mvp.vert", GL_VERTEX_SHADER);
fragment_shader = load_shader("src/mvp.frag", GL_FRAGMENT_SHADER); fragment_shader = load_shader("src/mvp.frag", GL_FRAGMENT_SHADER);
@ -188,9 +188,9 @@ void Pudding::load_gl_context()
pudding_model.attributes("color")->bind(4, mvp_program, "vertex_color"); pudding_model.attributes("color")->bind(4, mvp_program, "vertex_color");
sb::Log::gl_errors("after loading shaders"); sb::Log::gl_errors("after loading shaders");
/* Fill VBO with attribute data */ /* Fill VBO with attribute data */
vbo.allocate(plane.size() + pudding_model.size(), GL_STATIC_DRAW); vbo.allocate(background.size() + pudding_model.size(), GL_STATIC_DRAW);
vbo.add(*plane.attributes("position")); vbo.add(*Plane::position);
vbo.add(*plane.attributes("uv")); vbo.add(*Plane::uv);
vbo.add(*pudding_model.attributes("uv")); vbo.add(*pudding_model.attributes("uv"));
vbo.add(*pudding_model.attributes("position")); vbo.add(*pudding_model.attributes("position"));
vbo.add(*pudding_model.attributes("color")); vbo.add(*pudding_model.attributes("color"));
@ -737,9 +737,9 @@ void Pudding::update()
/* switch to flat shader for background */ /* switch to flat shader for background */
glUseProgram(flat_program); glUseProgram(flat_program);
glUniform1f(uniform["flat"]["time"], time_seconds); glUniform1f(uniform["flat"]["time"], time_seconds);
/* disable pudding attributes and enable rectangle attributes */ /* disable pudding attributes and enable background attributes */
pudding_model.disable(); pudding_model.disable();
plane.enable(); background.enable();
glUniform1i(uniform["flat"]["texture"], 0); glUniform1i(uniform["flat"]["texture"], 0);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
background.current().bind(); background.current().bind();
@ -747,7 +747,7 @@ void Pudding::update()
glUniform3f(uniform["flat"]["blend"], 0.0f, 0.0f, 1.0f); glUniform3f(uniform["flat"]["blend"], 0.0f, 0.0f, 1.0f);
glUniform1i(uniform["flat"]["scroll"], true); glUniform1i(uniform["flat"]["scroll"], true);
/* draws rectangle vertices and rectangle texture using UV coords */ /* draws rectangle vertices and rectangle texture using UV coords */
glDrawArrays(GL_TRIANGLES, 0, plane.attributes("position")->count()); glDrawArrays(GL_TRIANGLES, 0, background.attributes("position")->count());
glUniform1i(uniform["flat"]["scroll"], false); glUniform1i(uniform["flat"]["scroll"], false);
/* draw pudding model using MVP shader */ /* draw pudding model using MVP shader */
glUseProgram(mvp_program); glUseProgram(mvp_program);
@ -759,8 +759,8 @@ void Pudding::update()
mvp = projection * VIEW_MATRIX * model; mvp = projection * VIEW_MATRIX * model;
/* pass the mvp matrix to the shader */ /* pass the mvp matrix to the shader */
glUniformMatrix4fv(uniform["mvp"]["mvp"], 1, GL_FALSE, &mvp[0][0]); glUniformMatrix4fv(uniform["mvp"]["mvp"], 1, GL_FALSE, &mvp[0][0]);
/* disable rectangle attributes and enable pudding attributes */ /* disable bg attributes and enable pudding attributes */
plane.disable(); background.disable();
pudding_model.attributes("position")->enable(); pudding_model.attributes("position")->enable();
if (items.size() == 0) if (items.size() == 0)
{ {
@ -795,9 +795,7 @@ void Pudding::update()
{ {
/* switch to flat shader for item and camera */ /* switch to flat shader for item and camera */
glUseProgram(flat_program); glUseProgram(flat_program);
/* disable pudding attributes and enable rectangle attributes */
pudding_model.disable(); pudding_model.disable();
plane.enable();
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
/* just need to set these once since we're drawing one texture per viewport */ /* just need to set these once since we're drawing one texture per viewport */
glUniform1i(uniform["flat"]["texture"], 0); glUniform1i(uniform["flat"]["texture"], 0);
@ -817,6 +815,7 @@ void Pudding::update()
} }
glViewport(viewport_box.left(), viewport_box.bottom(), viewport_box.width(), viewport_box.height()); glViewport(viewport_box.left(), viewport_box.bottom(), viewport_box.width(), viewport_box.height());
current_item().get_active_image_texture().bind(); current_item().get_active_image_texture().bind();
plane.enable();
/* draws rectangle vertices and rectangle texture using UV coords */ /* draws rectangle vertices and rectangle texture using UV coords */
glDrawArrays(GL_TRIANGLES, 0, plane.attributes("position")->count()); glDrawArrays(GL_TRIANGLES, 0, plane.attributes("position")->count());
} }
@ -827,8 +826,9 @@ void Pudding::update()
glViewport(viewport_box.left(), viewport_box.bottom(), viewport_box.width(), viewport_box.height()); glViewport(viewport_box.left(), viewport_box.bottom(), viewport_box.width(), viewport_box.height());
/* bind texture for drawing */ /* bind texture for drawing */
camera_view.current().bind(); camera_view.current().bind();
camera_view.enable();
/* draws rectangle vertices and rectangle texture using UV coords */ /* draws rectangle vertices and rectangle texture using UV coords */
glDrawArrays(GL_TRIANGLES, 0, plane.attributes("position")->count()); glDrawArrays(GL_TRIANGLES, 0, camera_view.attributes("position")->count());
} }
} }
SDL_GL_SwapWindow(get_window()); SDL_GL_SwapWindow(get_window());