Add experimental emscripten port. Thanks @labsin for the patch.
Note: To compile on Linux you currently have to enable the line with: //#define _IRR_LINUX_PLATFORM_ //Hack in IrrCompileConfig.h (will try to find another solution later, but currently working on Windows) Not yet tested at all on Windows. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@5406 dfc29bdd-3216-0410-991c-e03cc46cb475master
parent
dd6a7ddc71
commit
55040b8c57
|
@ -0,0 +1,68 @@
|
|||
# Makefile for Irrlicht Examples
|
||||
# It's usually sufficient to change just the target name and source file list
|
||||
# and be sure that CXX is set to a valid compiler
|
||||
|
||||
# Name of the executable created (.exe will be added automatically if necessary)
|
||||
Target := 01.HelloWorld
|
||||
# List of source files, separated by spaces
|
||||
Sources := main.cpp
|
||||
# Path to Irrlicht directory, should contain include/ and lib/
|
||||
IrrlichtHome := ../..
|
||||
# Path for the executable. Note that Irrlicht.dll should usually also be there for win32 systems
|
||||
BinPath = ../../bin/$(SYSTEM)
|
||||
|
||||
all_emscripten: EMSCRIPTEN=1
|
||||
|
||||
# general compiler settings (might need to be set when compiling the lib, too)
|
||||
CPPFLAGS += -I$(IrrlichtHome)/include -I/usr/X11R6/include
|
||||
ifndef NDEBUG
|
||||
ifdef EMSCRIPTEN
|
||||
LDFLAGS += -s DEMANGLE_SUPPORT=1
|
||||
endif
|
||||
CXXFLAGS += -g -Wall
|
||||
else
|
||||
ifdef EMSCRIPTEN
|
||||
LDFLAGS += -O3
|
||||
endif
|
||||
CXXFLAGS += -O3
|
||||
endif
|
||||
|
||||
#default target is Linux
|
||||
all: all_linux
|
||||
|
||||
# target specific settings
|
||||
ll_linux all_emscripten all_win32 static_win32: LDFLAGS += -L$(IrrlichtHome)/lib/$(SYSTEM) -lIrrlicht
|
||||
all_linux: LDFLAGS += -L/usr/X11R6/lib$(LIBSELECT) -lGL -lEGL -lGLESv1_CM -lGLESv2 -lXxf86vm -lXext -lX11 -lXcursor
|
||||
all_linux clean_linux: SYSTEM=Linux
|
||||
all_emscripten clean_emscripten: SYSTEM=emscripten
|
||||
all_win32 clean_win32 static_win32: SYSTEM=Win32-gcc
|
||||
all_win32 clean_win32 static_win32: SUF=.exe
|
||||
all_emscripten clean_emscripten: SUF=.html
|
||||
all_emscripten: CXXFLAGS += -fno-exceptions -fno-rtti -fstrict-aliasing -std=gnu++11 -U__STRICT_ANSI__
|
||||
all_emscripten: LDFLAGS += -lGLESv2 -s FULL_ES2=1 -lSDL --preload-file ../../media@/media -s ALLOW_MEMORY_GROWTH=1
|
||||
static_win32: CPPFLAGS += -D_IRR_STATIC_LIB_
|
||||
all_win32: LDFLAGS += -lopengl32 -lEGL -lGLESv1_CM -lGLESv2 -lm
|
||||
static_win32: LDFLAGS += -lgdi32 -lwinspool -lcomdlg32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 -lopengl32 -lEGL -lGLESv1_CM -lGLESv2
|
||||
# name of the binary - only valid for targets which set SYSTEM
|
||||
DESTPATH = $(BinPath)/$(Target)$(SUF)
|
||||
|
||||
all_linux all_win32 all_emscripten static_win32:
|
||||
$(warning Building...)
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(Sources) -o $(DESTPATH) $(LDFLAGS)
|
||||
|
||||
clean: clean_linux clean_win32 clean_emscripten
|
||||
$(warning Cleaning...)
|
||||
|
||||
clean_linux clean_win32 clean_emscripten:
|
||||
@$(RM) $(DESTPATH)
|
||||
|
||||
.PHONY: all all_win32 all_emscripten static_win32 clean clean_linux clean_win32 clean_emscripten
|
||||
|
||||
#multilib handling
|
||||
ifeq ($(HOSTTYPE), x86_64)
|
||||
LIBSELECT=64
|
||||
endif
|
||||
#solaris real-time features
|
||||
ifeq ($(HOSTTYPE), sun4)
|
||||
LDFLAGS += -lrt
|
||||
endif
|
|
@ -0,0 +1,279 @@
|
|||
/** Example 001 HelloWorld
|
||||
|
||||
This Tutorial shows how to set up the IDE for using the Irrlicht Engine and how
|
||||
to write a simple HelloWorld program with it. The program will show how to use
|
||||
the basics of the VideoDriver, the GUIEnvironment, and the SceneManager.
|
||||
Microsoft Visual Studio is used as an IDE, but you will also be able to
|
||||
understand everything if you are using a different one or even another
|
||||
operating system than windows.
|
||||
|
||||
You have to include the header file <irrlicht.h> in order to use the engine. The
|
||||
header file can be found in the Irrlicht Engine SDK directory \c include. To let
|
||||
the compiler find this header file, the directory where it is located has to be
|
||||
specified. This is different for every IDE and compiler you use. Let's explain
|
||||
shortly how to do this in Microsoft Visual Studio:
|
||||
|
||||
- If you use Version 6.0, select the Menu Extras -> Options.
|
||||
Select the directories tab, and select the 'Include' Item in the combo box.
|
||||
Add the \c include directory of the irrlicht engine folder to the list of
|
||||
directories. Now the compiler will find the Irrlicht.h header file. We also
|
||||
need the irrlicht.lib to be found, so stay in that dialog, select 'Libraries'
|
||||
in the combo box and add the \c lib/VisualStudio directory.
|
||||
\image html "vc6optionsdir.jpg"
|
||||
\image latex "vc6optionsdir.jpg"
|
||||
\image html "vc6include.jpg"
|
||||
\image latex "vc6include.jpg"
|
||||
|
||||
- If your IDE is Visual Studio .NET, select Tools -> Options.
|
||||
Select the projects entry and then select VC++ directories. Select 'show
|
||||
directories for include files' in the combo box, and add the \c include
|
||||
directory of the irrlicht engine folder to the list of directories. Now the
|
||||
compiler will find the Irrlicht.h header file. We also need the irrlicht.lib
|
||||
to be found, so stay in that dialog, select 'show directories for Library
|
||||
files' and add the \c lib/VisualStudio directory.
|
||||
\image html "vcnetinclude.jpg"
|
||||
\image latex "vcnetinclude.jpg"
|
||||
|
||||
That's it. With your IDE set up like this, you will now be able to develop
|
||||
applications with the Irrlicht Engine.
|
||||
|
||||
Lets start!
|
||||
|
||||
After we have set up the IDE, the compiler will know where to find the Irrlicht
|
||||
Engine header files so we can include it now in our code.
|
||||
*/
|
||||
#include <irrlicht.h>
|
||||
#include "exampleHelper.h"
|
||||
#include <emscripten.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
In the Irrlicht Engine, everything can be found in the namespace 'irr'. So if
|
||||
you want to use a class of the engine, you have to write irr:: before the name
|
||||
of the class. For example to use the IrrlichtDevice write: irr::IrrlichtDevice.
|
||||
To get rid of the irr:: in front of the name of every class, we tell the
|
||||
compiler that we use that namespace from now on, and we will not have to write
|
||||
irr:: anymore.
|
||||
*/
|
||||
using namespace irr;
|
||||
|
||||
/*
|
||||
There are 5 sub namespaces in the Irrlicht Engine. Take a look at them, you can
|
||||
read a detailed description of them in the documentation by clicking on the top
|
||||
menu item 'Namespace List' or by using this link:
|
||||
http://irrlicht.sourceforge.net/docu/namespaces.html
|
||||
Like the irr namespace, we do not want these 5 sub namespaces now, to keep this
|
||||
example simple. Hence, we tell the compiler again that we do not want always to
|
||||
write their names.
|
||||
*/
|
||||
using namespace core;
|
||||
using namespace scene;
|
||||
using namespace video;
|
||||
using namespace io;
|
||||
using namespace gui;
|
||||
|
||||
/*
|
||||
To be able to use the Irrlicht.DLL file, we need to link with the Irrlicht.lib.
|
||||
We could set this option in the project settings, but to make it easy, we use a
|
||||
pragma comment lib for VisualStudio. On Windows platforms, we have to get rid
|
||||
of the console window, which pops up when starting a program with main(). This
|
||||
is done by the second pragma. We could also use the WinMain method, though
|
||||
losing platform independence then.
|
||||
*/
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment(lib, "Irrlicht.lib")
|
||||
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
|
||||
#endif
|
||||
|
||||
IrrlichtDevice *device = 0;
|
||||
IVideoDriver* driver = 0;
|
||||
ISceneManager* smgr = 0;
|
||||
IGUIEnvironment* guienv = 0;
|
||||
|
||||
/*
|
||||
emscripten can't run things in an endless-loop or otherwise the browse will consider
|
||||
the script to hang.
|
||||
*/
|
||||
#ifdef __EMSCRIPTEN__
|
||||
void one_iter()
|
||||
{
|
||||
if(!device->run())
|
||||
{
|
||||
//emscripten_cancel_main_loop();
|
||||
return;
|
||||
}
|
||||
driver->beginScene(ECBF_COLOR | ECBF_DEPTH, SColor(255,100,101,140));
|
||||
|
||||
smgr->drawAll();
|
||||
guienv->drawAll();
|
||||
|
||||
driver->endScene();
|
||||
}
|
||||
#endif //__EMSCRIPTEN__
|
||||
|
||||
|
||||
/*
|
||||
This is the main method. We can now use main() on every platform.
|
||||
*/
|
||||
int main()
|
||||
{
|
||||
/*
|
||||
The most important function of the engine is the createDevice()
|
||||
function. The IrrlichtDevice is created by it, which is the root
|
||||
object for doing anything with the engine. createDevice() has 7
|
||||
parameters:
|
||||
|
||||
- deviceType: Type of the device. This can currently be the Null-device,
|
||||
one of the two software renderers, D3D9, or OpenGL. In this
|
||||
example we use EDT_SOFTWARE, but to try out, you might want to
|
||||
change it to EDT_BURNINGSVIDEO, EDT_NULL, EDT_DIRECT3D9, or EDT_OPENGL.
|
||||
|
||||
- windowSize: Size of the Window or screen in FullScreenMode to be
|
||||
created. In this example we use 640x480.
|
||||
|
||||
- bits: Amount of color bits per pixel. This should be 16 or 32. The
|
||||
parameter is often ignored when running in windowed mode.
|
||||
|
||||
- fullscreen: Specifies if we want the device to run in fullscreen mode
|
||||
or not.
|
||||
|
||||
- stencilbuffer: Specifies if we want to use the stencil buffer (for
|
||||
drawing shadows).
|
||||
|
||||
- vsync: Specifies if we want to have vsync enabled, this is only useful
|
||||
in fullscreen mode.
|
||||
|
||||
- eventReceiver: An object to receive events. We do not want to use this
|
||||
parameter here, and set it to 0.
|
||||
|
||||
Always check the return value to cope with unsupported drivers,
|
||||
dimensions, etc.
|
||||
*/
|
||||
#ifndef __EMSCRIPTEN__
|
||||
device =
|
||||
createDevice( video::EDT_OGLES1, dimension2d<u32>(640, 480), 16,
|
||||
false, false, false, 0);
|
||||
#else //__EMSCRIPTEN__
|
||||
device =
|
||||
createDevice(video::EDT_OGLES2, dimension2d<u32>(640, 480), 16,
|
||||
false, false, false, 0);
|
||||
+#endif //__EMSCRIPTEN__
|
||||
|
||||
if (!device)
|
||||
return 1;
|
||||
|
||||
/*
|
||||
Set the caption of the window to some nice text. Note that there is an
|
||||
'L' in front of the string. The Irrlicht Engine uses wide character
|
||||
strings when displaying text.
|
||||
*/
|
||||
device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");
|
||||
|
||||
/*
|
||||
Get a pointer to the VideoDriver, the SceneManager and the graphical
|
||||
user interface environment, so that we do not always have to write
|
||||
device->getVideoDriver(), device->getSceneManager(), or
|
||||
device->getGUIEnvironment().
|
||||
*/
|
||||
driver = device->getVideoDriver();
|
||||
smgr = device->getSceneManager();
|
||||
guienv = device->getGUIEnvironment();
|
||||
|
||||
/*
|
||||
We add a hello world label to the window, using the GUI environment.
|
||||
The text is placed at the position (10,10) as top left corner and
|
||||
(260,22) as lower right corner.
|
||||
*/
|
||||
guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
|
||||
rect<s32>(10,10,260,22), true);
|
||||
|
||||
/*
|
||||
Get a media path dedicated for your platform.
|
||||
*/
|
||||
const io::path mediaPath = getExampleMediaPath();
|
||||
|
||||
/*
|
||||
To show something interesting, we load a Quake 2 model and display it.
|
||||
We only have to get the Mesh from the Scene Manager with getMesh() and add
|
||||
a SceneNode to display the mesh with addAnimatedMeshSceneNode(). We
|
||||
check the return value of getMesh() to become aware of loading problems
|
||||
and other errors.
|
||||
|
||||
Instead of writing the filename sydney.md2, it would also be possible
|
||||
to load a Maya object file (.obj), a complete Quake3 map (.bsp) or any
|
||||
other supported file format. By the way, that cool Quake 2 model
|
||||
called sydney was modelled by Brian Collins.
|
||||
*/
|
||||
IAnimatedMesh* mesh = smgr->getMesh(mediaPath + "sydney.md2");
|
||||
if (!mesh)
|
||||
{
|
||||
device->drop();
|
||||
return 1;
|
||||
}
|
||||
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
|
||||
|
||||
/*
|
||||
To let the mesh look a little bit nicer, we change its material. We
|
||||
disable lighting because we do not have a dynamic light in here, and
|
||||
the mesh would be totally black otherwise. Then we set the frame loop,
|
||||
such that the predefined STAND animation is used. And last, we apply a
|
||||
texture to the mesh. Without it the mesh would be drawn using only a
|
||||
color.
|
||||
*/
|
||||
if (node)
|
||||
{
|
||||
node->setMaterialFlag(EMF_LIGHTING, false);
|
||||
node->setMD2Animation(scene::EMAT_STAND);
|
||||
node->setMaterialTexture( 0, driver->getTexture(mediaPath + "sydney.bmp") );
|
||||
}
|
||||
|
||||
/*
|
||||
To look at the mesh, we place a camera into 3d space at the position
|
||||
(0, 30, -40). The camera looks from there to (0,5,0), which is
|
||||
approximately the place where our md2 model is.
|
||||
*/
|
||||
smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
|
||||
|
||||
/*
|
||||
Ok, now we have set up the scene, lets draw everything: We run the
|
||||
device in a while() loop, until the device does not want to run any
|
||||
more. This would be when the user closes the window or presses ALT+F4
|
||||
(or whatever keycode closes a window).
|
||||
*/
|
||||
while(device->run())
|
||||
{
|
||||
/*
|
||||
Anything can be drawn between a beginScene() and an endScene()
|
||||
call. The beginScene() call clears the screen with a color and
|
||||
the depth buffer, if desired. Then we let the Scene Manager and
|
||||
the GUI Environment draw their content. With the endScene()
|
||||
call everything is presented on the screen.
|
||||
*/
|
||||
driver->beginScene(ECBF_COLOR | ECBF_DEPTH, SColor(255,100,101,140));
|
||||
|
||||
smgr->drawAll();
|
||||
guienv->drawAll();
|
||||
|
||||
driver->endScene();
|
||||
}
|
||||
|
||||
+#ifndef __EMSCRIPTEN__
|
||||
/*
|
||||
After we are done with the render loop, we have to delete the Irrlicht
|
||||
Device created before with createDevice(). In the Irrlicht Engine, you
|
||||
have to delete all objects you created with a method or function which
|
||||
starts with 'create'. The object is simply deleted by calling ->drop().
|
||||
See the documentation at irr::IReferenceCounted::drop() for more
|
||||
information.
|
||||
*/
|
||||
device->drop();
|
||||
#else // __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(one_iter, 0, 0);
|
||||
#endif //__EMSCRIPTEN__
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
That's it. Compile and run.
|
||||
**/
|
|
@ -0,0 +1,5 @@
|
|||
emscripten is a project to compile c/c++ code int the asm.js format which can be run in some browsers.
|
||||
See http://kripken.github.io/emscripten-site for more information.
|
||||
|
||||
emscripten support for Irrlicht is a work in process. Use at your own risk.
|
||||
Might take work and knowledge to get it running.
|
|
@ -0,0 +1,394 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Irrlicht Engine Tutorial</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
</head>
|
||||
|
||||
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
|
||||
<br>
|
||||
<table width="90%" border="0" cellspacing="0" cellpadding="2" align="center">
|
||||
<tr>
|
||||
<td bgcolor="#666699"> <b><font color="#FFFFFF">Tutorial 1.HelloWorld</font></b></td>
|
||||
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="90" bgcolor="#F7F3F7"> <div align="left">
|
||||
<p>This Tutorial shows how to set up the IDE for using the
|
||||
Irrlicht Engine and how to write a simple HelloWorld program
|
||||
with it. The program will show how to use the basics of
|
||||
the VideoDriver, the GUIEnvironment and the SceneManager.<br>
|
||||
The result of this example will look like this:</p>
|
||||
<p align="center"><img src="../../media/001shot.jpg" width="259" height="204"><br>
|
||||
</p>
|
||||
</div></td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
<br> <table width="90%" border="0" cellspacing="0" cellpadding="2" align="center">
|
||||
<tr> <a name="settingup"></a>
|
||||
<td bgcolor="#666699"> <b><font color="#FFFFFF">Setting up the
|
||||
IDE</font></b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="90" bgcolor="#F7F3F7"> <div align="left">
|
||||
<div align="left">
|
||||
<p align="left">To use the engine, we will have to include
|
||||
the header file <irrlicht.h>, which can be found
|
||||
in the Irrlicht Engine SDK directory \include. To let
|
||||
the compiler find this header file, the directory where
|
||||
it is located should be specified somewhere. This is different
|
||||
for every IDE and compiler. I will explain how to do this
|
||||
in Microsoft Visual Studio C++ 6.0 and .NET:</p>
|
||||
|
||||
</div>
|
||||
<ul>
|
||||
<li>
|
||||
<div align="left">If you use Version 6.0, select the Menu
|
||||
Extras -> Options. Select the directories tab, and
|
||||
select the 'Include' Item in the combo box. Add the
|
||||
\include directory of the Irrlicht Engine folder to
|
||||
the list of directories. Now the compiler will find
|
||||
the Irrlicht.h header file. We also need the location
|
||||
of irrlicht.lib to be listed, so select the 'Libraries'
|
||||
tab and add the \lib\VisualStudio directory.<br>
|
||||
<br>
|
||||
<img src="../../media/vc6optionsdir.jpg" width="231" height="172" align="middle"> <img src="../../media/vc6include.jpg" width="231" height="159" align="middle"><br>
|
||||
<br>
|
||||
|
||||
</div>
|
||||
</li>
|
||||
<li>If your IDE is Visual Studio .NET, select Tools ->
|
||||
Options. Select the Projects entry and then select VC++
|
||||
directories. Select 'show directories for include files'
|
||||
in the combo box, and add the \include directory of the
|
||||
Irrlicht Engine folder to the list of directories so the
|
||||
compiler will find the Irrlicht.h header file. We also
|
||||
need the irrlicht.lib to be found, so select 'show directories
|
||||
for Library files' and add the \lib\VisualStudio directory.<br>
|
||||
<br>
|
||||
<img src="../../media/vcnetinclude.jpg" width="256" height="160">
|
||||
<br>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
</div></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br> <table width="90%" border="0" cellspacing="0" cellpadding="2" align="center">
|
||||
<tr>
|
||||
<td bgcolor="#666699"> <font color="#FFFFFF"><b>Lets start!</b></font></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td height="90" bgcolor="#F7F3F7" valign="top"> <div align="left">
|
||||
<div align="left">
|
||||
<div align="left">
|
||||
<div align="left">
|
||||
<p>After we have set up the IDE, the compiler will know
|
||||
where to find the Irrlicht Engine header files so
|
||||
we can include it now into our code.</p>
|
||||
<table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
|
||||
<tr>
|
||||
<td> <pre>#include <irrlicht.h></pre> </td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
<p>In the Irrlicht Engine, everything can be found in
|
||||
the namespace 'irr'. So if you want to use a class
|
||||
of the engine, you'll have to type an irr:: before
|
||||
the name of the class. For example, to use the IrrlichtDevice,
|
||||
write: irr::IrrlichtDevice. To avoid having to put
|
||||
irr:: before of the name of every class, we tell the
|
||||
compiler that we use that namespace.</p>
|
||||
<table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
|
||||
<tr>
|
||||
<td> <pre>using namespace irr;</pre> </td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<p>There are 5 sub-namespaces in the Irrlicht Engine.
|
||||
Take a look at them: you can read a detailed description
|
||||
of them in the documentation by clicking on the top
|
||||
menu item '<a href="http://irrlicht.sourceforge.net/docu/namespaces.html">Namespace
|
||||
List</a>'. To keep this example simple, we don't want
|
||||
to have to specify the name spaces, Hence:</p>
|
||||
<table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
|
||||
<tr>
|
||||
<td> <pre>using namespace core;<br>using namespace scene;<br>using namespace video;<br>using namespace io;<br>using namespace gui;</pre> </td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
<p>To be able to use the Irrlicht.DLL file, we need
|
||||
to link with the Irrlicht.lib. We could set this option
|
||||
in the project settings, but to make it easy we use
|
||||
a pragma comment:</p>
|
||||
<table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
|
||||
<tr>
|
||||
<td> <pre>#pragma comment(lib, "Irrlicht.lib")</pre> </td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
<p>Now the main method: to keep this example simple
|
||||
we use int main(), which can be used on any platform.
|
||||
However, on Windows platforms, we could also use the
|
||||
WinMain method if we would want to get rid of the
|
||||
console window which pops up when starting a program
|
||||
with main().</p>
|
||||
<table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
|
||||
<tr>
|
||||
<td> <pre>int main()<br>{</pre> </td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<p>The most important function of the engine is the
|
||||
'createDevice' function. The Irrlicht Device, which
|
||||
is the root object for doing everything with the engine,
|
||||
can be created with it. createDevice() has 7 parameters:</p>
|
||||
</div>
|
||||
<ul>
|
||||
<li>
|
||||
|
||||
<div align="left"> deviceType: Type of the device. This can currently
|
||||
be the Null device, the Software device, Direct3D8, Direct3D9,
|
||||
or OpenGL. In this example we use EDT_SOFTWARE, but, to try
|
||||
them out, you might want to change it to EDT_NULL, EDT_DIRECT3D8,
|
||||
EDT_DIRECT3D9 or EDT_OPENGL. </div>
|
||||
</li>
|
||||
<li>
|
||||
<div align="left">windowSize: Size of the window or
|
||||
full screen mode to be created. In this example
|
||||
we use 512x384.</div>
|
||||
|
||||
</li>
|
||||
<li>
|
||||
<div align="left">bits: Number of bits per pixel when
|
||||
in full screen mode. This should be 16 or 32. This
|
||||
parameter is ignored when running in windowed mode.</div>
|
||||
</li>
|
||||
<li>
|
||||
<div align="left">fullscreen: Specifies if we want
|
||||
the device to run in full screen mode or not.</div>
|
||||
</li>
|
||||
<li>stencilbuffer: Specifies if we want to use the stencil
|
||||
buffer for drawing shadows.</li>
|
||||
|
||||
<li>vsync: Specifies if we want to have vsync enabled.
|
||||
This is only useful in full screen mode.</li>
|
||||
<li>
|
||||
<div align="left">eventReceiver: An object to receive
|
||||
events. We do not want to use this parameter here,
|
||||
and set it to 0.</div>
|
||||
</li>
|
||||
</ul>
|
||||
<table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
|
||||
<tr>
|
||||
<td> <pre>IrrlichtDevice *device =<br> createDevice(EDT_SOFTWARE, dimension2d<s32>(512, 384), 16,<br> false, false, false, 0);</pre> </td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
<p>Now we set the caption of the window to some nice text.
|
||||
Note that there is a 'L' in front of the string: the
|
||||
Irrlicht Engine uses wide character strings when displaying
|
||||
text.</p>
|
||||
<table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
|
||||
<tr>
|
||||
<td> <pre>device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");</pre> </td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
<p>Now we store a pointer to the video driver, the SceneManager,
|
||||
and the graphical user interface environment so that
|
||||
we do not always have to write device->getVideoDriver(),
|
||||
device->getSceneManager(), and device->getGUIEnvironment().</p>
|
||||
<table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
|
||||
<tr>
|
||||
<td> <pre>IVideoDriver* driver = device->getVideoDriver();<br>ISceneManager* smgr = device->getSceneManager();<br>IGUIEnvironment* guienv = device->getGUIEnvironment();</pre> </td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
<p> We add a hello world label to the window using the
|
||||
GUI environment. The text is placed at the position
|
||||
(10,10) as top left corner and (200,22) as lower right
|
||||
corner.</p>
|
||||
<table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
|
||||
<tr>
|
||||
<td> <pre>guienv->addStaticText(L"Hello World! This is the Irrlicht Software engine!",<br> rect<s32>(10,10,200,22), true);</pre> </td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
<p>To display something interesting, we load a Quake 2
|
||||
model and display it. We only have to get the Mesh from
|
||||
the Scene Manager with getMesh() and add a SceneNode
|
||||
to display the mesh with addAnimatedMeshSceneNode().
|
||||
Instead of loading a Quake2 file (.md2), it is also
|
||||
possible to load a Maya object file (.obj), a complete
|
||||
Quake3 map (.bsp), or a Milshape file (.ms3d).<br>
|
||||
By the way, that cool Quake 2 model called sydney.md2
|
||||
was modelled by Brian Collins.</p>
|
||||
<table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
|
||||
<tr>
|
||||
<td> <pre>IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");<br>IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );</pre> </td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
<p>To make the mesh look a little bit nicer, we change
|
||||
its material a little bit: we disable lighting because
|
||||
we do not have a dynamic light in here and the mesh
|
||||
would be totally black. Then we set the frame loop so
|
||||
that the animation is looped between the frames 0 and
|
||||
310. Then, at last, we apply a texture to the mesh.
|
||||
Without it the mesh would be drawn using only a solid
|
||||
color.</p>
|
||||
<table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
|
||||
<tr>
|
||||
<td> <pre>if (node)<br>{<br> node->setMaterialFlag(EMF_LIGHTING, false);<br> node->setFrameLoop(0, 310); <br> node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );<br>}</pre>
|
||||
</td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
<p>To look at the mesh, we place a camera into 3d space
|
||||
at the position (0, 10, -40). The camera looks from
|
||||
there to (0,5,0).</p>
|
||||
<table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
|
||||
<tr>
|
||||
<td> <pre>smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));</pre> </td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<p>Ok. Now that we have set up the scene, let's draw everything:
|
||||
we run the device in a while() loop until the device
|
||||
does not want to run any more. This would be when the
|
||||
user closes the window or presses ALT+F4 in Windows.</p>
|
||||
<table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
|
||||
<tr>
|
||||
<td> <pre>while(device->run())<br>{</pre> </td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<p> Everything must be drawn between a beginScene() and
|
||||
an endScene() call. The beginScene clears the screen
|
||||
with a color and also the depth buffer, if desired.
|
||||
Then we let the Scene Manager and the GUI environment
|
||||
draw their content. With the endScene() call, everything
|
||||
is presented on the screen.</p>
|
||||
<table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
|
||||
<tr>
|
||||
|
||||
<td> <pre> driver->beginScene(true, true, SColor(255,100,101,140));<br>
|
||||
smgr->drawAll();
|
||||
guienv->drawAll();</pre>
|
||||
<pre> driver->endScene();
|
||||
}</pre> </td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
<p>After we are finished, we have to delete the Irrlicht
|
||||
Device created earlier with createDevice(). With the
|
||||
Irrlicht Engine, you should delete all objects you created
|
||||
with a method or function that starts with 'create'.
|
||||
The object is deleted simply by calling ->drop().
|
||||
See the <a href="http://irrlicht.sourceforge.net/docu/classirr_1_1IUnknown.html#a3" target="_blank">documentation</a>
|
||||
for more information.</p>
|
||||
<table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
|
||||
<tr>
|
||||
<td> <pre> device->drop();<br> return 0;
|
||||
}</pre> </td>
|
||||
|
||||
</tr>
|
||||
</table>
|
||||
<p>That's it. Compile and run. </p>
|
||||
<p> </p>
|
||||
</div>
|
||||
</div>
|
||||
</div></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<br>
|
||||
<table width="90%" border="0" cellspacing="0" cellpadding="2" align="center">
|
||||
<tr>
|
||||
<td bgcolor="#666699"> <b><font color="#FFFFFF">Possible Errors
|
||||
or Problems</font></b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td height="90" bgcolor="#F7F3F7"> <div align="left">
|
||||
<div align="left">
|
||||
<div align="left">
|
||||
<p><strong>Visual Studio</strong><br>
|
||||
|
||||
While trying to compile the tutorial, if you get the
|
||||
error: </p>
|
||||
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td bgcolor="#CCCCCC"><font face="Courier New, Courier, mono">fatal
|
||||
error C1083: Cannot open include file: 'irrlicht.h':
|
||||
No such file or directory</font></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p>Solution: You may have set the include directory improperly
|
||||
in the Visual Studio options. See <a href="#settingup">above</a>
|
||||
for information on setting it. </p>
|
||||
|
||||
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td bgcolor="#CCCCCC"><font face="Courier New, Courier, mono">LINK
|
||||
: LNK6004: HelloWorld.exe not found or not built
|
||||
by the last incremental link; performing full link<br>
|
||||
LINK : fatal error LNK1104: cannot open file "Irrlicht.lib"<br>
|
||||
Error executing link.exe</font></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> Solution: You may have set the library directory improperly.
|
||||
See <a href="#settingup">above</a> for information on
|
||||
setting it. <br>
|
||||
|
||||
<br>
|
||||
</p>
|
||||
<p><strong>Compiler independent problems<br>
|
||||
</strong>If the tutorial compiles successfully but gives
|
||||
the error: </p>
|
||||
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td bgcolor="#CCCCCC"><font face="Courier New, Courier, mono">This
|
||||
application has failed to start because Irrlicht.dll
|
||||
was not found. Re-installing the application may
|
||||
fix this problem</font></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<p>Solution: You may have forgotten to copy the Irrlicht.dll
|
||||
file from Irrlicht\bin\VisualStudio to the directory
|
||||
the tutorial's project file is in. </p>
|
||||
If the tutorial compiles and runs successfully but produces
|
||||
errors in the console like:<br>
|
||||
<br>
|
||||
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td bgcolor="#CCCCCC"><font face="Courier New, Courier, mono">Could
|
||||
not load mesh, because file could not be opened.:
|
||||
../media/sydney.md2</font></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<p> Or:</p>
|
||||
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
|
||||
<tr>
|
||||
<td bgcolor="#CCCCCC"><em><font face="Courier New, Courier, mono">Could
|
||||
not open file of texture: stones.jpg</font></em><font face="Courier New, Courier, mono"><b><br>
|
||||
</b><em>Could not load texture: stones.jpg </em></font></td>
|
||||
</tr>
|
||||
|
||||
</table>
|
||||
<p>Solution: The file listed in the error message cannot
|
||||
be found. Ensure that the directory specified in the
|
||||
main.cpp exists and is where the file is located. <br>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div></td>
|
||||
</tr>
|
||||
</table>
|
||||
<p> </p>
|
||||
</body>
|
||||
</html>
|
|
@ -100,6 +100,18 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__EMSCRIPTEN__)
|
||||
#define _IRR_EMSCRIPTEN_PLATFORM_
|
||||
#define NO_IRR_COMPILE_WITH_JOYSTICK_EVENTS_
|
||||
#define NO_IRR_COMPILE_WITH_OPENGL_
|
||||
#define NO_IRR_COMPILE_WITH_OGLES1_
|
||||
#define _IRR_COMPILE_WITH_OGLES2_
|
||||
#define _IRR_COMPILE_WITH_EGL_MANAGER_
|
||||
#define _IRR_COMPILE_WITH_SDL_DEVICE_
|
||||
#define NO_IRR_COMPILE_WITH_X11_DEVICE_
|
||||
//#define _IRR_LINUX_PLATFORM_ //Hack
|
||||
#endif // __EMSCRIPTEN__
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#define _IRR_ANDROID_PLATFORM_
|
||||
#define _IRR_COMPILE_WITH_ANDROID_DEVICE_
|
||||
|
@ -114,7 +126,7 @@
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(_IRR_WINDOWS_API_) && !defined(_IRR_OSX_PLATFORM_) && !defined(_IRR_IOS_PLATFORM_) && !defined(_IRR_ANDROID_PLATFORM_)
|
||||
#if !defined(_IRR_WINDOWS_API_) && !defined(_IRR_OSX_PLATFORM_) && !defined(_IRR_IOS_PLATFORM_) && !defined(_IRR_ANDROID_PLATFORM_) && !defined(_IRR_EMSCRIPTEN_PLATFORM_)
|
||||
#ifndef _IRR_SOLARIS_PLATFORM_
|
||||
#define _IRR_LINUX_PLATFORM_
|
||||
#endif
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace irr
|
|||
UsePerformanceTimer(true),
|
||||
SDK_version_do_not_use(IRRLICHT_SDK_VERSION),
|
||||
PrivateData(0),
|
||||
#if defined(_IRR_COMPILE_WITH_IOS_DEVICE_) || defined(_IRR_ANDROID_PLATFORM_)
|
||||
#if defined(_IRR_COMPILE_WITH_IOS_DEVICE_) || defined(_IRR_ANDROID_PLATFORM_) || defined(_IRR_EMSCRIPTEN_PLATFORM_)
|
||||
OGLES2ShaderPath("media/Shaders/")
|
||||
#else
|
||||
OGLES2ShaderPath("../../media/Shaders/")
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace irr
|
|||
|
||||
static io::path getExampleMediaPath()
|
||||
{
|
||||
#if defined (_IRR_IOS_PLATFORM_) || defined (_IRR_ANDROID_PLATFORM_) || defined (_IRR_OSX_PLATFORM_)
|
||||
#if defined (_IRR_IOS_PLATFORM_) || defined (_IRR_ANDROID_PLATFORM_) || defined (_IRR_OSX_PLATFORM_) || defined (_IRR_EMSCRIPTEN_PLATFORM_)
|
||||
return io::path("media/");
|
||||
#else
|
||||
return io::path("../../media/");
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#ifdef _IRR_COMPILE_WITH_EGL_MANAGER_
|
||||
|
||||
#if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_) || defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_)
|
||||
#if defined(_IRR_COMPILE_WITH_ANDROID_DEVICE_) || defined(_IRR_COMPILE_WITH_FB_DEVICE_) || defined(_IRR_COMPILE_WITH_WINDOWS_DEVICE_) || defined(__EMSCRIPTEN__)
|
||||
#include <EGL/egl.h>
|
||||
#else
|
||||
#include <GLES/egl.h>
|
||||
|
|
|
@ -35,8 +35,7 @@
|
|||
#include <io.h> // for _access
|
||||
#include <tchar.h>
|
||||
#endif
|
||||
#else
|
||||
#if (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_) || defined(_IRR_IOS_PLATFORM_) || defined(_IRR_ANDROID_PLATFORM_))
|
||||
#elif (defined(_IRR_POSIX_API_) || defined(_IRR_OSX_PLATFORM_) || defined(_IRR_IOS_PLATFORM_) || defined(_IRR_ANDROID_PLATFORM_))
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
@ -45,7 +44,8 @@
|
|||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#elif defined(_IRR_EMSCRIPTEN_PLATFORM_)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace irr
|
||||
|
|
|
@ -20,6 +20,13 @@
|
|||
#include <SDL/SDL_syswm.h>
|
||||
#include <SDL/SDL_video.h>
|
||||
|
||||
#ifdef _IRR_EMSCRIPTEN_PLATFORM_
|
||||
#ifdef _IRR_COMPILE_WITH_OGLES2_
|
||||
#include "CEGLManager.h"
|
||||
#endif
|
||||
#include <emscripten.h>
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma comment(lib, "SDL.lib")
|
||||
#endif // _MSC_VER
|
||||
|
@ -37,6 +44,10 @@ namespace irr
|
|||
IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& params,
|
||||
io::IFileSystem* io, CIrrDeviceSDL* device);
|
||||
#endif
|
||||
|
||||
#if defined(_IRR_COMPILE_WITH_OGLES2_) && defined(_IRR_EMSCRIPTEN_PLATFORM_)
|
||||
IVideoDriver* createOGLES2Driver(const irr::SIrrlichtCreationParameters& params, io::IFileSystem* io, IContextManager* contextManager);
|
||||
#endif
|
||||
} // end namespace video
|
||||
|
||||
} // end namespace irr
|
||||
|
@ -73,14 +84,16 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
|
|||
SDL_putenv("SDL_VIDEODRIVER=directx");
|
||||
#elif defined(_IRR_OSX_PLATFORM_)
|
||||
SDL_putenv("SDL_VIDEODRIVER=Quartz");
|
||||
#else
|
||||
#elif !defined(_IRR_EMSCRIPTEN_PLATFORM_)
|
||||
SDL_putenv("SDL_VIDEODRIVER=x11");
|
||||
#endif
|
||||
// SDL_putenv("SDL_WINDOWID=");
|
||||
|
||||
SDL_VERSION(&Info.version);
|
||||
|
||||
#ifndef _IRR_EMSCRIPTEN_PLATFORM_
|
||||
SDL_GetWMInfo(&Info);
|
||||
#endif //_IRR_EMSCRIPTEN_PLATFORM_
|
||||
core::stringc sdlversion = "SDL Version ";
|
||||
sdlversion += Info.version.major;
|
||||
sdlversion += ".";
|
||||
|
@ -104,6 +117,11 @@ CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)
|
|||
SDL_Flags |= SDL_OPENGL;
|
||||
else if (CreationParams.Doublebuffer)
|
||||
SDL_Flags |= SDL_DOUBLEBUF;
|
||||
#ifdef _IRR_EMSCRIPTEN_PLATFORM_
|
||||
else
|
||||
SDL_Flags = SDL_SWSURFACE;
|
||||
#endif //_IRR_EMSCRIPTEN_PLATFORM_
|
||||
|
||||
// create window
|
||||
if (CreationParams.DriverType != video::EDT_NULL)
|
||||
{
|
||||
|
@ -136,6 +154,10 @@ CIrrDeviceSDL::~CIrrDeviceSDL()
|
|||
|
||||
bool CIrrDeviceSDL::createWindow()
|
||||
{
|
||||
#ifdef _IRR_EMSCRIPTEN_PLATFORM_
|
||||
emscripten_set_canvas_size( Width, Height);
|
||||
return true;
|
||||
#else // !_IRR_EMSCRIPTEN_PLATFORM_
|
||||
if ( Close )
|
||||
return false;
|
||||
|
||||
|
@ -204,6 +226,7 @@ bool CIrrDeviceSDL::createWindow()
|
|||
}
|
||||
|
||||
return true;
|
||||
#endif // !_IRR_EMSCRIPTEN_PLATFORM_
|
||||
}
|
||||
|
||||
|
||||
|
@ -254,6 +277,21 @@ void CIrrDeviceSDL::createDriver()
|
|||
#endif
|
||||
break;
|
||||
|
||||
case video::EDT_OGLES2:
|
||||
#if defined(_IRR_COMPILE_WITH_OGLES2_) && defined(_IRR_EMSCRIPTEN_PLATFORM_)
|
||||
{
|
||||
video::SExposedVideoData data;
|
||||
|
||||
ContextManager = new video::CEGLManager();
|
||||
ContextManager->initialize(CreationParams, data);
|
||||
|
||||
VideoDriver = video::createOGLES2Driver(CreationParams, FileSystem, ContextManager);
|
||||
}
|
||||
#else
|
||||
os::Printer::log("No OpenGL-ES2 support compiled in.", ELL_ERROR);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case video::EDT_NULL:
|
||||
VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize);
|
||||
break;
|
||||
|
@ -420,7 +458,11 @@ bool CIrrDeviceSDL::run()
|
|||
{
|
||||
Width = SDL_event.resize.w;
|
||||
Height = SDL_event.resize.h;
|
||||
Screen = SDL_SetVideoMode( Width, Height, 0, SDL_Flags );
|
||||
#ifdef _IRR_EMSCRIPTEN_PLATFORM_
|
||||
emscripten_set_canvas_size( Width, Height);
|
||||
#else //_IRR_EMSCRIPTEN_PLATFORM_
|
||||
Screen = SDL_SetVideoMode( Width, Height, 0, SDL_Flags );
|
||||
#endif //_IRR_EMSCRIPTEN_PLATFOR
|
||||
if (VideoDriver)
|
||||
VideoDriver->OnResize(core::dimension2d<u32>(Width, Height));
|
||||
}
|
||||
|
@ -600,6 +642,9 @@ void CIrrDeviceSDL::setWindowCaption(const wchar_t* text)
|
|||
//! presents a surface in the client area
|
||||
bool CIrrDeviceSDL::present(video::IImage* surface, void* windowId, core::rect<s32>* srcClip)
|
||||
{
|
||||
#ifdef _IRR_EMSCRIPTEN_PLATFORM_
|
||||
return true;
|
||||
#else // !_IRR_EMSCRIPTEN_PLATFORM_
|
||||
SDL_Surface *sdlSurface = SDL_CreateRGBSurfaceFrom(
|
||||
surface->lock(), surface->getDimension().Width, surface->getDimension().Height,
|
||||
surface->getBitsPerPixel(), surface->getPitch(),
|
||||
|
@ -675,6 +720,7 @@ bool CIrrDeviceSDL::present(video::IImage* surface, void* windowId, core::rect<s
|
|||
SDL_FreeSurface(sdlSurface);
|
||||
surface->unlock();
|
||||
return (scr != 0);
|
||||
#endif // !_IRR_EMSCRIPTEN_PLATFORM_
|
||||
}
|
||||
|
||||
|
||||
|
@ -688,6 +734,10 @@ void CIrrDeviceSDL::closeDevice()
|
|||
//! \return Pointer to a list with all video modes supported
|
||||
video::IVideoModeList* CIrrDeviceSDL::getVideoModeList()
|
||||
{
|
||||
#ifdef _IRR_EMSCRIPTEN_PLATFORM_
|
||||
os::Printer::log("VideoModeList not available on the web." , ELL_WARNING);
|
||||
return VideoModeList;
|
||||
#elif // !_IRR_EMSCRIPTEN_PLATFORM_
|
||||
if (!VideoModeList->getVideoModeCount())
|
||||
{
|
||||
// enumerate video modes.
|
||||
|
@ -706,12 +756,17 @@ video::IVideoModeList* CIrrDeviceSDL::getVideoModeList()
|
|||
}
|
||||
|
||||
return VideoModeList;
|
||||
#endif // !_IRR_EMSCRIPTEN_PLATFORM_
|
||||
}
|
||||
|
||||
|
||||
//! Sets if the window should be resizable in windowed mode.
|
||||
void CIrrDeviceSDL::setResizable(bool resize)
|
||||
{
|
||||
#ifdef _IRR_EMSCRIPTEN_PLATFORM_
|
||||
os::Printer::log("Resizable not available on the web." , ELL_WARNING);
|
||||
return;
|
||||
#elif // !_IRR_EMSCRIPTEN_PLATFORM_
|
||||
if (resize != Resizable)
|
||||
{
|
||||
if (resize)
|
||||
|
@ -721,6 +776,7 @@ void CIrrDeviceSDL::setResizable(bool resize)
|
|||
Screen = SDL_SetVideoMode( 0, 0, 0, SDL_Flags );
|
||||
Resizable = resize;
|
||||
}
|
||||
#endif // !_IRR_EMSCRIPTEN_PLATFORM_
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -59,6 +59,8 @@ LINKOBJ = $(IRRMESHOBJ) $(IRROBJ) $(IRRPARTICLEOBJ) $(IRRANIMOBJ) \
|
|||
$(IRRGUIOBJ) $(ZLIBOBJ) $(JPEGLIBOBJ) $(LIBPNGOBJ) $(LIBAESGM) \
|
||||
$(BZIP2OBJ) $(EXTRAOBJ)
|
||||
|
||||
emscripten: EMSCRIPTEN=1
|
||||
|
||||
###############
|
||||
#Compiler flags
|
||||
|
||||
|
@ -66,14 +68,27 @@ CXXINCS = -I../../include -Izlib -Ijpeglib -Ilibpng
|
|||
CPPFLAGS += $(CXXINCS) -DIRRLICHT_EXPORTS=1
|
||||
CXXFLAGS += -Wall -pipe -fno-exceptions -fno-rtti -fstrict-aliasing
|
||||
ifndef NDEBUG
|
||||
CXXFLAGS += -g -D_DEBUG
|
||||
CXXFLAGS += -g -D_DEBUG
|
||||
else
|
||||
CXXFLAGS += -fexpensive-optimizations -O3
|
||||
ifndef EMSCRIPTEN
|
||||
CXXFLAGS += -fexpensive-optimizations -O3
|
||||
else
|
||||
CXXFLAGS += -O3
|
||||
endif
|
||||
endif
|
||||
ifdef PROFILE
|
||||
CXXFLAGS += -pg
|
||||
CXXFLAGS += -pg
|
||||
endif
|
||||
ifdef EMSCRIPTEN
|
||||
CXXFLAGS += -std=gnu++11 -U__STRICT_ANSI__
|
||||
ifndef NDEBUG
|
||||
CFLAGS := -DPNG_THREAD_UNSAFE_OK -DPNG_NO_MMX_CODE -DPNG_NO_MNG_FEATURES
|
||||
else
|
||||
CFLAGS := -O3 -DPNG_THREAD_UNSAFE_OK -DPNG_NO_MMX_CODE -DPNG_NO_MNG_FEATURES
|
||||
endif
|
||||
else
|
||||
CFLAGS := -O3 -fexpensive-optimizations -DPNG_THREAD_UNSAFE_OK -DPNG_NO_MMX_CODE -DPNG_NO_MNG_FEATURES
|
||||
endif
|
||||
CFLAGS := -O3 -fexpensive-optimizations -DPNG_THREAD_UNSAFE_OK -DPNG_NO_MMX_CODE -DPNG_NO_MNG_FEATURES
|
||||
|
||||
sharedlib sharedlib_osx: CXXFLAGS += -fPIC
|
||||
sharedlib sharedlib_osx: CFLAGS += -fPIC
|
||||
|
@ -117,7 +132,7 @@ SONAME = $(SHARED_LIB).$(VERSION_MAJOR).$(VERSION_MINOR)
|
|||
|
||||
####################
|
||||
# All target, builds Irrlicht as static lib (libIrrlicht.a) and copies it into lib/Linux
|
||||
all linux: staticlib
|
||||
all linux emscripten: staticlib
|
||||
|
||||
# Builds Irrlicht as shared lib (libIrrlicht.so.versionNumber) and copies it into lib/Linux
|
||||
sharedlib: $(LINKOBJ)
|
||||
|
@ -163,7 +178,7 @@ TAGS:
|
|||
|
||||
# Create dependency files for automatic recompilation
|
||||
%.d:%.cpp
|
||||
$(CXX) $(CPPFLAGS) -MM -MF $@ $<
|
||||
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -MM -MF $@ $<
|
||||
|
||||
# Create dependency files for automatic recompilation
|
||||
%.d:%.c
|
||||
|
@ -192,5 +207,4 @@ help:
|
|||
clean:
|
||||
$(RM) $(LINKOBJ) $(SHARED_FULLNAME) $(STATIC_LIB) $(LINKOBJ:.o=.d)
|
||||
|
||||
.PHONY: all sharedlib staticlib sharedlib_win32 staticlib_win32 help install clean
|
||||
|
||||
.PHONY: all sharedlib staticlib sharedlib_win32 staticlib_win32 emscripten help install clean
|
||||
|
|
|
@ -189,6 +189,58 @@ namespace os
|
|||
}
|
||||
} // end namespace os
|
||||
|
||||
#elif defined(_IRR_EMSCRIPTEN_PLATFORM_)
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// emscripten version
|
||||
// ----------------------------------------------------------------
|
||||
|
||||
#include <emscripten.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace os
|
||||
{
|
||||
|
||||
//! prints a debuginfo string
|
||||
void Printer::print(const c8* message, ELOG_LEVEL ll)
|
||||
{
|
||||
int log_level;
|
||||
switch (ll)
|
||||
{
|
||||
case ELL_DEBUG:
|
||||
log_level=0;
|
||||
break;
|
||||
case ELL_INFORMATION:
|
||||
log_level=0;
|
||||
break;
|
||||
case ELL_WARNING:
|
||||
log_level=EM_LOG_WARN;
|
||||
break;
|
||||
case ELL_ERROR:
|
||||
log_level=EM_LOG_ERROR;
|
||||
break;
|
||||
default: // ELL_NONE
|
||||
log_level=0;
|
||||
break;
|
||||
}
|
||||
emscripten_log(log_level, "%s\n", message);
|
||||
}
|
||||
|
||||
void Timer::initTimer(bool usePerformanceTimer)
|
||||
{
|
||||
initVirtualTimer();
|
||||
}
|
||||
|
||||
u32 Timer::getRealTime()
|
||||
{
|
||||
double time = emscripten_get_now();
|
||||
return (u32)(time);
|
||||
}
|
||||
} // end namespace os
|
||||
|
||||
#else
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
|
@ -223,7 +275,7 @@ namespace os
|
|||
}
|
||||
} // end namespace os
|
||||
|
||||
#endif // end linux / android / windows
|
||||
#endif // end linux / emscripten / android / windows
|
||||
|
||||
namespace os
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue