diff --git a/data/shaders/colortexturedquad.vert b/data/shaders/colortexturedquad.vert index 06bd61b40..4c7a4b352 100644 --- a/data/shaders/colortexturedquad.vert +++ b/data/shaders/colortexturedquad.vert @@ -6,11 +6,11 @@ uniform vec2 texsize; #ifdef Explicit_Attrib_Location_Usable layout(location=0) in vec2 Position; layout(location=3) in vec2 Texcoord; -layout(location=2) in uvec4 Color; +layout(location=2) in vec4 Color; #else in vec2 Position; in vec2 Texcoord; -in uvec4 Color; +in vec4 Color; #endif out vec2 uv; @@ -18,7 +18,7 @@ out vec4 col; void main() { - col = vec4(Color) / 255.; + col = Color.zyxw; uv = Texcoord * texsize + texcenter; gl_Position = vec4(Position * size + center, 0., 1.); } diff --git a/src/graphics/2dutils.cpp b/src/graphics/2dutils.cpp index 91ca4cee7..7ad16a848 100644 --- a/src/graphics/2dutils.cpp +++ b/src/graphics/2dutils.cpp @@ -93,41 +93,12 @@ class ColoredTextureRectShader : public TextureShader { -#ifdef XX -private: - GLuint m_quad_buffer; - - void initQuadBuffer() - { - const float quad_vertex[] = { -1., -1., -1., 1., // UpperLeft - -1., 1., -1., -1., // LowerLeft - 1., -1., 1., 1., // UpperRight - 1., 1., 1., -1. }; // LowerRight - glGenBuffers(1, &m_quad_buffer); - glBindBuffer(GL_ARRAY_BUFFER, m_quad_buffer); - glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), quad_vertex, - GL_STATIC_DRAW); - - glGenVertexArrays(1, &SharedObject::UIVAO); - glBindVertexArray(SharedObject::UIVAO); - glEnableVertexAttribArray(0); - glEnableVertexAttribArray(3); - glBindBuffer(GL_ARRAY_BUFFER, m_quad_buffer); - glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); - glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), - (GLvoid *)(2 * sizeof(float))); - glBindVertexArray(0); - } // initQuadBuffer -#endif public: GLuint m_color_vbo; GLuint m_vao; ColoredTextureRectShader() { -#ifdef XX - initQuadBuffer(); -#endif loadProgram(OBJECT, GL_VERTEX_SHADER, "colortexturedquad.vert", GL_FRAGMENT_SHADER, "colortexturedquad.frag"); assignUniforms("center", "size", "texcenter", "texsize"); @@ -143,16 +114,15 @@ public: glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), 0); glVertexAttribPointer(3, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (GLvoid *)(2 * sizeof(float))); - const unsigned quad_color[] = { 0, 0, 0, 255, + glBindVertexArray(0); + const uint8_t quad_color[] = { 0, 0, 0, 255, 255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255, 255 }; glGenBuffers(1, &m_color_vbo); glBindBuffer(GL_ARRAY_BUFFER, m_color_vbo); - glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(unsigned), quad_color, - GL_DYNAMIC_DRAW); - glVertexAttribIPointer(2, 4, GL_UNSIGNED_INT, 4 * sizeof(unsigned), 0); - glBindVertexArray(0); + glBufferData(GL_ARRAY_BUFFER, 16, quad_color, GL_DYNAMIC_DRAW); + } // ColoredTextureRectShader }; // ColoredTextureRectShader @@ -164,16 +134,11 @@ static void drawTexColoredQuad(const video::ITexture *texture, float tex_center_pos_y, float tex_width, float tex_height) { - unsigned colors[] = { - col[0].getRed(), col[0].getGreen(), col[0].getBlue(), col[0].getAlpha(), - col[1].getRed(), col[1].getGreen(), col[1].getBlue(), col[1].getAlpha(), - col[2].getRed(), col[2].getGreen(), col[2].getBlue(), col[2].getAlpha(), - col[3].getRed(), col[3].getGreen(), col[3].getBlue(), col[3].getAlpha(), - }; - + glBindVertexArray(ColoredTextureRectShader::getInstance()->m_vao); glBindBuffer(GL_ARRAY_BUFFER, ColoredTextureRectShader::getInstance()->m_color_vbo); - glBufferSubData(GL_ARRAY_BUFFER, 0, 16 * sizeof(unsigned), colors); + glBufferSubData(GL_ARRAY_BUFFER, 0, 16, col); + glVertexAttribPointer(2, 4, GL_UNSIGNED_BYTE, GL_TRUE, 4 , 0); ColoredTextureRectShader::getInstance()->use(); glBindVertexArray(ColoredTextureRectShader::getInstance()->m_vao); @@ -186,8 +151,9 @@ static void drawTexColoredQuad(const video::ITexture *texture, core::vector2df(tex_width, tex_height)); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - glBindVertexArray(0); glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindVertexArray(0); + glGetError(); } // drawTexColoredQuad