From c2615456a0888ca9992ccd2336f18ce5fa78af03 Mon Sep 17 00:00:00 2001 From: Edouard Dupin Date: Sun, 30 Oct 2011 18:29:09 +0100 Subject: [PATCH] Add textured object at the OObject system --- Sources/etk/etkDebug.cpp | 2 +- Sources/ewolOObject.cpp | 80 ++++++++++++++++++-- Sources/ewolOObject.h | 9 +-- Sources/ewolTexture.cpp | 30 ++++---- Sources/ewolWindows.cpp | 154 ++++++--------------------------------- 5 files changed, 115 insertions(+), 160 deletions(-) diff --git a/Sources/etk/etkDebug.cpp b/Sources/etk/etkDebug.cpp index 30f71b7e..a2123c0b 100644 --- a/Sources/etk/etkDebug.cpp +++ b/Sources/etk/etkDebug.cpp @@ -29,7 +29,7 @@ #define EDN_LOG_MAX_LENGTH 250 -#define FUNCTION_NAME_SIZE (50) +#define FUNCTION_NAME_SIZE (70) void TOOLS_DisplayFuncName(int32_t ligne, const char* className, const char* funcName, const char* libName) { diff --git a/Sources/ewolOObject.cpp b/Sources/ewolOObject.cpp index 9468fcbc..5f6faeb7 100644 --- a/Sources/ewolOObject.cpp +++ b/Sources/ewolOObject.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -102,19 +103,88 @@ void ewol::OObject2DColored::Rectangle(float x, float y, float w, float h, float +#undef __class__ +#define __class__ "ewol::OObject2DTextured" -/* -OObject2DTextured::Draw(void) + + +ewol::OObject2DTextured::OObject2DTextured(etk::File textureName) +{ + EWOL_DEBUG("Create OObject textured : \"" << textureName << "\""); + m_textureId = ewol::LoadTexture(textureName); +} + +ewol::OObject2DTextured::~OObject2DTextured(void) +{ + ewol::UnLoadTexture(m_textureId); +} + +void ewol::OObject2DTextured::Draw(void) { if (m_coord.Size()<=0) { + EWOL_WARNING("Nothink to draw..."); return; } + + glColor4f(1.0, 1.0, 1.0, 1.0); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, 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] ); + glVertexPointer( 2, GL_FLOAT, 0, &m_coord[0] ); glTexCoordPointer( 2, GL_FLOAT, 0, &m_coordTex[0] ); - glDrawArrays( GL_TRIANGLES, 0, m_linkCoord.Size()); + 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 + glDisable(GL_TEXTURE_2D); } -*/ + +void ewol::OObject2DTextured::Rectangle(float x, float y, float w, float h, float texX, float texY, float texSX, float texSY) +{ + //EWOL_DEBUG("Add rectangle : ..."); + coord2D_ts point; + texCoord_ts tex; + + tex.u = texX; + tex.v = texY; + point.x = x; + point.y = y; + m_coord.PushBack(point); + m_coordTex.PushBack(tex); + + + tex.u = texSX; + tex.v = texY; + point.x = x + w; + point.y = y; + m_coord.PushBack(point); + m_coordTex.PushBack(tex); + + + tex.u = texSX; + tex.v = texSY; + point.x = x + w; + point.y = y + h; + m_coord.PushBack(point); + m_coordTex.PushBack(tex); + + m_coord.PushBack(point); + m_coordTex.PushBack(tex); + + tex.u = texX; + tex.v = texSY; + point.x = x; + point.y = y + h; + m_coord.PushBack(point); + m_coordTex.PushBack(tex); + + tex.u = texX; + tex.v = texY; + point.x = x; + point.y = y; + m_coord.PushBack(point); + m_coordTex.PushBack(tex); +} + + diff --git a/Sources/ewolOObject.h b/Sources/ewolOObject.h index dd32c1fe..e36bf16e 100644 --- a/Sources/ewolOObject.h +++ b/Sources/ewolOObject.h @@ -26,6 +26,7 @@ #define __EWOL_O_OBJECT_H__ #include +#include #include #include @@ -92,21 +93,19 @@ namespace ewol { }; */ - /* class OObject2DTextured :public ewol::OObject { public: - OObject2DTextured(void) {}; - virtual ~OObject2DTextured(void) {}; + OObject2DTextured(etk::File textureName); + virtual ~OObject2DTextured(void); public: virtual void Draw(void); + void Rectangle(float x, float y, float w, float h, float texX=0.0, float texY=0.0, float texSX=1.0, float texSY=1.0); protected: uint32_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_linkCoord; //!< internal link between point to generate triangle }; - */ }; #endif diff --git a/Sources/ewolTexture.cpp b/Sources/ewolTexture.cpp index 693db394..01043469 100644 --- a/Sources/ewolTexture.cpp +++ b/Sources/ewolTexture.cpp @@ -383,19 +383,17 @@ int32_t ewol::LoadTexture(etk::File fileName) void ewol::UnLoadTexture(uint32_t textureID) { - if (listLoadedTexture.Size()!=0) { - for (int32_t iii=0; iiim_openGlTextureID == textureID) { - listLoadedTexture[iii]->m_nbTimeLoaded--; - if (0 == listLoadedTexture[iii]->m_nbTimeLoaded) { - EWOL_DEBUG("Remove openGL texture ID=" << textureID << " file:" << listLoadedTexture[iii]->m_filename); - glDeleteTextures(1,&listLoadedTexture[iii]->m_openGlTextureID); - delete(listLoadedTexture[iii]); - listLoadedTexture[iii] = NULL; - listLoadedTexture.Erase(iii); - return; - } + for (int32_t iii=0; iiim_openGlTextureID == textureID) { + listLoadedTexture[iii]->m_nbTimeLoaded--; + if (0 == listLoadedTexture[iii]->m_nbTimeLoaded) { + EWOL_DEBUG("Remove openGL texture ID=" << textureID << " file:" << listLoadedTexture[iii]->m_filename); + glDeleteTextures(1,&listLoadedTexture[iii]->m_openGlTextureID); + delete(listLoadedTexture[iii]); + listLoadedTexture[iii] = NULL; + listLoadedTexture.Erase(iii); } + return; } } EWOL_CRITICAL("Can not find TextureId=" << textureID << " in the list of texture loaded...==> to remove it ..."); @@ -404,11 +402,9 @@ void ewol::UnLoadTexture(uint32_t textureID) int32_t ewol::GetTextureSize(uint32_t textureID) { - if (listLoadedTexture.Size()!=0) { - for (int32_t iii=0; iiim_openGlTextureID == textureID) { - return listLoadedTexture[iii]->m_imageSize; - } + for (int32_t iii=0; iiim_openGlTextureID == textureID) { + return listLoadedTexture[iii]->m_imageSize; } } EWOL_ERROR("Can not find TextureId=" << textureID << " in the list of texture loaded..."); diff --git a/Sources/ewolWindows.cpp b/Sources/ewolWindows.cpp index 46c22712..cf48d1ef 100644 --- a/Sources/ewolWindows.cpp +++ b/Sources/ewolWindows.cpp @@ -121,14 +121,13 @@ void ewol::Windows::SysDraw(void) static ewol::OObject2DColored myOObject; + static ewol::OObject2DTextured myOObjectTex_r5g6b5 ("dataTest/test_16b_r5g6b5.bmp"); + static ewol::OObject2DTextured myOObjectTex_x1r5g5b5("dataTest/test_16b_x1r5g5b5.bmp"); + static ewol::OObject2DTextured myOObjectTex_r8g8b8 ("dataTest/test_24b_r8g8b8.bmp"); + static ewol::OObject2DTextured myOObjectTex_x8r8g8b8("dataTest/test_32b_x8r8g8b8.bmp"); + static ewol::OObject2DTextured myOObjectTex_a8r8g8b8("dataTest/test_32b_a8r8g8b8.bmp"); static bool isinit = false; - static int32_t texID1 = -1; - static int32_t texID2 = -1; - static int32_t texID3 = -1; - static int32_t texID4 = -1; - static int32_t texID5 = -1; - static int32_t texID6 = -1; - static int32_t fontID = -1; + static int32_t fontID = 0; if (false == isinit) { isinit=true; @@ -145,32 +144,20 @@ void ewol::Windows::SysDraw(void) myOObject.Rectangle(50, 50, 50, 50, 0.0, 1.0, 0.0, 1.0); myOObject.Rectangle(80, 80, 100, 50, 0.0, 0.0, 1.0, 1.0); myOObject.Rectangle(50, 00, 300, 300, 0.2, 0.2, 0.2, 0.5); - - //myOObject.Rectangle(-50, -50, 120, 120, 0.0, 1.0, 1.0, 0.5); - - - etk::File myFile("dataTest/test_16b_r5g6b5.bmp"); - texID1 = LoadTexture(myFile); - myFile = "dataTest/test_16b_x1r5g5b5.bmp"; - texID2 = LoadTexture(myFile); - myFile = "dataTest/test_24b_r8g8b8.bmp"; - texID3 = LoadTexture(myFile); - myFile = "dataTest/test_32b_x8r8g8b8.bmp"; - texID4 = LoadTexture(myFile); - myFile = "dataTest/test_16b_a1r5g5b5.bmp"; - texID5 = LoadTexture(myFile); - myFile = "dataTest/test_32b_a8r8g8b8.bmp"; - texID6 = LoadTexture(myFile); - - myOObject.Rectangle(300, 300, 50, 50, 1.0, 1.0, 1.0, 1.0); - myOObject.Rectangle(350, 350, 50, 50, 1.0, 0.0, 0.0, 1.0); - myOObject.Rectangle(400, 400, 50, 50, 0.0, 1.0, 0.0, 1.0); - myOObject.Rectangle(450, 450, 50, 50, 0.0, 0.0, 1.0, 1.0); - myOObject.Rectangle(500, 500, 50, 50, 0.0, 0.0, 0.0, 1.0); - + /* myOObject.Rectangle(200, 300, 900, 54, 0.0, 0.0, 0.0, 1.0); myOObject.Rectangle(200, 300, 900, 13, 0.0, 1.0, 0.0, 1.0); myOObject.Rectangle(200, 343, 900, 11, 1.0, 0.0, 0.0, 1.0); + */ + + myOObjectTex_r5g6b5.Rectangle( 300, 0, 100, 100); + myOObjectTex_x1r5g5b5.Rectangle(300, 100, 100, 100); + myOObjectTex_r8g8b8.Rectangle( 300, 200, 100, 100); + myOObjectTex_x8r8g8b8.Rectangle(400, 0, 100, 100); + myOObjectTex_a8r8g8b8.Rectangle(400, 100, 100, 100); + + + if (true == ewol::AddFont("dataTest/TextMonospace.ebt", true, true, true) ) { fontID = GetFontIdWithFileName("dataTest/TextMonospace.ebt"); } @@ -178,108 +165,11 @@ void ewol::Windows::SysDraw(void) } myOObject.Draw(); - - if (texID3 > -1) { - glColor4f(1.0, 1.0, 1.0, 0.5); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, texID3); - glBegin(GL_QUADS); - glTexCoord2f(0.0, 0.0); - glVertex3f(300.0, 300.0, 0.0); - glTexCoord2f(1.0, 0.0); - glVertex3f(550.0, 300.0, 0.0); - glTexCoord2f(1.0, 1.0); - glVertex3f(550.0, 550.0, 0.0); - glTexCoord2f(0.0, 1.0); - glVertex3f(300.0, 550.0, 0.0); - glEnd(); - glDisable(GL_TEXTURE_2D); - } - - - if (texID1 > -1) { - glColor4f(1.0, 1.0, 1.0, 1.0); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, texID1); - glBegin(GL_QUADS); - glTexCoord2f(0.0, 0.0); - glVertex3f(300.0, 0.0, 0.0); - glTexCoord2f(1.0, 0.0); - glVertex3f(400.0, 0.0, 0.0); - glTexCoord2f(1.0, 1.0); - glVertex3f(400.0, 100.0, 0.0); - glTexCoord2f(0.0, 1.0); - glVertex3f(300.0, 100.0, 0.0); - glEnd(); - glDisable(GL_TEXTURE_2D); - } - - if (texID2 > -1) { - glColor4f(1.0, 1.0, 1.0, 1.0); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, texID2); - glBegin(GL_QUADS); - glTexCoord2f(0.0, 0.0); - glVertex3f(300.0, 100.0, 0.0); - glTexCoord2f(1.0, 0.0); - glVertex3f(400.0, 100.0, 0.0); - glTexCoord2f(1.0, 1.0); - glVertex3f(400.0, 200.0, 0.0); - glTexCoord2f(0.0, 1.0); - glVertex3f(300.0, 200.0, 0.0); - glEnd(); - glDisable(GL_TEXTURE_2D); - } - - if (texID4 > -1) { - glColor4f(1.0, 1.0, 1.0, 1.0); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, texID4); - glBegin(GL_QUADS); - glTexCoord2f(0.0, 0.0); - glVertex3f(300.0, 200.0, 0.0); - glTexCoord2f(1.0, 0.0); - glVertex3f(400.0, 200.0, 0.0); - glTexCoord2f(1.0, 1.0); - glVertex3f(400.0, 300.0, 0.0); - glTexCoord2f(0.0, 1.0); - glVertex3f(300.0, 300.0, 0.0); - glEnd(); - glDisable(GL_TEXTURE_2D); - } - - if (texID5 > -1) { - glColor4f(1.0, 1.0, 1.0, 1.0); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, texID5); - glBegin(GL_QUADS); - glTexCoord2f(0.0, 0.0); - glVertex3f(400.0, 0.0, 0.0); - glTexCoord2f(1.0, 0.0); - glVertex3f(500.0, 0.0, 0.0); - glTexCoord2f(1.0, 1.0); - glVertex3f(500.0, 100.0, 0.0); - glTexCoord2f(0.0, 1.0); - glVertex3f(400.0, 100.0, 0.0); - glEnd(); - glDisable(GL_TEXTURE_2D); - } - if (texID6 > -1) { - glColor4f(1.0, 1.0, 1.0, 1.0); - glEnable(GL_TEXTURE_2D); - glBindTexture(GL_TEXTURE_2D, texID6); - glBegin(GL_QUADS); - glTexCoord2f(0.0, 0.0); - glVertex3f(400.0, 100.0, 0.0); - glTexCoord2f(1.0, 0.0); - glVertex3f(500.0, 100.0, 0.0); - glTexCoord2f(1.0, 1.0); - glVertex3f(500.0, 200.0, 0.0); - glTexCoord2f(0.0, 1.0); - glVertex3f(400.0, 200.0, 0.0); - glEnd(); - glDisable(GL_TEXTURE_2D); - } + myOObjectTex_r5g6b5.Draw(); + myOObjectTex_x1r5g5b5.Draw(); + myOObjectTex_r8g8b8.Draw(); + myOObjectTex_x8r8g8b8.Draw(); + myOObjectTex_a8r8g8b8.Draw(); coord3D_ts drawPosition = { 200.0, 300.0, 0.0};