Exemple #1
0
		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);
}
FHTML5Application::FHTML5Application()
    : GenericApplication( MakeShareable( new FHTML5Cursor() ) )
    , ApplicationWindow(FHTML5Window::Make())
    , InputInterface( FHTML5InputInterface::Create(MessageHandler, Cursor ) )
    , WarmUpTicks(-1)
{

#if PLATFORM_HTML5_BROWSER
    // full screen will only be requested after the first click after the window gains focus.
    // the problem is that because of security/UX reasons browsers don't allow pointer lock in main loop
    // but only through callbacks generated by browser.

    // work around emscripten bug where deffered browser requests are not called if there are no callbacks.
    emscripten_set_mousedown_callback("#canvas",0,1,mouse_callback);
    emscripten_set_pointerlockchange_callback(0,0,true,pointerlockchange_callback);
#endif

}
Exemple #4
0
	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);
	}
Exemple #5
0
void application::init_context()
{
  auto attrs = EmscriptenWebGLContextAttributes{};
  attrs.stencil = EM_TRUE;
  attrs.enableExtensionsByDefault = EM_FALSE;

  emscripten_webgl_init_context_attributes(&attrs);

  const auto ctx = emscripten_webgl_create_context(canvas_target, &attrs);

  emscripten_webgl_make_context_current(ctx);

  glctx = ctx;

  emscripten_webgl_enable_extension(glctx, "ANGLE_instanced_arrays");

  emscripten_set_mousedown_callback(
   canvas_target, this, false, &enable_drag_handler);
  emscripten_set_touchstart_callback(
   canvas_target, this, false, &enable_drag_handler);

  emscripten_set_mouseup_callback(
   canvas_target, this, false, &disable_drag_handler);
  emscripten_set_mouseleave_callback(
   canvas_target, this, false, &disable_drag_handler);
  emscripten_set_mouseout_callback(
   canvas_target, this, false, &disable_drag_handler);
  emscripten_set_touchend_callback(
   canvas_target, this, false, &disable_drag_handler);
  emscripten_set_touchcancel_callback(
   canvas_target, this, false, &disable_drag_handler);

  emscripten_set_mousemove_callback(
   canvas_target, this, false, &mouse_move_handler);
  emscripten_set_touchmove_callback(
   canvas_target, this, false, &mouse_move_handler);
};
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);
}