diff --git a/Makefile b/Makefile index 98010f5d..f8954a8c 100644 --- a/Makefile +++ b/Makefile @@ -168,6 +168,7 @@ CXXFILES += etk/etkDebug.cpp \ CXXFILES += ewol.cpp \ ewolDebug.cpp \ ewolOObject.cpp \ + ewolTexture.cpp \ ewolWidget.cpp \ ewolWindows.cpp diff --git a/Sources/etk/etkDebug.h b/Sources/etk/etkDebug.h index 58cb6001..fbfeff51 100644 --- a/Sources/etk/etkDebug.h +++ b/Sources/etk/etkDebug.h @@ -74,11 +74,12 @@ void TOOLS_DisplayTime(void); std::cout << "[" << info << "] " << data; \ std::cout << ETK_BASH_COLOR_NORMAL < 3 +# define TK_VERBOSE(data) ETK_VERBOSE(etkLibName, data) +#else +# define TK_VERBOSE(data) do {}while(0) +#endif + #define TK_ASSERT(cond, data) ETK_ASSERT(etkLibName, cond, data) #if ETK_DEBUG_LEVEL > 1 diff --git a/Sources/etk/etkFile.cpp b/Sources/etk/etkFile.cpp index dbd73225..22de2282 100644 --- a/Sources/etk/etkFile.cpp +++ b/Sources/etk/etkFile.cpp @@ -24,6 +24,7 @@ #include +#include #include @@ -144,14 +145,14 @@ void etk::File::SetCompleateName(etk::String &newFilename) m_folder = ""; m_shortFilename = ""; m_lineNumberOpen = 0; - TK_DEBUG("1 :Set Name : " << newFilename ); + TK_VERBOSE("1 :Set Name : " << newFilename ); etk::String destFilename; if (newFilename.Size() == 0) { destFilename = "no-name"; } else { destFilename = newFilename; } - TK_DEBUG("2 : Get file Name : " << destFilename ); + TK_VERBOSE("2 : Get file Name : " << destFilename ); if ('/' != *destFilename.c_str()) { // Get the command came from the running of the program : char cCurrentPath[FILENAME_MAX]; @@ -164,7 +165,7 @@ void etk::File::SetCompleateName(etk::String &newFilename) destFilename += '/'; destFilename += tmpFilename; } - TK_DEBUG("3 : Get file Name : " << destFilename ); + TK_VERBOSE("3 : Get file Name : " << destFilename ); // Get the real Path of the current File ok = realpath(destFilename.c_str(), buf); @@ -174,10 +175,10 @@ void etk::File::SetCompleateName(etk::String &newFilename) // Get the FileName etk::String tmpFilename = destFilename.Extract(lastPos+1); destFilename.Remove(lastPos, destFilename.Size() - lastPos); - TK_DEBUG("try to find :\"" << destFilename << "\" / \"" << tmpFilename << "\" "); + TK_VERBOSE("try to find :\"" << destFilename << "\" / \"" << tmpFilename << "\" "); ok = realpath(destFilename.c_str(), buf); if (!ok) { - TK_ERROR("Can not find real Path name of \"" << destFilename << "\""); + TK_VERBOSE("Can not find real Path name of \"" << destFilename << "\""); m_shortFilename = tmpFilename; m_folder = destFilename; } else { @@ -202,7 +203,7 @@ void etk::File::SetCompleateName(etk::String &newFilename) m_shortFilename = destFilename; } } - TK_DEBUG("Set FileName :\"" << m_folder << "\" / \"" << m_shortFilename << "\" "); + TK_VERBOSE("Set FileName :\"" << m_folder << "\" / \"" << m_shortFilename << "\" "); } int32_t etk::File::GetLineNumber(void) @@ -242,3 +243,35 @@ etk::String etk::File::GetExtention(void) } return tmpExt; } + + + +int32_t etk::File::Size(void) +{ + FILE *myFile=NULL; + etk::String myCompleateName = GetCompleateName(); + myFile=fopen(myCompleateName.c_str(),"rb"); + if(NULL == myFile) { + //EWOL_ERROR("Can not find the file name=\"" << m_folder << "\" / \"" << m_shortFilename << "\""); + return -1; + } + int32_t size = 0; + fseek(myFile, 0, SEEK_END); + size = ftell(myFile); + fseek(myFile, 0, SEEK_SET); + fclose(myFile); + return size; +} + + +bool etk::File::Exist(void) +{ + FILE *myFile=NULL; + etk::String myCompleateName = GetCompleateName(); + myFile=fopen(myCompleateName.c_str(),"rb"); + if(NULL == myFile) { + return false; + } + fclose(myFile); + return true; +} diff --git a/Sources/etk/etkFile.h b/Sources/etk/etkFile.h index 82a95b24..7b8fb351 100644 --- a/Sources/etk/etkFile.h +++ b/Sources/etk/etkFile.h @@ -44,6 +44,8 @@ namespace etk etk::String GetCompleateName(void) const; bool HasExtention(void); etk::String GetExtention(void); + int32_t Size(void); + bool Exist(void); int32_t GetLineNumber(void); void SetLineNumber(int32_t newline); void SetCompleateName(etk::String &newFilename); diff --git a/Sources/ewolOObject.cpp b/Sources/ewolOObject.cpp index 4dbbfdcc..ec605489 100644 --- a/Sources/ewolOObject.cpp +++ b/Sources/ewolOObject.cpp @@ -50,8 +50,8 @@ void ewol::OObject2DColored::Draw(void) //EWOL_DEBUG("Draw ..." << m_coord.Size()/3 << " triangle(s)"); // Disable Pointers - glDisableClientState( GL_VERTEX_ARRAY ); glDisableClientState( GL_COLOR_ARRAY ); + glDisableClientState( GL_VERTEX_ARRAY ); } diff --git a/Sources/ewolTexture.cpp b/Sources/ewolTexture.cpp new file mode 100644 index 00000000..83931340 --- /dev/null +++ b/Sources/ewolTexture.cpp @@ -0,0 +1,345 @@ +/** + ******************************************************************************* + * @file ewolTexture.cpp + * @brief ewol Texture loading system (sources) + * @author Edouard DUPIN + * @date 28/10/2011 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + + + +#include + +extern "C" +{ +#pragma pack(push,1) + typedef struct + { + int16_t bfType; + int32_t bfSize; + int32_t bfReserved; + int32_t bfOffBits; + } bitmapFileHeader_ts; + + typedef struct + { + int32_t biSize; + int32_t biWidth; + int32_t biHeight; + int16_t biPlanes; + int16_t biBitCount; + int32_t biCompression; + int32_t biSizeImage; + int32_t biXPelsPerMeter; + int32_t biYPelsPerMeter; + int32_t biClrUsed; + int32_t biClrImportant; + } bitmapInfoHeader_ts; +#pragma pack(pop) + + typedef enum { + BITS_16_R5G6B5, + BITS_16_X1R5G5B5, + BITS_24_R8G8B8, + BITS_32_X8R8G8B8, + BITS_32_A8R8G8B8 + } modeBitmap_te; +}; + +class Bitmap +{ + private: + modeBitmap_te m_dataMode; + int32_t m_width; + int32_t m_height; + int32_t m_size; + uint8_t * m_data; + uint8_t * m_dataGenerate; + bitmapFileHeader_ts m_FileHeader; + bitmapInfoHeader_ts m_InfoHeader; + public: + Bitmap(etk::File & fileName) : m_data(NULL), m_dataGenerate(NULL) + { + m_dataMode = BITS_16_R5G6B5; + m_width = 0; + m_height = 0; + m_size = 0; + + FILE *File=NULL; + // Get the fileSize ... + if (fileName.Size() < sizeof(bitmapFileHeader_ts) + sizeof(bitmapInfoHeader_ts) ) { + EWOL_ERROR("not enought data in the file named=\"" << fileName << "\""); + return; + } + unsigned int ImageIdx=0; + File=fopen(fileName.GetCompleateName().c_str(),"rb"); + if(NULL == File) { + EWOL_ERROR("Can not find the file name=\"" << fileName << "\""); + return; + } + // get the data : + if (fread(&m_FileHeader,sizeof(bitmapFileHeader_ts),1,File) != 1) { + EWOL_ERROR("error loading file header"); + fclose(File); + return; + } + if (fread(&m_InfoHeader,sizeof(bitmapInfoHeader_ts),1,File) != 1) { + EWOL_ERROR("error loading file header"); + fclose(File); + return; + } + // TODO : do otherwise ... + fseek(File,m_FileHeader.bfOffBits,SEEK_SET); + if(ferror(File)) { + EWOL_ERROR("error with the 'bfOffBits' in the file named=\"" << fileName << "\""); + fclose(File); + return; + } + // Check the header error : + if (m_FileHeader.bfType != 0x4D42) { + EWOL_ERROR("the file=\"" << fileName << "\" is not a bitmap file ..."); + fclose(File); + return; + } + if (m_FileHeader.bfReserved != 0x00000000) { + EWOL_ERROR("the bfReserved feald is not at 0 ==> not supported format ..."); + fclose(File); + return; + } + if( m_InfoHeader.biBitCount == 16 + && m_InfoHeader.biCompression == 0) + { + m_dataMode = BITS_16_X1R5G5B5; + } else if( m_InfoHeader.biBitCount == 16 + && m_InfoHeader.biCompression == 3) + { + m_dataMode = BITS_16_R5G6B5; + } else if( m_InfoHeader.biBitCount == 24 + && m_InfoHeader.biCompression == 0) + { + m_dataMode = BITS_24_R8G8B8; + } else if( m_InfoHeader.biBitCount == 32 + && m_InfoHeader.biCompression == 3) + { + m_dataMode = BITS_32_X8R8G8B8; + } else if( m_InfoHeader.biBitCount == 32 + && m_InfoHeader.biCompression == 0) + { + m_dataMode = BITS_32_A8R8G8B8; + } else { + EWOL_ERROR("the biBitCount & biCompression fealds are unknow ==> not supported format ..."); + fclose(File); + return; + } + m_width = m_InfoHeader.biWidth; + m_height = m_InfoHeader.biHeight; + + if(0 != m_InfoHeader.biSizeImage) + { + m_data=new uint8_t[m_InfoHeader.biSizeImage]; + fread(m_data,m_InfoHeader.biSizeImage,1,File); + // allocate the destination data ... + m_dataGenerate=new uint8_t[m_width*m_height*4]; + } + fclose(File); + // need now to generate RGBA data ... + switch(m_dataMode) + { + case BITS_16_R5G6B5: + { + uint16_t * pointer = (uint16_t*)m_data; + uint8_t * pointerdst = m_dataGenerate; + for(int32_t yyy=0; yyy> 8); + m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 1] = (int8_t)((*pointer & 0x07E0) >> 3); + m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 2] = (int8_t)(*pointer << 3); + m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 3] = 0xFF; + pointer++; + } + } + } + break; + case BITS_16_X1R5G5B5: + { + uint16_t * pointer = (uint16_t*)m_data; + uint8_t * pointerdst = m_dataGenerate; + for(int32_t yyy=0; yyy> 7); + m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 1] = (int8_t)((*pointer & 0x03E0) >> 2); + m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 2] = (int8_t)(*pointer << 3); + m_dataGenerate[4*((m_height-yyy-1) * m_width + xxx ) + 3] = 0xFF; + pointer++; + } + } + } + break; + case BITS_24_R8G8B8: + { + uint8_t * pointer = m_data; + for(int32_t yyy=0; yyy +#include + +int32_t ewol::LoadTexture(etk::File & fileName) +{ + etk::String fileExtention = fileName.GetExtention(); + if (fileExtention == "bmp") { + if (false == fileName.Exist()) { + EWOL_ERROR("File does not Exist ... " << fileName); + return -1; + } + Bitmap myBitmap(fileName); + myBitmap.Display(); + if (myBitmap.LoadOK() == true) { + GLuint textureid; + glGenTextures(1, &textureid); + glBindTexture(GL_TEXTURE_2D, textureid); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); + //--- mode nearest + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + //--- Mode linear + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, myBitmap.Width(), myBitmap.Height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, myBitmap.Data()); + return textureid; + } else { + return -1; + } + } else { + EWOL_ERROR("Extention not manage " << fileName); + return -1; + } +} + +void ewol::UnLoadTexture(int32_t textureID) +{ + +} + diff --git a/Sources/ewolTexture.h b/Sources/ewolTexture.h new file mode 100644 index 00000000..5bbed713 --- /dev/null +++ b/Sources/ewolTexture.h @@ -0,0 +1,39 @@ +/** + ******************************************************************************* + * @file ewolTexture.h + * @brief ewol Texture loading system (header) + * @author Edouard DUPIN + * @date 28/10/2011 + * @par Project + * ewol + * + * @par Copyright + * Copyright 2011 Edouard DUPIN, all right reserved + * + * This software is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY. + * + * Licence summary : + * You can modify and redistribute the sources code and binaries. + * You can send me the bug-fix + * + * Term of the licence in in the file licence.txt. + * + ******************************************************************************* + */ + +#ifndef __EWOL_TEXTURE_H__ +#define __EWOL_TEXTURE_H__ + +#include +#include +#include + +namespace ewol +{ + int32_t LoadTexture(etk::File & fileName); + void UnLoadTexture(int32_t textureID); +}; + +#endif + diff --git a/Sources/ewolWindows.cpp b/Sources/ewolWindows.cpp index 792a452b..dfde07d5 100644 --- a/Sources/ewolWindows.cpp +++ b/Sources/ewolWindows.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include @@ -58,6 +59,16 @@ bool ewol::Windows::OnEventInput(int32_t IdInput, eventInputType_te typeEvent, d +#include +#include +#include +#include +#if defined(EWOL_X11_MODE__XF86V) +# include +#elif defined(EWOL_X11_MODE__XRENDER) +# include +#endif + void ewol::Windows::SysDraw(void) { @@ -84,6 +95,7 @@ void ewol::Windows::SysDraw(void) //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA); //glBlendFunc(GL_SRC_ALPHA, GL_SRC_COLOR); + /* @@ -105,7 +117,12 @@ void ewol::Windows::SysDraw(void) static ewol::OObject2DColored myOObject; 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; if (false == isinit) { isinit=true; @@ -124,10 +141,131 @@ void ewol::Windows::SysDraw(void) 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.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); } - myOObject.Draw(); + 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); + } } diff --git a/data/exemple.eol b/dataTest/exemple.eol similarity index 100% rename from data/exemple.eol rename to dataTest/exemple.eol diff --git a/dataTest/test_16b_a1r5g5b5.bmp b/dataTest/test_16b_a1r5g5b5.bmp new file mode 100644 index 00000000..68b78667 Binary files /dev/null and b/dataTest/test_16b_a1r5g5b5.bmp differ diff --git a/dataTest/test_16b_r5g6b5.bmp b/dataTest/test_16b_r5g6b5.bmp new file mode 100644 index 00000000..7e0fac99 Binary files /dev/null and b/dataTest/test_16b_r5g6b5.bmp differ diff --git a/dataTest/test_16b_x1r5g5b5.bmp b/dataTest/test_16b_x1r5g5b5.bmp new file mode 100644 index 00000000..7c813a2f Binary files /dev/null and b/dataTest/test_16b_x1r5g5b5.bmp differ diff --git a/dataTest/test_24b_r8g8b8.bmp b/dataTest/test_24b_r8g8b8.bmp new file mode 100644 index 00000000..083fddde Binary files /dev/null and b/dataTest/test_24b_r8g8b8.bmp differ diff --git a/dataTest/test_32b_a8r8g8b8.bmp b/dataTest/test_32b_a8r8g8b8.bmp new file mode 100644 index 00000000..c08adada Binary files /dev/null and b/dataTest/test_32b_a8r8g8b8.bmp differ diff --git a/dataTest/test_32b_x8r8g8b8.bmp b/dataTest/test_32b_x8r8g8b8.bmp new file mode 100644 index 00000000..a270b672 Binary files /dev/null and b/dataTest/test_32b_x8r8g8b8.bmp differ