From 741a325a5f4195679b6c8b4a04cab34ae9c026b4 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Thu, 27 Sep 2012 23:01:52 -0400 Subject: [PATCH] add shot-ring shader and create shot-ring attributes buffer --- assets/fs/shaders/shot-ring.f.glsl | 5 +++++ assets/fs/shaders/shot-ring.v.glsl | 13 +++++++++++++ src/client/Client-gl.cc | 25 +++++++++++++++++++++++++ src/client/Client.h | 1 + 4 files changed, 44 insertions(+) create mode 100644 assets/fs/shaders/shot-ring.f.glsl create mode 100644 assets/fs/shaders/shot-ring.v.glsl diff --git a/assets/fs/shaders/shot-ring.f.glsl b/assets/fs/shaders/shot-ring.f.glsl new file mode 100644 index 0000000..660872d --- /dev/null +++ b/assets/fs/shaders/shot-ring.f.glsl @@ -0,0 +1,5 @@ + +void main(void) +{ + gl_FragColor = vec4(1.0, 0.1, 0.1, 1.0); +} diff --git a/assets/fs/shaders/shot-ring.v.glsl b/assets/fs/shaders/shot-ring.v.glsl new file mode 100644 index 0000000..2d2fb41 --- /dev/null +++ b/assets/fs/shaders/shot-ring.v.glsl @@ -0,0 +1,13 @@ + +uniform mat4 projection; +uniform mat4 modelview; +uniform float scale; + +/* pos.xyz is position, pos.w is offset */ +attribute vec4 pos; + +void main(void) +{ + vec3 pos3 = pos.xyz * (scale + pos.w); + gl_Position = projection * modelview * vec4(pos3, 1); +} diff --git a/src/client/Client-gl.cc b/src/client/Client-gl.cc index 41fc340..c1ade35 100644 --- a/src/client/Client-gl.cc +++ b/src/client/Client-gl.cc @@ -17,6 +17,8 @@ using namespace std; #define SKY_DIST 2000 #define NUM_SKY_STEPS 9 #define LAVA_SIZE 100 +#define SHOT_RING_WIDTH 20.0f +#define NUM_SHOT_RING_STEPS 24 /* points of a horizontal hexagon 1.0 units high */ static const float overlay_hex_attributes[][3] = { @@ -183,6 +185,29 @@ bool Client::initgl() cerr << "Error creating sky attribute buffer" << endl; return false; } + vector shot_ring_attributes((NUM_SHOT_RING_STEPS + 1) * 2 * 4); + for (int i = 0, idx = 0; i <= NUM_SHOT_RING_STEPS; i++) + { + double angle = i * M_PI * 2.0 / NUM_SHOT_RING_STEPS; + GLfloat x = sin(angle); + GLfloat y = cos(angle); + shot_ring_attributes[idx++] = x; + shot_ring_attributes[idx++] = y; + shot_ring_attributes[idx++] = 0.0f; + shot_ring_attributes[idx++] = 0.0f; + + shot_ring_attributes[idx++] = x; + shot_ring_attributes[idx++] = y; + shot_ring_attributes[idx++] = 0.0f; + shot_ring_attributes[idx++] = SHOT_RING_WIDTH; + } + if (!m_shot_ring_attributes.create(GL_ARRAY_BUFFER, GL_STATIC_DRAW, + &shot_ring_attributes[0], + sizeof(shot_ring_attributes[0]) * shot_ring_attributes.size())) + { + cerr << "Error creating shot ring attributes buffer" << endl; + return false; + } unsigned int lava_texture_length; const uint8_t *lava_texture = CFS.get_file("textures/lava.jpg", &lava_texture_length); diff --git a/src/client/Client.h b/src/client/Client.h index 6518f71..0c967c4 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -52,6 +52,7 @@ class Client GLBuffer m_sky_attributes; GLBuffer m_tex_quad_attributes; GLBuffer m_quad_attributes; + GLBuffer m_shot_ring_attributes; refptr m_net_client; bool client_has_focus; sf::Texture m_lava_texture;