From 969c36f27a912fad2bd606b72ab5953a9da3caae Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Thu, 21 Jun 2012 18:31:39 +0200 Subject: [PATCH] add color at the sprite --- Sources/libewol/ewol/OObject/Sprite.cpp | 91 +++++++++++-------------- Sources/libewol/ewol/OObject/Sprite.h | 3 + 2 files changed, 42 insertions(+), 52 deletions(-) diff --git a/Sources/libewol/ewol/OObject/Sprite.cpp b/Sources/libewol/ewol/OObject/Sprite.cpp index 35bbade1..f61fbf27 100644 --- a/Sources/libewol/ewol/OObject/Sprite.cpp +++ b/Sources/libewol/ewol/OObject/Sprite.cpp @@ -37,6 +37,7 @@ ewol::Sprite::Sprite(etk::UString spriteName) m_name = spriteName; EWOL_VERBOSE("Create Sprite : \"" << m_name << "\""); m_textureId = ewol::texture::Load(m_name); + } ewol::Sprite::Sprite(etk::UString spriteName, float sizeX, float sizeY) { @@ -63,18 +64,20 @@ void ewol::Sprite::Draw(void) EWOL_WARNING("Texture does not exist ..."); return; } - glColor4f(1.0, 1.0, 1.0, 1.0); glEnable(GL_TEXTURE_2D); //EWOL_WARNING("Draw with texture : " << m_textureId << " ==> ogl=" << ewol::texture::GetGLID(m_textureId)); glBindTexture(GL_TEXTURE_2D, ewol::texture::GetGLID(m_textureId)); - glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays - glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays - glVertexPointer( 3, GL_FLOAT, 0, &m_coord[0] ); - glTexCoordPointer( 2, GL_FLOAT, 0, &m_coordTex[0] ); + glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays + glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays + glEnableClientState( GL_COLOR_ARRAY ); // Enable Color Arrays + glVertexPointer( 3, GL_FLOAT, 0, &m_coord[0] ); + glTexCoordPointer( 2, GL_FLOAT, 0, &m_coordTex[0] ); + glColorPointer( 4, GL_UNSIGNED_BYTE, 0, &m_coordColor[0] ); glDrawArrays( GL_TRIANGLES, 0, m_coord.Size()); //EWOL_DEBUG("request draw of " << m_coord.Size() << " elements"); - glDisableClientState( GL_VERTEX_ARRAY ); // Disable Vertex Arrays - glDisableClientState( GL_TEXTURE_COORD_ARRAY ); // Disable Texture Coord Arrays + glDisableClientState( GL_COLOR_ARRAY ); // Disable Color Arrays + glDisableClientState( GL_VERTEX_ARRAY ); // Disable Vertex Arrays + glDisableClientState( GL_TEXTURE_COORD_ARRAY ); // Disable Texture Coord Arrays glDisable(GL_TEXTURE_2D); } @@ -82,58 +85,36 @@ void ewol::Sprite::Clear(void) { m_coord.Clear(); m_coordTex.Clear(); + m_coordColor.Clear(); } void ewol::Sprite::Element(Vector2D pos, float size, float angle) { - angle -= M_PI/4; - size *= 0.7; - texCoord_ts texA, texB, texC, texD; - texA.u = 0.0; - texA.v = 0.0; - texB.u = 0.0; - texB.v = 1.0; - texC.u = 1.0; - texC.v = 1.0; - texD.u = 1.0; - texD.v = 0.0; - - Vector3D point; - point.y = 0; - float yyySin = sin(angle) * size; - float xxxCos = cos(angle) * size; - - point.x = xxxCos + pos.x; - point.y = yyySin + pos.y; - m_coord.PushBack(point); - m_coordTex.PushBack(texB); - - point.x = yyySin + pos.x; - point.y = -xxxCos + pos.y; - m_coord.PushBack(point); - m_coordTex.PushBack(texC); - - point.x = -xxxCos + pos.x; - point.y = -yyySin + pos.y; - m_coord.PushBack(point); - m_coordTex.PushBack(texD); - - m_coord.PushBack(point); - m_coordTex.PushBack(texD); - - point.x = -yyySin + pos.x; - point.y = xxxCos + pos.y; - m_coord.PushBack(point); - m_coordTex.PushBack(texA); - - point.x = xxxCos + pos.x; - point.y = yyySin + pos.y; - m_coord.PushBack(point); - m_coordTex.PushBack(texB); + color_ts tmpColor(0xFFFFFFFF); + Vector3D pos2; + pos2.x = pos.x; + pos2.y = pos.y; + pos2.z = 0.0; + Element(pos2, size, angle, tmpColor); +} + +void ewol::Sprite::Element(Vector3D pos, float size, float angle) +{ + color_ts tmpColor(0xFFFFFFFF); + Element(pos, size, angle, tmpColor); +} + +void ewol::Sprite::Element(Vector2D pos, float size, float angle, color_ts tmpColor) +{ + Vector3D pos2; + pos2.x = pos.x; + pos2.y = pos.y; + pos2.z = 0.0; + Element(pos2, size, angle, tmpColor); } -void ewol::Sprite::Element(Vector3D pos, float size, float angle) +void ewol::Sprite::Element(Vector3D pos, float size, float angle, color_ts tmpColor) { angle -= M_PI/4; size *= 0.7; @@ -155,28 +136,34 @@ void ewol::Sprite::Element(Vector3D pos, float size, float angle) point.y = yyySin + pos.y; m_coord.PushBack(point); m_coordTex.PushBack(texB); + m_coordColor.PushBack(tmpColor); point.x = yyySin + pos.x; point.y = -xxxCos + pos.y; m_coord.PushBack(point); m_coordTex.PushBack(texC); + m_coordColor.PushBack(tmpColor); point.x = -xxxCos + pos.x; point.y = -yyySin + pos.y; m_coord.PushBack(point); m_coordTex.PushBack(texD); + m_coordColor.PushBack(tmpColor); m_coord.PushBack(point); m_coordTex.PushBack(texD); + m_coordColor.PushBack(tmpColor); point.x = -yyySin + pos.x; point.y = xxxCos + pos.y; m_coord.PushBack(point); m_coordTex.PushBack(texA); + m_coordColor.PushBack(tmpColor); point.x = xxxCos + pos.x; point.y = yyySin + pos.y; m_coord.PushBack(point); m_coordTex.PushBack(texB); + m_coordColor.PushBack(tmpColor); } diff --git a/Sources/libewol/ewol/OObject/Sprite.h b/Sources/libewol/ewol/OObject/Sprite.h index fc3fae59..283fa550 100644 --- a/Sources/libewol/ewol/OObject/Sprite.h +++ b/Sources/libewol/ewol/OObject/Sprite.h @@ -40,11 +40,14 @@ namespace ewol { void Clear(void); void Element(Vector2D pos, float size, float angle); void Element(Vector3D pos, float size, float angle); + void Element(Vector2D pos, float size, float angle, color_ts tmpColor); + void Element(Vector3D pos, float size, float angle, color_ts tmpColor); bool HasName(etk::UString& name) { return name == m_name; }; protected: int32_t m_textureId; //!< texture internal ID etk::VectorType > m_coord; //!< internal coord of the object etk::VectorType m_coordTex; //!< internal texture coordinate for every point + etk::VectorType m_coordColor; //!< internal color of the different point }; };