diff --git a/external/etk b/external/etk index 28ffa0fb..fb13e03d 160000 --- a/external/etk +++ b/external/etk @@ -1 +1 @@ -Subproject commit 28ffa0fb754b2e9cdba86bf9d4bbfc35770fe70b +Subproject commit fb13e03dc913ccd56c27aef4c780e68e3b384b84 diff --git a/sources/ewol/compositing/Area.cpp b/sources/ewol/compositing/Area.cpp new file mode 100644 index 00000000..cec4bd97 --- /dev/null +++ b/sources/ewol/compositing/Area.cpp @@ -0,0 +1,166 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#include + +#include +#include +#include + +#undef __class__ +#define __class__ "ewol::Area" + +ewol::Area::Area(ivec2 size) : + m_position(0.0, 0.0, 0.0), + m_color(draw::color::white), + m_GLprogram(NULL), + m_GLPosition(-1), + m_GLMatrix(-1), + m_GLColor(-1), + m_GLtexture(-1), + m_GLtexID(-1), + m_resource(NULL) +{ + ewol::resource::Keep(m_resource); + m_resource->SetImageSize(size); + m_resource->Flush(); + LoadProgram(); +} + +ewol::Area::~Area(void) +{ + if (NULL != m_resource) { + ewol::resource::Release(m_resource); + m_resource = NULL; + } + ewol::resource::Release(m_GLprogram); +} + +void ewol::Area::LoadProgram(void) +{ + etk::UString tmpString("DATA:textured3D.prog"); + // get the shader resource : + m_GLPosition = 0; + if (true == ewol::resource::Keep(tmpString, m_GLprogram) ) { + m_GLPosition = m_GLprogram->GetAttribute("EW_coord3d"); + m_GLColor = m_GLprogram->GetAttribute("EW_color"); + m_GLtexture = m_GLprogram->GetAttribute("EW_texture2d"); + m_GLMatrix = m_GLprogram->GetUniform("EW_MatrixTransformation"); + m_GLtexID = m_GLprogram->GetUniform("EW_texID"); + } +} + +void ewol::Area::Draw(void) +{ + if (m_coord.Size()<=0) { + //EWOL_WARNING("Nothink to draw..."); + return; + } + if (m_resource == NULL) { + // this is a normale case ... the user can choice to have no image ... + return; + } + if (m_GLprogram==NULL) { + EWOL_ERROR("No shader ..."); + return; + } + // set Matrix : translation/positionMatrix + mat4 tmpMatrix = ewol::openGL::GetMatrix()*m_matrixApply; + m_GLprogram->Use(); + m_GLprogram->UniformMatrix4fv(m_GLMatrix, 1, tmpMatrix.m_mat); + // TextureID + m_GLprogram->SetTexture0(m_GLtexID, m_resource->GetId()); + // position : + m_GLprogram->SendAttribute(m_GLPosition, 3/*x,y,z,unused*/, &m_coord[0], 4*sizeof(btScalar)); + // Texture : + m_GLprogram->SendAttribute(m_GLtexture, 2/*u,v*/, &m_coordTex[0]); + // color : + m_GLprogram->SendAttribute(m_GLColor, 4/*r,g,b,a*/, &m_coordColor[0]); + // Request the draw od the elements : + glDrawArrays(GL_TRIANGLES, 0, m_coord.Size()); + m_GLprogram->UnUse(); +} + +void ewol::Area::Clear(void) +{ + // call upper class + ewol::Compositing::Clear(); + // Reset Buffer : + m_coord.Clear(); + m_coordTex.Clear(); + m_coordColor.Clear(); + // Reset temporal variables : + m_position = vec3(0.0, 0.0, 0.0); +} + + +vec3 ewol::Area::GetPos(void) +{ + return m_position; +} + + +void ewol::Area::SetPos(vec3 pos) +{ + m_position = pos; +} + + +void ewol::Area::SetRelPos(vec3 pos) +{ + m_position += pos; +} + + +void ewol::Area::Print(ivec2 size) +{ + vec3 point(0,0,0); + vec2 tex(0,1); + + point.setX(m_position.x()); + point.setY(m_position.y()); + m_coord.PushBack(point); + m_coordTex.PushBack(tex); + m_coordColor.PushBack(m_color); + + + tex.setValue(1,1); + point.setX(m_position.x() + size.x()); + point.setY(m_position.y()); + m_coord.PushBack(point); + m_coordTex.PushBack(tex); + m_coordColor.PushBack(m_color); + + + tex.setValue(1,0); + point.setX(m_position.x() + size.x()); + point.setY(m_position.y() + size.y()); + m_coord.PushBack(point); + m_coordTex.PushBack(tex); + m_coordColor.PushBack(m_color); + + m_coord.PushBack(point); + m_coordTex.PushBack(tex); + m_coordColor.PushBack(m_color); + + tex.setValue(0,0); + point.setX(m_position.x()); + point.setY(m_position.y() + size.y()); + m_coord.PushBack(point); + m_coordTex.PushBack(tex); + m_coordColor.PushBack(m_color); + + tex.setValue(0,1); + point.setX(m_position.x()); + point.setY(m_position.y()); + m_coord.PushBack(point); + m_coordTex.PushBack(tex); + m_coordColor.PushBack(m_color); +} + + diff --git a/sources/ewol/compositing/Area.h b/sources/ewol/compositing/Area.h new file mode 100644 index 00000000..14116b88 --- /dev/null +++ b/sources/ewol/compositing/Area.h @@ -0,0 +1,87 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#ifndef __EWOL_COMPOSITING_AREA_H__ +#define __EWOL_COMPOSITING_AREA_H__ + +#include +#include +#include + +namespace ewol +{ + class Area : public ewol::Compositing + { + private: + vec3 m_position; //!< The current position to draw + draw::Color m_color; //!< The text foreground color + private: + ewol::Program* m_GLprogram; //!< pointer on the opengl display program + int32_t m_GLPosition; //!< openGL id on the element (vertex buffer) + int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix) + int32_t m_GLColor; //!< openGL id on the element (color buffer) + int32_t m_GLtexture; //!< openGL id on the element (Texture position) + int32_t m_GLtexID; //!< openGL id on the element (texture ID) + private: + ewol::Texture* m_resource; //!< texture resources + etk::Vector m_coord; //!< internal coord of the object + etk::Vector m_coordTex; //!< internal texture coordinate for every point + etk::Vector m_coordColor; //!< internal color of the different point + private: + /** + * @brief Load the openGL program and get all the ID needed + */ + void LoadProgram(void); + public: + /** + * @brief generic constructor + * @param[in] imageName Name of the file that might be loaded + */ + Area(ivec2 size); + /** + * @brief generic destructor + */ + ~Area(void); + public: + /** + * @brief Draw All the refistered text in the current element on openGL + */ + void Draw(void); + /** + * @brief Clear alll tre registered element in the current element + */ + void Clear(void); + /** + * @brief Get the current display position (sometime needed in the gui control) + * @return the current position. + */ + vec3 GetPos(void); + /** + * @brief Set position for the next text writen + * @param[in] pos Position of the text (in 3D) + */ + void SetPos(vec3 pos); + /** + * @brief Set relative position for the next text writen + * @param[in] pos ofset apply of the text (in 3D) + */ + void SetRelPos(vec3 pos); + /** + * @brief Add a compleate of the image to display with the requested size + * @param[in] size Size of the output image + */ + void Print(ivec2 size); + + draw::Image& Get(void) { return m_resource->Get(); }; + void Flush(void) { m_resource->Flush(); }; + + }; +}; + +#endif + diff --git a/sources/ewol/compositing/Image.h b/sources/ewol/compositing/Image.h index cf1aabbc..5b60c364 100644 --- a/sources/ewol/compositing/Image.h +++ b/sources/ewol/compositing/Image.h @@ -18,27 +18,26 @@ namespace ewol class Image : public ewol::Compositing { private: + vec3 m_position; //!< The current position to draw + vec3 m_clippingPosStart; //!< Clipping start position + vec3 m_clippingPosStop; //!< Clipping stop position + bool m_clippingEnable; //!< true if the clipping must be activated private: - vec3 m_position; //!< The current position to draw - vec3 m_clippingPosStart; //!< Clipping start position - vec3 m_clippingPosStop; //!< Clipping stop position - bool m_clippingEnable; //!< true if the clipping must be activated + draw::Color m_color; //!< The text foreground color + vec3 m_axes; //!< Rotation axes (instant) + float m_angle; //!< Angle to set at the axes private: - draw::Color m_color; //!< The text foreground color - vec3 m_axes; //!< Rotation axes (instant) - float m_angle; //!< Angle to set at the axes + ewol::Program* m_GLprogram; //!< pointer on the opengl display program + int32_t m_GLPosition; //!< openGL id on the element (vertex buffer) + int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix) + int32_t m_GLColor; //!< openGL id on the element (color buffer) + int32_t m_GLtexture; //!< openGL id on the element (Texture position) + int32_t m_GLtexID; //!< openGL id on the element (texture ID) private: - ewol::Program* m_GLprogram; //!< pointer on the opengl display program - int32_t m_GLPosition; //!< openGL id on the element (vertex buffer) - int32_t m_GLMatrix; //!< openGL id on the element (transformation matrix) - int32_t m_GLColor; //!< openGL id on the element (color buffer) - int32_t m_GLtexture; //!< openGL id on the element (Texture position) - int32_t m_GLtexID; //!< openGL id on the element (texture ID) - private: - ewol::TextureFile* m_resource; //!< texture resources - etk::Vector m_coord; //!< internal coord of the object - etk::Vector m_coordTex; //!< internal texture coordinate for every point - etk::Vector m_coordColor; //!< internal color of the different point + ewol::TextureFile* m_resource; //!< texture resources + etk::Vector m_coord; //!< internal coord of the object + etk::Vector m_coordTex; //!< internal texture coordinate for every point + etk::Vector m_coordColor; //!< internal color of the different point private: /** * @brief Load the openGL program and get all the ID needed diff --git a/sources/ewol/renderer/resources/Texture.cpp b/sources/ewol/renderer/resources/Texture.cpp index 3e907b1b..aabdc0af 100644 --- a/sources/ewol/renderer/resources/Texture.cpp +++ b/sources/ewol/renderer/resources/Texture.cpp @@ -57,32 +57,31 @@ void ewol::Texture::UpdateContext(void) if (false == m_loaded) { // Request a new texture at OpenGl : glGenTextures(1, &m_texId); - // TODO : check error ??? - glBindTexture(GL_TEXTURE_2D, m_texId); - // TODO : Check error ??? - //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); - EWOL_INFO("TEXTURE: Add [" << m_uniqueId << "]=" << m_data.GetSize() << " OGl_Id=" <