From 81c9015bd70a2f6a08e307d833b44f76a558be88 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sat, 13 Oct 2012 22:03:59 -0400 Subject: [PATCH] add shot reload overlay bar --- assets/fs/shaders/overlay_reload.f.glsl | 7 ++++++ src/client/Client-gl.cc | 32 +++++++++++++++++++++++++ src/client/Client.h | 1 + 3 files changed, 40 insertions(+) create mode 100644 assets/fs/shaders/overlay_reload.f.glsl diff --git a/assets/fs/shaders/overlay_reload.f.glsl b/assets/fs/shaders/overlay_reload.f.glsl new file mode 100644 index 0000000..9a07b65 --- /dev/null +++ b/assets/fs/shaders/overlay_reload.f.glsl @@ -0,0 +1,7 @@ + +varying vec3 pos_i; + +void main(void) +{ + gl_FragColor = mix(vec4(.7, .7, 1, 1), vec4(0, 0, 1, 1), (pos_i.x + 1) / 2); +} diff --git a/src/client/Client-gl.cc b/src/client/Client-gl.cc index a27ab54..c3c56c4 100644 --- a/src/client/Client-gl.cc +++ b/src/client/Client-gl.cc @@ -114,6 +114,11 @@ bool Client::initgl() "pos", 0, "normal", 1, NULL, "projection", "modelview", NULL)) return false; + if (!m_overlay_reload_program.create( + CFS.get_file("shaders/obj.v.glsl"), + CFS.get_file("shaders/overlay_reload.f.glsl"), + "pos", 0, "normal", 1, NULL, + "projection", "modelview", NULL)) if (!m_sky_program.create( CFS.get_file("shaders/sky.v.glsl"), CFS.get_file("shaders/sky.f.glsl"), @@ -552,6 +557,25 @@ void Client::draw_overlay() modelview.to_uniform(m_overlay_hover_program.uniform("modelview")); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + /* draw shot reload bar */ + glViewport(m_width - 200, 50, 150, 25); + m_overlay_reload_program.use(); + m_quad_attributes.bind(); + glEnableVertexAttribArray(0); + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), NULL); + GLMatrix::Identity.to_uniform( + m_overlay_reload_program.uniform("projection")); + modelview.load_identity(); + double reload_pct = + m_players[m_current_player]->m_shot.isNull() + ? 1.0 + : (m_players[m_current_player]->m_shot->get_elapsed_time() / + m_players[m_current_player]->m_shot->get_duration()); + modelview.translate(reload_pct - 1, 0, 0); + modelview.scale(reload_pct * 2, 2.0, 1.0); + modelview.to_uniform(m_overlay_reload_program.uniform("modelview")); + glDrawArrays(GL_TRIANGLE_FAN, 0, 4); + /* draw map border */ glViewport(0, 0, m_width, m_height); m_overlay_program.use(); @@ -576,6 +600,14 @@ void Client::draw_overlay() modelview.to_uniform(m_overlay_program.uniform("modelview")); glDrawArrays(GL_LINE_LOOP, 0, 4); + /* draw shot reload bar border */ + modelview.load_identity(); + modelview.ortho(0, m_width, 0, m_height, -1, 1); + modelview.translate(m_width - 200 + 150 / 2, 50 + 25 / 2, 0); + modelview.scale(150.1, 25.1, 1); + modelview.to_uniform(m_overlay_program.uniform("modelview")); + glDrawArrays(GL_LINE_LOOP, 0, 4); + /* reset GL to normal state */ glDisableVertexAttribArray(0); glEnable(GL_DEPTH_TEST); diff --git a/src/client/Client.h b/src/client/Client.h index 9dd0311..82a1a81 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -55,6 +55,7 @@ class Client GLProgram m_obj_program; GLProgram m_overlay_program; GLProgram m_overlay_hover_program; + GLProgram m_overlay_reload_program; GLProgram m_sky_program; GLProgram m_lava_program; GLProgram m_shot_ring_program;