Add the code in emscripten hello_worldd which was missing in last 2 check-ins (sorry).

- Add a function to check for canvas resizes 
- Switch to WebGL1 driver


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@5508 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien 2017-07-19 13:05:25 +00:00
parent 60d2798d9d
commit 7f190b80cd
2 changed files with 61 additions and 35 deletions

View File

@ -40,8 +40,8 @@ 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 += -lGL -lSDL --preload-file ../../media@/media -s ALLOW_MEMORY_GROWTH=1 -s NO_EXIT_RUNTIME=1
# You have to check yourself if oyu need FULL_ES2 or not (it's slower sometimes, but some stuff simply won't work yet without this)
all_emscripten: LDFLAGS += -s FULL_ES2=1
# You need the FULL_ES2 when using EDT_OGLES2 driver
#all_emscripten: LDFLAGS += -s FULL_ES2=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

View File

@ -40,11 +40,36 @@ IVideoDriver* driver = 0;
ISceneManager* smgr = 0;
IGUIEnvironment* guienv = 0;
ICameraSceneNode* camera = 0;
dimension2d<u32> screenSize(640, 480);
#ifdef __EMSCRIPTEN__
/*
Handle changes in canvas size which are done with html/js.
Note that it's only OK for windowed so far,
the switch to fullscreen not yet working.
*/
void checkCanvasResize()
{
int w, h, fs;
emscripten_get_canvas_size(&w, &h, &fs);
const core::dimension2d<u32> canvasDim(w,h);
if ( canvasDim != screenSize )
{
screenSize = canvasDim;
driver->OnResize(canvasDim);
driver->setViewPort(irr::core::rect<irr::s32>(0,0,w,h));
irr::f32 aspect = (irr::f32)w / (irr::f32)h;
camera->setAspectRatio(aspect);
}
}
/*
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())
@ -57,6 +82,10 @@ void one_iter()
emscripten_cancel_main_loop();
return;
}
// In case you have a resizeable canvas (resized from html)
checkCanvasResize();
driver->beginScene(ECBF_COLOR | ECBF_DEPTH, SColor(255,100,101,140));
smgr->drawAll();
@ -76,21 +105,18 @@ int main()
Create device flags for emscripten are still experimental
and might not all work.
- deviceType: You have to use video::EDT_OGLES2 which will be translated
to WebGL by emscripten.
It can be useful to have EDT_OGLES2 or EDT_OGLES1 for comparison for
testing on the desktop.
- deviceType: You can to use EDT_OGLES2 or EDT_WEBGL1 on emscripten.
EDT_WEBGL1 is better optimized but does not yet support all options.
EDT_OGLES2 needs -s FULL_ES2=1 as linker flag in the Makefile.
*/
#ifndef __EMSCRIPTEN__
device =
createDevice( video::EDT_OGLES1, dimension2d<u32>(640, 480), 16,
false, false, false, 0);
video::E_DRIVER_TYPE deviceType = EDT_OGLES2;
#else //__EMSCRIPTEN__
device =
createDevice(video::EDT_OGLES2, dimension2d<u32>(640, 480), 16,
false, false, false, 0);
video::E_DRIVER_TYPE deviceType = EDT_WEBGL1;
#endif //__EMSCRIPTEN__
device = createDevice(deviceType, screenSize, 16, false, false, false, 0);
if (!device)
return 1;
@ -158,7 +184,7 @@ int main()
(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));
camera = smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
#ifndef __EMSCRIPTEN__ // this part only so you can run the same code on desktop
/*