int32_t run(int _argc, char** _argv) { emscripten_set_mousedown_callback("#canvas", this, true, mouseCb); emscripten_set_mouseup_callback("#canvas", this, true, mouseCb); emscripten_set_mousemove_callback("#canvas", this, true, mouseCb); emscripten_set_wheel_callback("#canvas", this, true, wheelCb); emscripten_set_keypress_callback(NULL, this, true, keyCb); emscripten_set_keydown_callback(NULL, this, true, keyCb); emscripten_set_keyup_callback(NULL, this, true, keyCb); emscripten_set_resize_callback(0, this, true, resizeCb); EmscriptenFullscreenStrategy fullscreenStrategy = {}; fullscreenStrategy.scaleMode = EMSCRIPTEN_FULLSCREEN_SCALE_DEFAULT; fullscreenStrategy.canvasResolutionScaleMode = EMSCRIPTEN_FULLSCREEN_CANVAS_SCALE_NONE; fullscreenStrategy.filteringMode = EMSCRIPTEN_FULLSCREEN_FILTERING_DEFAULT; fullscreenStrategy.canvasResizedCallback = canvasResizeCb; fullscreenStrategy.canvasResizedCallbackUserData = this; emscripten_request_fullscreen_strategy("#canvas", false, &fullscreenStrategy); emscripten_set_focus_callback(NULL, this, true, focusCb); emscripten_set_focusin_callback(NULL, this, true, focusCb); emscripten_set_focusout_callback(NULL, this, true, focusCb); int32_t result = main(_argc, _argv); return result; }
void CoreWindow::MainLoop(void) { emscripten_set_keyup_callback("#window", NULL, 0, keyUpEvent); emscripten_set_keydown_callback("#window", NULL, 0, keyDownEvent); emscripten_set_mousedown_callback("#window", NULL, 0, mouseEvent); emscripten_set_mouseup_callback("#window", NULL, 0, mouseEvent); emscripten_set_mousemove_callback("#window", NULL, 0, mouseEvent); emscripten_set_resize_callback("#window", NULL, 0, resizeEvent); emscripten_set_main_loop (idleloop, 0, 1); }
EmInputWindow::EmInputWindow(EmRenderWindow& renderWindow) : InputWindow() , m_renderWindow(renderWindow) { emscripten_set_mousemove_callback(0, this, true, [](int eventType, const EmscriptenMouseEvent* mouseEvent, void* window) { return EM_BOOL(static_cast<EmInputWindow*>(window)->injectMouseMove(*mouseEvent)); }); emscripten_set_mousedown_callback(0, this, true, [](int eventType, const EmscriptenMouseEvent* mouseEvent, void* window) { return EM_BOOL(static_cast<EmInputWindow*>(window)->injectMouseDown(*mouseEvent)); }); emscripten_set_mouseup_callback(0, this, true, [](int eventType, const EmscriptenMouseEvent* mouseEvent, void* window) { return EM_BOOL(static_cast<EmInputWindow*>(window)->injectMouseUp(*mouseEvent)); }); emscripten_set_wheel_callback(0, this, true, [](int eventType, const EmscriptenWheelEvent* wheelEvent, void* window) { return EM_BOOL(static_cast<EmInputWindow*>(window)->injectWheel(*wheelEvent)); }); emscripten_set_keydown_callback(0, this, true, [](int eventType, const EmscriptenKeyboardEvent* keyEvent, void* window) { return EM_BOOL(static_cast<EmInputWindow*>(window)->injectKeyDown(*keyEvent)); }); emscripten_set_keyup_callback(0, this, true, [](int eventType, const EmscriptenKeyboardEvent* keyEvent, void* window) { return EM_BOOL(static_cast<EmInputWindow*>(window)->injectKeyUp(*keyEvent)); }); emscripten_set_keypress_callback(0, this, true, [](int eventType, const EmscriptenKeyboardEvent* keyEvent, void* window) { return EM_BOOL(static_cast<EmInputWindow*>(window)->injectKeyPress(*keyEvent)); }); //glfwSetScrollCallback(m_glWindow, [](GLFWwindow* w, double x, double y) { static_cast<GlInputWindow*>(glfwGetWindowUserPointer(w))->injectWheel(x, y); }); //glfwMakeContextCurrent(m_glWindow); //glfwSetInputMode(m_glWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); }
int main() { setupKeys();// setup the HTML key mappings emscripten_set_canvas_size(800, 600); printf("hello world!\n"); std::ifstream f; f.open( "./data/pyramid.PropellerModel", std::ifstream::binary ); if(f.is_open()) printf("file open ok!\n"); else printf("file open not ok :< \n"); engine::sys::addLogger(new game::sys::ConsoleLogger()); printf("initting rendering\n"); gameInstance.initializeRenderer(NULL); printf("starting init()\n"); { engine::file::FileList files; gameInstance.getFileManager()->listFiles(files); engine::file::FileList::FileArray arr = files.getFiles(); LOG_INFO("listing files, count: " << arr.size()); for (unsigned i = 0; i < arr.size(); ++i) LOG_INFO(" * " << arr[i]); } gameInstance.getConsole()->execute("set defaultScene phys"); gameInstance.init(); { engine::file::FileList files; gameInstance.getFileManager()->listFiles(files); engine::file::FileList::FileArray arr = files.getFiles(); LOG_INFO("listing files, count: " << arr.size()); for (unsigned i = 0; i < arr.size(); ++i) LOG_INFO(" * " << arr[i]); } gameInstance.getConsole()->execute("echo OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO"); gameInstance.getConsole()->execute("ls"); gameInstance.getConsole()->execute("filemanagerlist"); gameInstance.getConsole()->execute("listcommands"); gameInstance.getConsole()->execute("listcvars"); gameInstance.getConsole()->execute("systemlist"); gameInstance.getConsole()->execute("ls"); gameInstance.getConsole()->execute("setpos -2.8281 -1.2858 1.918"); gameInstance.getConsole()->execute("bind KEY_W playerup"); gameInstance.getConsole()->execute("bind KEY_S playerdown"); gameInstance.getConsole()->execute("bind KEY_A playerleft"); gameInstance.getConsole()->execute("bind KEY_D playerright"); printf("init done\n"); printf("total of %i systems registered.\n", gameInstance.getSystemManager()->getSystemList().size()); gameInstance.update(); emscripten_set_keydown_callback(NULL, NULL, true, &keyDown); emscripten_set_keyup_callback(NULL, NULL, true, &keyUp); emscripten_set_main_loop(loop, 60, 1); return 0; }
void ofxAppEmscriptenWindow::setup(const ofGLESWindowSettings & settings){ EGLint numConfigs; EGLint majorVersion; EGLint minorVersion; EGLConfig config; EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE, EGL_NONE }; EGLint attribList[] = { EGL_RED_SIZE, EGL_DONT_CARE, EGL_GREEN_SIZE, EGL_DONT_CARE, EGL_BLUE_SIZE, EGL_DONT_CARE, EGL_ALPHA_SIZE, EGL_DONT_CARE, EGL_DEPTH_SIZE, EGL_DONT_CARE, EGL_STENCIL_SIZE, EGL_DONT_CARE, EGL_SAMPLE_BUFFERS, EGL_DONT_CARE, EGL_NONE }; // Get Display display = eglGetDisplay((EGLNativeDisplayType)EGL_DEFAULT_DISPLAY); if ( display == EGL_NO_DISPLAY ){ ofLogError() << "coudln't get display"; return; } // Initialize EGL if ( !eglInitialize(display, &majorVersion, &minorVersion) ){ ofLogError() << "couldn't initialize display"; return; } // Get configs if ( !eglGetConfigs(display, NULL, 0, &numConfigs) ){ ofLogError() << "couldn't get configs"; return; } ofLogNotice("ofxAppEmscriptenWindow") << "Got " << numConfigs << " display configs"; // Choose config if ( !eglChooseConfig(display, attribList, &config, 1, &numConfigs) ){ ofLogError() << "couldn't choose display"; return; } // Create a surface surface = eglCreateWindowSurface(display, config, NULL, NULL); if ( surface == EGL_NO_SURFACE ){ ofLogError() << "couldn't create surface"; return; } // Create a GL context context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs ); if ( context == EGL_NO_CONTEXT ){ ofLogError() << "couldn't create context"; return; } // Make the context current if ( !eglMakeCurrent(display, surface, surface, context) ){ ofLogError() << "couldn't make current display"; return; } setWindowShape(settings.width,settings.height); _renderer = make_shared<ofGLProgrammableRenderer>(this); ((ofGLProgrammableRenderer*)_renderer.get())->setup(2,0); emscripten_set_keydown_callback(0,this,1,&keydown_cb); emscripten_set_keyup_callback(0,this,1,&keyup_cb); emscripten_set_mousedown_callback(0,this,1,&mousedown_cb); emscripten_set_mouseup_callback(0,this,1,&mouseup_cb); emscripten_set_mousemove_callback(0,this,1,&mousemoved_cb); emscripten_set_touchstart_callback(0,this,1,&touch_cb); emscripten_set_touchend_callback(0,this,1,&touch_cb); emscripten_set_touchmove_callback(0,this,1,&touch_cb); emscripten_set_touchcancel_callback(0,this,1,&touch_cb); }