From 8675018522f623c3bdc4312019230957fa75aac4 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Tue, 2 Feb 2016 00:09:29 +0100 Subject: [PATCH] Graphics: Change Vertex color to 4 components. --- assets/shaders/standard.vert.glsl | 4 ++-- assets/shaders/text.vert.glsl | 4 ++-- include/Spectre/Graphics/Vertex2D.h | 6 +++--- source/Graphics/BatchRenderer2D.cpp | 4 ++-- source/Graphics/Sprite.cpp | 2 +- source/Graphics/Text.cpp | 2 +- source/Graphics/Vertex2D.cpp | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/assets/shaders/standard.vert.glsl b/assets/shaders/standard.vert.glsl index 1902c20..c221d39 100644 --- a/assets/shaders/standard.vert.glsl +++ b/assets/shaders/standard.vert.glsl @@ -3,7 +3,7 @@ uniform mat4 u_MVP; layout(location = 0) in vec3 in_pos; -layout(location = 3) in vec3 in_color; +layout(location = 3) in vec4 in_color; layout(location = 8) in vec2 in_texcoord; out vec4 vColor; @@ -13,7 +13,7 @@ void main(void) { gl_Position = u_MVP * vec4(in_pos, 1.0); - vColor = vec4(in_color, 1.0); + vColor = in_color; // in_texcoord is defined with (0,0) at top-left (same as in_pos) // however, sampling in OpenGL expects bottom-left. So we must flip Y. diff --git a/assets/shaders/text.vert.glsl b/assets/shaders/text.vert.glsl index dd12133..7ad9468 100644 --- a/assets/shaders/text.vert.glsl +++ b/assets/shaders/text.vert.glsl @@ -4,7 +4,7 @@ uniform mat4 u_MVP; uniform sampler2D u_tex0; layout (location = 0) in vec2 in_pos; -layout (location = 3) in vec3 in_color; +layout (location = 3) in vec4 in_color; layout (location = 8) in vec2 in_texCoords; out vec2 vTexCoords; @@ -17,5 +17,5 @@ void main() { // Texture coordinates are in pixels. // Need to convert into UV space before passing to fragment shader. vTexCoords = in_texCoords / textureSize(u_tex0, 0); - vColor = vec4(in_color, 1.0); + vColor = in_color; } diff --git a/include/Spectre/Graphics/Vertex2D.h b/include/Spectre/Graphics/Vertex2D.h index f27ed6e..4f55b98 100644 --- a/include/Spectre/Graphics/Vertex2D.h +++ b/include/Spectre/Graphics/Vertex2D.h @@ -3,7 +3,7 @@ #define SPECTRE_GRAPHICS_VERTEX2D_H #include -#include +#include // Based on https://www.opengl.org/sdk/docs/tutorials/ClockworkCoders/attributes.php enum VertexAttrib @@ -18,13 +18,13 @@ enum VertexAttrib struct Vertex2D { Vector2f position; - Vector3f color; + Vector4f color; Vector2f uv; Vertex2D(); Vertex2D(Vector2f pos); Vertex2D(Vector2f pos, Vector2f uv); - Vertex2D(Vector2f pos, Vector3f color, Vector2f uv = 0.0f); + Vertex2D(Vector2f pos, Vector4f color, Vector2f uv = 0.0f); }; #endif /* SPECTRE_GRAPHICS_VERTEX2D_H */ diff --git a/source/Graphics/BatchRenderer2D.cpp b/source/Graphics/BatchRenderer2D.cpp index 4bbc71c..7cf81f6 100644 --- a/source/Graphics/BatchRenderer2D.cpp +++ b/source/Graphics/BatchRenderer2D.cpp @@ -130,10 +130,10 @@ void BatchRenderer2D::render() // Setup color glEnableVertexAttribArray(VertexAttribColor0); - glVertexAttribPointer(VertexAttribColor0, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), (void*) 8); + glVertexAttribPointer(VertexAttribColor0, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), (void*) 8); glEnableVertexAttribArray(VertexAttribTexCoord0); - glVertexAttribPointer(VertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), (void*) 20); + glVertexAttribPointer(VertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), (void*) 24); // Set shader uniforms. m_textShader.enable(); diff --git a/source/Graphics/Sprite.cpp b/source/Graphics/Sprite.cpp index feee0b6..8ee6851 100644 --- a/source/Graphics/Sprite.cpp +++ b/source/Graphics/Sprite.cpp @@ -60,7 +60,7 @@ void Sprite::setSize(vec2f size) void Sprite::setColor(const Color& color) { - m_vertices[0].color = color.toRGBf(); + m_vertices[0].color = color.toRGBAf(); m_vertices[1].color = m_vertices[0].color; m_vertices[2].color = m_vertices[0].color; m_vertices[3].color = m_vertices[0].color; diff --git a/source/Graphics/Text.cpp b/source/Graphics/Text.cpp index a43eca4..2d39730 100644 --- a/source/Graphics/Text.cpp +++ b/source/Graphics/Text.cpp @@ -92,7 +92,7 @@ void Text::updateGeometry() const { Vector2f origin; Vector2f size = getSize(); - Vector3f color = getColor().toRGBf(); + Vector4f color = getColor().toRGBAf(); m_vertices.clear(); diff --git a/source/Graphics/Vertex2D.cpp b/source/Graphics/Vertex2D.cpp index e16b6f8..2aeccdc 100644 --- a/source/Graphics/Vertex2D.cpp +++ b/source/Graphics/Vertex2D.cpp @@ -22,7 +22,7 @@ uv (_uv) { } -Vertex2D::Vertex2D(Vector2f _pos, Vector3f _color, Vector2f _uv) : +Vertex2D::Vertex2D(Vector2f _pos, Vector4f _color, Vector2f _uv) : position (_pos), color (_color), uv (_uv)