diff --git a/ege/resource/Mesh.cpp b/ege/resource/Mesh.cpp index 24c87f6..e786979 100644 --- a/ege/resource/Mesh.cpp +++ b/ege/resource/Mesh.cpp @@ -540,8 +540,8 @@ void ege::resource::Mesh::addTriangle(const std::string& _layerName, const vec3& return; } ewol::openGL::renderMode tmpRenderMode = m_materials[_layerName]->getRenderMode(); - if ( tmpRenderMode != ewol::openGL::renderQuad - || tmpRenderMode != ewol::openGL::renderQuadStrip) { + if ( tmpRenderMode == ewol::openGL::renderQuad + || tmpRenderMode == ewol::openGL::renderQuadStrip) { EGE_TODO("Create quad interface ..."); } else if ( tmpRenderMode == ewol::openGL::renderTriangle || tmpRenderMode == ewol::openGL::renderLineStrip diff --git a/ege/resource/Mesh.h b/ege/resource/Mesh.h index c4b61fb..2f4477b 100644 --- a/ege/resource/Mesh.h +++ b/ege/resource/Mesh.h @@ -34,6 +34,7 @@ namespace ege { class Mesh : public ewol::Resource { public: static std::shared_ptr createGrid(int32_t _lineCount, const vec3& _position=vec3(0,0,0), float _size=1.0f, const std::string& _materialName="basics"); + static std::shared_ptr createCube(float _size=1.0f, const std::string& _materialName="basics", const etk::Color& _color=etk::color::white); public: /** * @not-in-doc diff --git a/ege/resource/MeshCube.cpp b/ege/resource/MeshCube.cpp new file mode 100644 index 0000000..7ceb828 --- /dev/null +++ b/ege/resource/MeshCube.cpp @@ -0,0 +1,36 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2011, Edouard DUPIN, all right reserved + * + * @license BSD v3 (see license file) + */ + +#include +#include + +std::shared_ptr ege::resource::Mesh::createCube(float _size, const std::string& _materialName, const etk::Color& _color) { + std::shared_ptr out = ege::resource::Mesh::create("---", "DATA:color3.prog"); + if (out != nullptr) { + std::shared_ptr material = std::make_shared(); + // set the element material properties : + material->setAmbientFactor(vec4(1,1,1,1)); + material->setDiffuseFactor(vec4(0,0,0,1)); + material->setSpecularFactor(vec4(0,0,0,1)); + material->setShininess(1); + material->setRenderMode(ewol::openGL::renderTriangle); + out->addMaterial(_materialName, material); + + out->addFaceIndexing(_materialName); + + out->addQuad(_materialName, vec3(-1,-1,-1)*_size, vec3(-1, 1,-1)*_size, vec3( 1, 1,-1)*_size, vec3( 1,-1,-1)*_size, _color); + out->addQuad(_materialName, vec3(-1,-1, 1)*_size, vec3(-1, 1, 1)*_size, vec3( 1, 1, 1)*_size, vec3( 1,-1, 1)*_size, _color); + out->addQuad(_materialName, vec3(-1,-1,-1)*_size, vec3(-1,-1, 1)*_size, vec3(-1, 1, 1)*_size, vec3(-1, 1,-1)*_size, _color); + out->addQuad(_materialName, vec3( 1,-1,-1)*_size, vec3( 1,-1, 1)*_size, vec3( 1, 1, 1)*_size, vec3( 1, 1,-1)*_size, _color); + out->addQuad(_materialName, vec3(-1,-1,-1)*_size, vec3(-1,-1, 1)*_size, vec3( 1,-1, 1)*_size, vec3( 1,-1,-1)*_size, _color); + out->addQuad(_materialName, vec3(-1, 1,-1)*_size, vec3(-1, 1, 1)*_size, vec3( 1, 1, 1)*_size, vec3( 1, 1,-1)*_size, _color); + // generate the VBO + out->generateVBO(); + } + return out; +} \ No newline at end of file diff --git a/ege/resource/MeshGird.cpp b/ege/resource/MeshGird.cpp index 52c811c..25381c9 100644 --- a/ege/resource/MeshGird.cpp +++ b/ege/resource/MeshGird.cpp @@ -11,7 +11,6 @@ std::shared_ptr ege::resource::Mesh::createGrid(int32_t _lineCount, const vec3& _position, float _size, const std::string& _materialName) { std::shared_ptr out = ege::resource::Mesh::create("---", "DATA:color3.prog"); - float lineSize = 0.1f; if (out != nullptr) { std::shared_ptr material = std::make_shared(); // set the element material properties : diff --git a/lutin_ege.py b/lutin_ege.py index 6a44fa6..79a0c8d 100644 --- a/lutin_ege.py +++ b/lutin_ege.py @@ -32,6 +32,7 @@ def create(target): 'ege/resource/Mesh.cpp', 'ege/resource/MeshEmf.cpp', 'ege/resource/MeshGird.cpp', + 'ege/resource/MeshCube.cpp', 'ege/resource/MeshObj.cpp', 'ege/resource/ParticuleMesh.cpp', 'ege/resource/tools/icoSphere.cpp', diff --git a/sample/MeshCreator/appl/Windows.cpp b/sample/MeshCreator/appl/Windows.cpp index 646b9d1..9099572 100644 --- a/sample/MeshCreator/appl/Windows.cpp +++ b/sample/MeshCreator/appl/Windows.cpp @@ -24,15 +24,63 @@ appl::Windows::Windows() { addObjectType("appl::Windows"); } +static std::shared_ptr createViewBoxStar() { + std::shared_ptr out = ege::resource::Mesh::create("---", "DATA:texturedNoMaterial.prog"); + if (out != nullptr) { + std::shared_ptr material = std::make_shared(); + // set the element material properties : + material->setAmbientFactor(vec4(1,1,1,1)); + material->setDiffuseFactor(vec4(0,0,0,1)); + material->setSpecularFactor(vec4(0,0,0,1)); + material->setShininess(1); + material->setTexture0(""); //" + out->addMaterial("basics", material); + // 1024 == > 1<<9 + // 2048 == > 1<<10 + // 4096 == > 1<<11 + int32_t size = 1<<11; + material->setImageSize(ivec2(size,size)); + egami::Image* myImage = material->get(); + if (nullptr == myImage) { + return out; + } + myImage->clear(etk::color::black); + ivec2 tmpPos; + for (int32_t iii=0; iii<6000; iii++) { + tmpPos.setValue(etk::tool::frand(0,size), etk::tool::frand(0,size)) ; + myImage->set(tmpPos, etk::color::white); + } + material->flush(); + // basis on cube : + out->createViewBox("basics", 1000/* distance */); + // generate the VBO + out->generateVBO(); + } + return out; +} - - +static std::shared_ptr createMars() { + std::shared_ptr out = ege::resource::Mesh::create("---"); + if (out != nullptr) { + std::shared_ptr material = std::make_shared(); + material->setAmbientFactor(vec4(0.112f,0.112f,0.112f,1.0f)); + material->setDiffuseFactor(vec4(0.512f,0.512f,0.512f,1.0f)); + material->setSpecularFactor(vec4(0.5f,0.5f,0.5f,1.0f)); + material->setShininess(96.078431f); + material->setTexture0("DATA:texture_mars.png"); + out->addMaterial("basics", material); + out->createIcoSphere("basics", 16, 3); + out->generateVBO(); + //m_env->addStaticMeshToDraw(myMesh); + } + return out; +} void appl::Windows::init() { ewol::widget::Windows::init(); setTitle("example ege : MeshCreator"); - getObjectManager().periodicCall.bind(shared_from_this(), &appl::Windows::onCallbackPeriodicUpdateCamera); + //getObjectManager().periodicCall.bind(shared_from_this(), &appl::Windows::onCallbackPeriodicUpdateCamera); m_env = ege::Environement::create(); // Create basic Camera @@ -49,73 +97,33 @@ void appl::Windows::init() { setSubWidget(tmpWidget); } // Create an external box : - std::shared_ptr myMesh = ege::resource::Mesh::create("---", "DATA:texturedNoMaterial.prog"); + std::shared_ptr myMesh = createViewBoxStar(); if (myMesh != nullptr) { - std::shared_ptr material = std::make_shared(); - // set the element material properties : - material->setAmbientFactor(vec4(1,1,1,1)); - material->setDiffuseFactor(vec4(0,0,0,1)); - material->setSpecularFactor(vec4(0,0,0,1)); - material->setShininess(1); - material->setTexture0(""); //" - myMesh->addMaterial("basics", material); - // 1024 == > 1<<9 - // 2048 == > 1<<10 - // 4096 == > 1<<11 - int32_t size = 1<<11; - material->setImageSize(ivec2(size,size)); - egami::Image* myImage = material->get(); - if (nullptr == myImage) { - return; - } - myImage->clear(etk::color::black); - ivec2 tmpPos; - for (int32_t iii=0; iii<6000; iii++) { - tmpPos.setValue(etk::tool::frand(0,size), etk::tool::frand(0,size)) ; - myImage->set(tmpPos, etk::color::white); - } - material->flush(); - // basis on cube : - myMesh->createViewBox("basics", 1000/* distance */); - // generate the VBO - myMesh->generateVBO(); m_env->addStaticMeshToDraw(myMesh); } - myMesh = ege::resource::Mesh::createGrid(10, vec3(0,0,0), 5); + myMesh = createGrid(10, vec3(0,0,0), 5); if (myMesh != nullptr) { m_env->addStaticMeshToDraw(myMesh); } if (true) { myMesh = ege::resource::Mesh::create("---"); if (myMesh != nullptr) { - std::shared_ptr material = std::make_shared(); - material->setAmbientFactor(vec4(0.112f,0.112f,0.112f,1.0f)); - material->setDiffuseFactor(vec4(0.512f,0.512f,0.512f,1.0f)); - material->setSpecularFactor(vec4(0.5f,0.5f,0.5f,1.0f)); - material->setShininess(96.078431f); - material->setTexture0("DATA:texture_mars.png"); - myMesh->addMaterial("basics", material); - myMesh->createIcoSphere("basics", 16, 3); - myMesh->generateVBO(); std::shared_ptr element = std::make_shared(m_env); //std::shared_ptr element = std::make_shared(m_env); element->setPosition(vec3(50,0,0)); element->setMesh(myMesh); m_env->addElement(element); - //m_env->addStaticMeshToDraw(myMesh); } } } void appl::Windows::onCallbackPeriodicUpdateCamera(const ewol::event::Time& _event) { - /* static float offset = 0; offset += 0.01; static float offset2 = 0; offset2 += 0.003; m_camera->setEye(vec3(100*std::sin(offset),100*std::cos(offset),40*std::cos(offset2))+vec3(50,0,0)); - */ } diff --git a/sample/RayTest/README.md b/sample/RayTest/README.md new file mode 100644 index 0000000..8db39b2 --- /dev/null +++ b/sample/RayTest/README.md @@ -0,0 +1 @@ +Camera position sample example \ No newline at end of file diff --git a/sample/RayTest/appl/Windows.cpp b/sample/RayTest/appl/Windows.cpp new file mode 100644 index 0000000..df0cfd3 --- /dev/null +++ b/sample/RayTest/appl/Windows.cpp @@ -0,0 +1,109 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#undef __class__ +#define __class__ "Windows" + +appl::Windows::Windows() { + addObjectType("appl::Windows"); +} + +static std::shared_ptr createViewBoxStar() { + std::shared_ptr out = ege::resource::Mesh::create("---", "DATA:texturedNoMaterial.prog"); + if (out != nullptr) { + std::shared_ptr material = std::make_shared(); + // set the element material properties : + material->setAmbientFactor(vec4(1,1,1,1)); + material->setDiffuseFactor(vec4(0,0,0,1)); + material->setSpecularFactor(vec4(0,0,0,1)); + material->setShininess(1); + material->setTexture0(""); //" + out->addMaterial("basics", material); + // 1024 == > 1<<9 + // 2048 == > 1<<10 + // 4096 == > 1<<11 + int32_t size = 1<<11; + material->setImageSize(ivec2(size,size)); + egami::Image* myImage = material->get(); + if (nullptr == myImage) { + return out; + } + myImage->clear(etk::color::black); + ivec2 tmpPos; + for (int32_t iii=0; iii<6000; iii++) { + tmpPos.setValue(etk::tool::frand(0,size), etk::tool::frand(0,size)) ; + myImage->set(tmpPos, etk::color::white); + } + material->flush(); + // basis on cube : + out->createViewBox("basics", 1000/* distance */); + // generate the VBO + out->generateVBO(); + } + return out; +} + + +void appl::Windows::init() { + ewol::widget::Windows::init(); + setTitle("example ege : RayTest"); + + getObjectManager().periodicCall.bind(shared_from_this(), &appl::Windows::onCallbackPeriodicUpdateCamera); + + m_env = ege::Environement::create(); + // Create basic Camera + m_camera = std::make_shared(vec3(30,30,-100), vec3(0,0,0)); + m_env->addCamera("basic", m_camera); + + std::shared_ptr tmpWidget = ege::widget::Scene::create(m_env); + if (tmpWidget == nullptr) { + APPL_ERROR("Can not allocate widget ==> display might be in error"); + } else { + tmpWidget->setExpand(bvec2(true,true)); + tmpWidget->setFill(bvec2(true,true)); + tmpWidget->setCamera("basic"); + setSubWidget(tmpWidget); + } + + // Create an external box : + std::shared_ptr myMesh = createViewBoxStar(); + if (myMesh != nullptr) { + m_env->addStaticMeshToDraw(myMesh); + } + // create basic gird: + myMesh = ege::resource::Mesh::createGrid(10, vec3(0,0,0), 5); + if (myMesh != nullptr) { + m_env->addStaticMeshToDraw(myMesh); + } + myMesh = ege::resource::Mesh::createCube(3); + if (myMesh != nullptr) { + m_env->addStaticMeshToDraw(myMesh); + } +} + + +void appl::Windows::onCallbackPeriodicUpdateCamera(const ewol::event::Time& _event) { + static float offset = 0; + offset += 0.01; + static float offset2 = 0; + offset2 += 0.003; + m_camera->setEye(vec3(100*std::sin(offset),100*std::cos(offset),40*std::cos(offset2))); +} + + diff --git a/sample/RayTest/appl/Windows.h b/sample/RayTest/appl/Windows.h new file mode 100644 index 0000000..2e1c631 --- /dev/null +++ b/sample/RayTest/appl/Windows.h @@ -0,0 +1,33 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#ifndef __APPL_WINDOWS_H__ +#define __APPL_WINDOWS_H__ + +#include +#include +#include + +namespace appl { + class Windows : public ewol::widget::Windows { + private: + std::shared_ptr m_env; + std::shared_ptr m_camera; + protected: + Windows(); + void init(); + public: + DECLARE_FACTORY(Windows); + virtual ~Windows() { }; + private: + void onCallbackPeriodicUpdateCamera(const ewol::event::Time& _event); + }; +}; + + +#endif \ No newline at end of file diff --git a/sample/RayTest/appl/debug.cpp b/sample/RayTest/appl/debug.cpp new file mode 100644 index 0000000..07299b6 --- /dev/null +++ b/sample/RayTest/appl/debug.cpp @@ -0,0 +1,15 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + + +#include + +int32_t appl::getLogId() { + static int32_t g_val = etk::log::registerInstance("GP-spaceShip"); + return g_val; +} diff --git a/sample/RayTest/appl/debug.h b/sample/RayTest/appl/debug.h new file mode 100644 index 0000000..8036fb5 --- /dev/null +++ b/sample/RayTest/appl/debug.h @@ -0,0 +1,52 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + + +#ifndef __APPL_DEBUG_H__ +#define __APPL_DEBUG_H__ + +#include + +namespace appl { + int32_t getLogId(); +}; +// TODO : Review this problem of multiple intanciation of "std::stringbuf sb" +#define APPL_BASE(info,data) \ + do { \ + if (info <= etk::log::getLevel(appl::getLogId())) { \ + std::stringbuf sb; \ + std::ostream tmpStream(&sb); \ + tmpStream << data; \ + etk::log::logStream(appl::getLogId(), info, __LINE__, __class__, __func__, tmpStream); \ + } \ + } while(0) + +#define APPL_CRITICAL(data) APPL_BASE(1, data) +#define APPL_ERROR(data) APPL_BASE(2, data) +#define APPL_WARNING(data) APPL_BASE(3, data) +#ifdef DEBUG + #define APPL_INFO(data) APPL_BASE(4, data) + #define APPL_DEBUG(data) APPL_BASE(5, data) + #define APPL_VERBOSE(data) APPL_BASE(6, data) + #define APPL_TODO(data) APPL_BASE(4, "TODO : " << data) +#else + #define APPL_INFO(data) do { } while(false) + #define APPL_DEBUG(data) do { } while(false) + #define APPL_VERBOSE(data) do { } while(false) + #define APPL_TODO(data) do { } while(false) +#endif + +#define APPL_ASSERT(cond,data) \ + do { \ + if (!(cond)) { \ + APPL_CRITICAL(data); \ + assert(!#cond); \ + } \ + } while (0) + +#endif diff --git a/sample/RayTest/appl/main.cpp b/sample/RayTest/appl/main.cpp new file mode 100644 index 0000000..ba5e841 --- /dev/null +++ b/sample/RayTest/appl/main.cpp @@ -0,0 +1,57 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + + +#include +#include +#include + +#include +#include +#include +#include +#include + + +class MainApplication : public ewol::context::Application { + public: + bool init(ewol::Context& _context, size_t _initId) { + APPL_INFO("==> Init APPL (START) [" << ewol::getBoardType() << "] (" << ewol::getCompilationMode() << ")"); + + // TODO : Remove this : Move if in the windows properties + _context.setSize(vec2(800, 600)); + + // select internal data for font ... + _context.getFontDefault().setUseExternal(true); + _context.getFontDefault().set("FreeSerif;DejaVuSansMono", 19); + + std::shared_ptr basicWindows = appl::Windows::create(); + // create the specific windows + _context.setWindows(basicWindows); + APPL_INFO("==> Init APPL (END)"); + return true; + } + + void unInit(ewol::Context& _context) { + APPL_INFO("==> Un-Init APPL (START)"); + // nothing to do ... + APPL_INFO("==> Un-Init APPL (END)"); + } +}; + +/** + * @brief Main of the program (This can be set in every case, but it is not used in Andoid...). + * @param std IO + * @return std IO + */ +int main(int _argc, const char *_argv[]) { + // second possibility + return ewol::run(new MainApplication(), _argc, _argv); +} + + diff --git a/sample/RayTest/appl/main.h b/sample/RayTest/appl/main.h new file mode 100644 index 0000000..caa7110 --- /dev/null +++ b/sample/RayTest/appl/main.h @@ -0,0 +1,14 @@ +/** + * @author Edouard DUPIN + * + * @copyright 2010, Edouard DUPIN, all right reserved + * + * @license APACHE-2 (see license file) + */ + +#ifndef __APPL_MAIN_H__ +#define __APPL_MAIN_H__ + + +#endif + diff --git a/sample/RayTest/data/texture_mars.png b/sample/RayTest/data/texture_mars.png new file mode 100644 index 0000000..8584cf8 Binary files /dev/null and b/sample/RayTest/data/texture_mars.png differ diff --git a/sample/RayTest/lutin_egeRayTest.py b/sample/RayTest/lutin_egeRayTest.py new file mode 100644 index 0000000..50665e1 --- /dev/null +++ b/sample/RayTest/lutin_egeRayTest.py @@ -0,0 +1,40 @@ +#!/usr/bin/python +import lutinModule as module +import lutinTools as tools +import lutinDebug as debug +import datetime + + +def get_desc(): + return "ege sample : RayTest" + +def create(target): + # module name is 'edn' and type binary. + myModule = module.Module(__file__, 'egeRayTest', 'PACKAGE') + + myModule.add_src_file([ + 'appl/debug.cpp', + 'appl/main.cpp', + 'appl/Windows.cpp' + ]) + + myModule.add_module_depend('ege') + + myModule.add_path(tools.get_current_path(__file__)) + + myModule.copy_folder("data/*") + + # set the package properties : + myModule.pkg_set("VERSION", "0.0.0") + myModule.pkg_set("VERSION_CODE", "0") + myModule.pkg_set("COMPAGNY_TYPE", "org") + myModule.pkg_set("COMPAGNY_NAME", "ege") + myModule.pkg_set("MAINTAINER", ["noOne "]) + myModule.pkg_set("SECTION", ["Game"]) + myModule.pkg_set("PRIORITY", "optional") + myModule.pkg_set("DESCRIPTION", "ege sample : Ray test") + myModule.pkg_set("NAME", "egeRayTest") + + # add the currrent module at the + return myModule +