add color at the sprite
This commit is contained in:
parent
4e271d2dcb
commit
969c36f27a
@ -37,6 +37,7 @@ ewol::Sprite::Sprite(etk::UString spriteName)
|
|||||||
m_name = spriteName;
|
m_name = spriteName;
|
||||||
EWOL_VERBOSE("Create Sprite : \"" << m_name << "\"");
|
EWOL_VERBOSE("Create Sprite : \"" << m_name << "\"");
|
||||||
m_textureId = ewol::texture::Load(m_name);
|
m_textureId = ewol::texture::Load(m_name);
|
||||||
|
|
||||||
}
|
}
|
||||||
ewol::Sprite::Sprite(etk::UString spriteName, float sizeX, float sizeY)
|
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 ...");
|
EWOL_WARNING("Texture does not exist ...");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
glColor4f(1.0, 1.0, 1.0, 1.0);
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
//EWOL_WARNING("Draw with texture : " << m_textureId << " ==> ogl=" << ewol::texture::GetGLID(m_textureId));
|
//EWOL_WARNING("Draw with texture : " << m_textureId << " ==> ogl=" << ewol::texture::GetGLID(m_textureId));
|
||||||
glBindTexture(GL_TEXTURE_2D, ewol::texture::GetGLID(m_textureId));
|
glBindTexture(GL_TEXTURE_2D, ewol::texture::GetGLID(m_textureId));
|
||||||
glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays
|
glEnableClientState( GL_VERTEX_ARRAY ); // Enable Vertex Arrays
|
||||||
glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays
|
glEnableClientState( GL_TEXTURE_COORD_ARRAY ); // Enable Texture Coord Arrays
|
||||||
glVertexPointer( 3, GL_FLOAT, 0, &m_coord[0] );
|
glEnableClientState( GL_COLOR_ARRAY ); // Enable Color Arrays
|
||||||
glTexCoordPointer( 2, GL_FLOAT, 0, &m_coordTex[0] );
|
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());
|
glDrawArrays( GL_TRIANGLES, 0, m_coord.Size());
|
||||||
//EWOL_DEBUG("request draw of " << m_coord.Size() << " elements");
|
//EWOL_DEBUG("request draw of " << m_coord.Size() << " elements");
|
||||||
glDisableClientState( GL_VERTEX_ARRAY ); // Disable Vertex Arrays
|
glDisableClientState( GL_COLOR_ARRAY ); // Disable Color Arrays
|
||||||
glDisableClientState( GL_TEXTURE_COORD_ARRAY ); // Disable Texture Coord Arrays
|
glDisableClientState( GL_VERTEX_ARRAY ); // Disable Vertex Arrays
|
||||||
|
glDisableClientState( GL_TEXTURE_COORD_ARRAY ); // Disable Texture Coord Arrays
|
||||||
glDisable(GL_TEXTURE_2D);
|
glDisable(GL_TEXTURE_2D);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,58 +85,36 @@ void ewol::Sprite::Clear(void)
|
|||||||
{
|
{
|
||||||
m_coord.Clear();
|
m_coord.Clear();
|
||||||
m_coordTex.Clear();
|
m_coordTex.Clear();
|
||||||
|
m_coordColor.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ewol::Sprite::Element(Vector2D<float> pos, float size, float angle)
|
void ewol::Sprite::Element(Vector2D<float> pos, float size, float angle)
|
||||||
{
|
{
|
||||||
angle -= M_PI/4;
|
color_ts tmpColor(0xFFFFFFFF);
|
||||||
size *= 0.7;
|
Vector3D<float> pos2;
|
||||||
texCoord_ts texA, texB, texC, texD;
|
pos2.x = pos.x;
|
||||||
texA.u = 0.0;
|
pos2.y = pos.y;
|
||||||
texA.v = 0.0;
|
pos2.z = 0.0;
|
||||||
texB.u = 0.0;
|
Element(pos2, size, angle, tmpColor);
|
||||||
texB.v = 1.0;
|
}
|
||||||
texC.u = 1.0;
|
|
||||||
texC.v = 1.0;
|
void ewol::Sprite::Element(Vector3D<float> pos, float size, float angle)
|
||||||
texD.u = 1.0;
|
{
|
||||||
texD.v = 0.0;
|
color_ts tmpColor(0xFFFFFFFF);
|
||||||
|
Element(pos, size, angle, tmpColor);
|
||||||
Vector3D<float> point;
|
}
|
||||||
point.y = 0;
|
|
||||||
float yyySin = sin(angle) * size;
|
void ewol::Sprite::Element(Vector2D<float> pos, float size, float angle, color_ts tmpColor)
|
||||||
float xxxCos = cos(angle) * size;
|
{
|
||||||
|
Vector3D<float> pos2;
|
||||||
point.x = xxxCos + pos.x;
|
pos2.x = pos.x;
|
||||||
point.y = yyySin + pos.y;
|
pos2.y = pos.y;
|
||||||
m_coord.PushBack(point);
|
pos2.z = 0.0;
|
||||||
m_coordTex.PushBack(texB);
|
Element(pos2, size, angle, tmpColor);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ewol::Sprite::Element(Vector3D<float> pos, float size, float angle)
|
void ewol::Sprite::Element(Vector3D<float> pos, float size, float angle, color_ts tmpColor)
|
||||||
{
|
{
|
||||||
angle -= M_PI/4;
|
angle -= M_PI/4;
|
||||||
size *= 0.7;
|
size *= 0.7;
|
||||||
@ -155,28 +136,34 @@ void ewol::Sprite::Element(Vector3D<float> pos, float size, float angle)
|
|||||||
point.y = yyySin + pos.y;
|
point.y = yyySin + pos.y;
|
||||||
m_coord.PushBack(point);
|
m_coord.PushBack(point);
|
||||||
m_coordTex.PushBack(texB);
|
m_coordTex.PushBack(texB);
|
||||||
|
m_coordColor.PushBack(tmpColor);
|
||||||
|
|
||||||
point.x = yyySin + pos.x;
|
point.x = yyySin + pos.x;
|
||||||
point.y = -xxxCos + pos.y;
|
point.y = -xxxCos + pos.y;
|
||||||
m_coord.PushBack(point);
|
m_coord.PushBack(point);
|
||||||
m_coordTex.PushBack(texC);
|
m_coordTex.PushBack(texC);
|
||||||
|
m_coordColor.PushBack(tmpColor);
|
||||||
|
|
||||||
point.x = -xxxCos + pos.x;
|
point.x = -xxxCos + pos.x;
|
||||||
point.y = -yyySin + pos.y;
|
point.y = -yyySin + pos.y;
|
||||||
m_coord.PushBack(point);
|
m_coord.PushBack(point);
|
||||||
m_coordTex.PushBack(texD);
|
m_coordTex.PushBack(texD);
|
||||||
|
m_coordColor.PushBack(tmpColor);
|
||||||
|
|
||||||
m_coord.PushBack(point);
|
m_coord.PushBack(point);
|
||||||
m_coordTex.PushBack(texD);
|
m_coordTex.PushBack(texD);
|
||||||
|
m_coordColor.PushBack(tmpColor);
|
||||||
|
|
||||||
point.x = -yyySin + pos.x;
|
point.x = -yyySin + pos.x;
|
||||||
point.y = xxxCos + pos.y;
|
point.y = xxxCos + pos.y;
|
||||||
m_coord.PushBack(point);
|
m_coord.PushBack(point);
|
||||||
m_coordTex.PushBack(texA);
|
m_coordTex.PushBack(texA);
|
||||||
|
m_coordColor.PushBack(tmpColor);
|
||||||
|
|
||||||
point.x = xxxCos + pos.x;
|
point.x = xxxCos + pos.x;
|
||||||
point.y = yyySin + pos.y;
|
point.y = yyySin + pos.y;
|
||||||
m_coord.PushBack(point);
|
m_coord.PushBack(point);
|
||||||
m_coordTex.PushBack(texB);
|
m_coordTex.PushBack(texB);
|
||||||
|
m_coordColor.PushBack(tmpColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,11 +40,14 @@ namespace ewol {
|
|||||||
void Clear(void);
|
void Clear(void);
|
||||||
void Element(Vector2D<float> pos, float size, float angle);
|
void Element(Vector2D<float> pos, float size, float angle);
|
||||||
void Element(Vector3D<float> pos, float size, float angle);
|
void Element(Vector3D<float> pos, float size, float angle);
|
||||||
|
void Element(Vector2D<float> pos, float size, float angle, color_ts tmpColor);
|
||||||
|
void Element(Vector3D<float> pos, float size, float angle, color_ts tmpColor);
|
||||||
bool HasName(etk::UString& name) { return name == m_name; };
|
bool HasName(etk::UString& name) { return name == m_name; };
|
||||||
protected:
|
protected:
|
||||||
int32_t m_textureId; //!< texture internal ID
|
int32_t m_textureId; //!< texture internal ID
|
||||||
etk::VectorType<Vector3D<float> > m_coord; //!< internal coord of the object
|
etk::VectorType<Vector3D<float> > m_coord; //!< internal coord of the object
|
||||||
etk::VectorType<texCoord_ts> m_coordTex; //!< internal texture coordinate for every point
|
etk::VectorType<texCoord_ts> m_coordTex; //!< internal texture coordinate for every point
|
||||||
|
etk::VectorType<color_ts> m_coordColor; //!< internal color of the different point
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user