Created
October 8, 2014 08:44
Ogre 1.10.x Test for Emscripten
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
emsc: | |
em++ ogre_test.cpp -I/usr/ogre/OgreMain/include/ -I/usr/ogre/build/include/ -I/usr/ogre/RenderSystems/GLES2/include/ -I/usr/ogre/PlugIns/OctreeSceneManager/include/ -I/usr/ogre/Components/RTShaderSystem/include/ -o ogre_test.bc -Werror | |
em++ ogre_test.bc /usr/ogre/build_static/lib/libRenderSystem_GLES2Static.a /usr/ogre/build_static/lib/libPlugin_OctreeSceneManagerStatic.a /usr/ogre/build_static/lib/libOgreRTShaderSystemStatic.a /usr/ogre/build_static/lib/libOgreMainStatic.a -o ogre.html --preload-file assets/plugins.cfg --preload-file assets/media/models/ogrehead.mesh --preload-file assets/media/materials/scripts/Ogre.material --preload-file assets/media/materials/scripts/cool.frag --preload-file assets/media/materials/scripts/cool.vs | |
native: | |
g++ -L/usr/lib/x86_64-linux-gnu/ -lfreeimage -lpthread -lX11 -lXt -lXmu -lXaw -lm -lGL -lGLU -lXrandr ogre_test.cpp -I/usr/ogre/OgreMain/include/ -I/usr/ogre/build/include/ -I/usr/ogre/RenderSystems/GL/include/ -I/usr/ogre/PlugIns/OctreeSceneManager/include/ -I/usr/ogre/Components/RTShaderSystem/include/ /usr/ogre/build_native/lib/libRenderSystem_GLStatic.a /usr/ogre/build_native/lib/libPlugin_OctreeSceneManagerStatic.a /usr/ogre/build_native/lib/libOgreRTShaderSystemStatic.a /usr/ogre/build_native/lib/libOgreMainStatic.a -o ogre.a -fpermissive | |
all: emsc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Ogre.h> | |
#ifdef EMSCRIPTEN | |
#include <OgreGLES2Plugin.h> | |
#include <EGL/egl.h> | |
#else | |
#include <OgreGLPlugin.h> | |
#endif | |
#include <OgreOctreePlugin.h> | |
#include <OgreRTShaderSystem.h> | |
#include <stdio.h> | |
using namespace Ogre; | |
Root* root = 0; | |
RenderWindow *window = 0; | |
void render_loop_cb() | |
{ | |
window->update(false); | |
window->swapBuffers(); | |
root->renderOneFrame(); | |
Ogre::WindowEventUtilities::messagePump(); | |
} | |
int main() | |
{ | |
// create a ogre root, | |
root = new Root( "assets/plugins.cfg", "assets/ogre.cfg", "ogre.log" ); | |
// load and install plugins here manually, since we are using a static build of ogre | |
// we need to be using GLES2 under emscripten | |
#ifdef EMSCRIPTEN | |
Ogre::GLES2Plugin *mGLPlugin = new Ogre::GLES2Plugin(); | |
#else | |
Ogre::GLPlugin *mGLPlugin = new Ogre::GLPlugin(); | |
#endif | |
Ogre::OctreePlugin* mOCPlugin = new Ogre::OctreePlugin(); | |
mGLPlugin->install(); | |
mOCPlugin->install(); | |
// pick the first available render system | |
RenderSystem *renderSystem; | |
const RenderSystemList renderers = root->getAvailableRenderers(); | |
// early exit if we didn't get a render system | |
if(renderers.empty()) | |
{ | |
printf("ERROR: No renderers are available.\n"); | |
return -1; | |
} | |
renderSystem = *(renderers.begin()); | |
Root::getSingleton().setRenderSystem(renderSystem); | |
renderSystem->setConfigOption("Video Mode", "640 x 480"); | |
// the dependency tracking for emscripten seems to be missing | |
// that we are using EGL unless we explicitly use egl-functions here | |
#ifdef EMSCRIPTEN | |
printf( "fake-usage of egl: %X\n", (unsigned int) eglGetProcAddress("glClear") ); | |
#endif | |
// this method can only be called after a renderer has been selected with Root::setRenderSystem | |
root->initialise(true, "Hello World!"); | |
// resource handling | |
ResourceGroupManager::getSingleton().addResourceLocation( "assets/media/models", "FileSystem"); | |
ResourceGroupManager::getSingleton().addResourceLocation( "assets/media/materials/scripts", "FileSystem"); | |
ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); | |
// scene management | |
SceneManager *smgr = root->createSceneManager( ST_GENERIC, "DefaultSceneManager"); | |
smgr->setAmbientLight(Ogre::ColourValue(0.5f, 0.5f, 0.5f)); // set ambient light for the scene | |
// Create an mesh entity and add it to the scene | |
Ogre::Entity* ogreHead = smgr->createEntity("Head", "ogrehead.mesh"); | |
Ogre::SceneNode* headNode = smgr->getRootSceneNode()->createChildSceneNode("HeadNode"); | |
headNode->attachObject(ogreHead); | |
headNode->translate( 0,0,-200.0f ); | |
// Create a Light attach it as a child to the mesh head | |
Ogre::Light* light = smgr->createLight("MainLight"); | |
light->setType(Ogre::Light::LT_DIRECTIONAL); | |
light->setDiffuseColour(ColourValue(0.5, 0.5, 0.5)); | |
light->setSpecularColour(ColourValue(0.5, 0.5, 0.5)); | |
light->setDirection(Ogre::Vector3(-1, 0.0, -1.0)); | |
headNode->attachObject( light ); | |
// setup a camera and viewport | |
Camera *cam = smgr->createCamera("MainCamera"); | |
window = root->getAutoCreatedWindow(); | |
Viewport *vp = window->addViewport(cam); | |
vp->setBackgroundColour(ColourValue(0.3, 0.6, 0.9)); | |
// enter the main render loop | |
#ifdef EMSCRIPTEN | |
emscripten_set_main_loop( render_loop_cb, 0, 1 ); | |
#else | |
while(1) | |
{ | |
render_loop_cb(); | |
} | |
#endif | |
delete root; | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment