From 00847a8aed2774a207c9278fbd80f59ec53a73fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maciej=20Sumi=C5=84ski?= Date: Sun, 30 Jun 2013 22:45:31 +0200 Subject: [PATCH] Colors are stored as unsigned bytes instead of floats. --- common/gal/opengl/opengl_gal.cpp | 2 +- common/gal/opengl/vbo_item.cpp | 8 ++++---- include/gal/opengl/vbo_container.h | 20 ++++++++++---------- include/gal/opengl/vbo_item.h | 6 +++--- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/common/gal/opengl/opengl_gal.cpp b/common/gal/opengl/opengl_gal.cpp index dde0ff9c6d..83a1f8c90e 100644 --- a/common/gal/opengl/opengl_gal.cpp +++ b/common/gal/opengl/opengl_gal.cpp @@ -511,7 +511,7 @@ void OPENGL_GAL::EndDrawing() // Bind vertices data buffers glBindBuffer( GL_ARRAY_BUFFER, vboVertices ); glVertexPointer( VBO_ITEM::CoordStride, GL_FLOAT, VBO_ITEM::VertByteSize, 0 ); - glColorPointer( VBO_ITEM::ColorStride, GL_FLOAT, VBO_ITEM::VertByteSize, + glColorPointer( VBO_ITEM::ColorStride, GL_UNSIGNED_BYTE, VBO_ITEM::VertByteSize, (GLvoid*) VBO_ITEM::ColorByteOffset ); // Shader parameters diff --git a/common/gal/opengl/vbo_item.cpp b/common/gal/opengl/vbo_item.cpp index a10a75a675..3f3d21b6b0 100644 --- a/common/gal/opengl/vbo_item.cpp +++ b/common/gal/opengl/vbo_item.cpp @@ -83,10 +83,10 @@ void VBO_ITEM::ChangeColor( const COLOR4D& aColor ) for( unsigned int i = 0; i < m_size; ++i ) { - vertexPtr->r = aColor.r; - vertexPtr->g = aColor.g; - vertexPtr->b = aColor.b; - vertexPtr->a = aColor.a; + vertexPtr->r = aColor.r * 255; + vertexPtr->g = aColor.g * 255; + vertexPtr->b = aColor.b * 255; + vertexPtr->a = aColor.a * 255; // Move on to the next vertex vertexPtr++; diff --git a/include/gal/opengl/vbo_container.h b/include/gal/opengl/vbo_container.h index 0d6a8df5c2..2f1c8a3075 100644 --- a/include/gal/opengl/vbo_container.h +++ b/include/gal/opengl/vbo_container.h @@ -150,10 +150,10 @@ public: */ inline void UseColor( const COLOR4D& aColor ) { - m_color[0] = aColor.r; - m_color[1] = aColor.g; - m_color[2] = aColor.b; - m_color[3] = aColor.a; + m_color[0] = aColor.r * 255; + m_color[1] = aColor.g * 255; + m_color[2] = aColor.b * 255; + m_color[3] = aColor.a * 255; } /** @@ -165,7 +165,7 @@ public: { for( unsigned int i = 0; i < VBO_ITEM::ColorStride; ++i ) { - m_color[i] = aColor[i]; + m_color[i] = aColor[i] * 255; } } @@ -179,10 +179,10 @@ public: */ inline void UseColor( GLfloat aR, GLfloat aG, GLfloat aB, GLfloat aA ) { - m_color[0] = aR; - m_color[1] = aG; - m_color[2] = aB; - m_color[3] = aA; + m_color[0] = aR * 255; + m_color[1] = aG * 255; + m_color[2] = aB * 255; + m_color[3] = aA * 255; } /** @@ -318,7 +318,7 @@ private: VBO_ITEM* item; ///< Color used for new vertices pushed. - GLfloat m_color[VBO_ITEM::ColorStride]; + GLubyte m_color[VBO_ITEM::ColorStride]; ///< Shader and its parameters used for new vertices pushed GLfloat m_shader[VBO_ITEM::ShaderStride]; diff --git a/include/gal/opengl/vbo_item.h b/include/gal/opengl/vbo_item.h index 865eb88466..6fc5c4675d 100644 --- a/include/gal/opengl/vbo_item.h +++ b/include/gal/opengl/vbo_item.h @@ -39,7 +39,7 @@ namespace KiGfx typedef struct VBO_VERTEX { GLfloat x, y, z; // Coordinates - GLfloat r, g, b, a; // Color + GLubyte r, g, b, a; // Color GLfloat shader[4]; // Shader type & params } VBO_VERTEX; @@ -136,10 +136,10 @@ public: // Offset of color data from the beginning of each vertex data static const unsigned int ColorByteOffset = offsetof(VBO_VERTEX, r); - static const unsigned int ColorOffset = ColorByteOffset / sizeof(GLfloat); + static const unsigned int ColorOffset = ColorByteOffset / sizeof(GLubyte); static const unsigned int ColorByteSize = sizeof(VBO_VERTEX().r) + sizeof(VBO_VERTEX().g) + sizeof(VBO_VERTEX().b) + sizeof(VBO_VERTEX().a); - static const unsigned int ColorStride = ColorByteSize / sizeof(GLfloat); + static const unsigned int ColorStride = ColorByteSize / sizeof(GLubyte); // Shader attributes static const unsigned int ShaderByteOffset = offsetof(VBO_VERTEX, shader);