Beispiel #1
0
static EM_BOOL _fullscreen_change_callback(int event_type, const EmscriptenFullscreenChangeEvent *event, void *user_data) {

	ERR_FAIL_COND_V(event_type!=EMSCRIPTEN_EVENT_FULLSCREENCHANGE, false);

	OS_JavaScript* os = static_cast<OS_JavaScript*>(user_data);
	String id = String::utf8(event->id);

	// empty id is canvas
	if (id.empty() || id=="canvas") {

		OS::VideoMode vm = os->get_video_mode();
		// this event property is the only reliable information on
		// browser fullscreen state
		vm.fullscreen = event->isFullscreen;

		if (event->isFullscreen) {
			vm.width = event->screenWidth;
			vm.height = event->screenHeight;
			os->set_video_mode(vm);
			emscripten_set_canvas_size(vm.width, vm.height);
		}
		else {
			os->set_video_mode(vm);
			if (!os->is_window_maximized()) {
				os->set_window_size(_windowed_size);
			}
		}
	}
	return false;
}
int main(int argc, char *argv[])
{
    SDL_Surface *screen;

    // Slightly different SDL initialization
    if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) {
        printf("Unable to initialize SDL: %s\n", SDL_GetError());
        return 1;
    }

    // Test 1: Check that initializing video mode with size (0,0) will use the size from the <canvas> element.
    screen = SDL_SetVideoMode( 0, 0, 16, SDL_OPENGL ); // *changed*

    // Test 2: Check that getting current canvas size works.
    int w, h, fs;
    emscripten_get_canvas_size(&w, &h, &fs);
    printf("w:%d,h:%d\n", w,h);
    assert(w == 700);
    assert(h == 200);

    // Test 3: Check that resizing the canvas works as well.
    emscripten_set_canvas_size(640, 480);
    emscripten_get_canvas_size(&w, &h, &fs);
    printf("w:%d,h:%d\n", w,h);
    assert(w == 640);
    assert(h == 480);

    SDL_Quit();
    REPORT_RESULT(1);
    return 0;
}
Beispiel #3
0
	void GlContext::resize(uint32_t _width, uint32_t _height, uint32_t _flags)
	{
#	if BX_PLATFORM_ANDROID
		if (NULL != m_display)
		{
			EGLNativeWindowType nwh = (EGLNativeWindowType )g_platformData.nwh;
			eglMakeCurrent(m_display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
			eglDestroySurface(m_display, m_surface);
			m_surface = eglCreateWindowSurface(m_display, m_config, nwh, NULL);
			BGFX_FATAL(m_surface != EGL_NO_SURFACE, Fatal::UnableToInitialize, "Failed to create surface.");
			EGLBoolean success = eglMakeCurrent(m_display, m_surface, m_surface, m_context);
			BGFX_FATAL(success, Fatal::UnableToInitialize, "Failed to set context.");

			EGLint format;
			eglGetConfigAttrib(m_display, m_config, EGL_NATIVE_VISUAL_ID, &format);
			ANativeWindow_setBuffersGeometry( (ANativeWindow*)g_platformData.nwh, _width, _height, format);
		}
#	elif BX_PLATFORM_EMSCRIPTEN
		emscripten_set_canvas_size(_width, _height);
#	else
		BX_UNUSED(_width, _height);
#	endif // BX_PLATFORM_*

		if (NULL != m_display)
		{
			bool vsync = !!(_flags&BGFX_RESET_VSYNC);
			eglSwapInterval(m_display, vsync ? 1 : 0);
		}
	}
Beispiel #4
0
	void EmRenderWindow::initContext()
	{
		printf("Setting Emscripten Canvas size\n");
		emscripten_set_canvas_size(m_width, m_height);

		EmscriptenWebGLContextAttributes attrs;
		emscripten_webgl_init_context_attributes(&attrs);
		attrs.depth = 1;
		attrs.stencil = 1;
		attrs.antialias = 1;
		attrs.majorVersion = 2;
		attrs.minorVersion = 0;

		assert(emscripten_webgl_get_current_context() == 0);

		printf("Creating Emscripten WebGL context\n");
		m_window = emscripten_webgl_create_context("canvas", &attrs);
		printf("Created Emscripten WebGL context %i\n", m_window);

		emscripten_webgl_make_context_current(m_window);

#if defined TOY_PLATFORM_LINUX || defined TOY_PLATFORM_BSD
		m_nativeHandle = (void*)(uintptr_t)glfwGetX11Window(_window);
#elif defined TOY_PLATFORM_OSX
		m_nativeHandle = glfwGetCocoaWindow(_window);
#elif defined TOY_PLATFORM_WINDOWS
		m_nativeHandle = glfwGetWin32Window(m_glWindow);
#endif
	}
    void Application::run() {
        
#ifndef EMSCRIPTEN
        while (!glfwWindowShouldClose(m_window)) {
            
#else
            int w = 0, h = 0;
            glfwGetFramebufferSize(m_window, &w, &h);
            if (w == 0 || h == 0) {
                printf("setting canvas size");
                emscripten_set_canvas_size(640, 480);
            }
            
            audioUpdate();
#endif
            
            if (m_on) {
                glClearColor(1, 0, 0, 1);
            } else {
                glClearColor(0, 0, 0, 1);
            }
            m_on = !m_on;
            
            glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
            glfwSwapBuffers(m_window);// Swap front and back buffers
            glfwPollEvents();       // Poll for and process events
#ifndef EMSCRIPTEN
        }
#endif
    }
int main(int argc, char *argv[])
{
    emscripten_set_canvas_size(800, 600);
    rarch_main(argc, argv);
    emscripten_set_main_loop(emscripten_mainloop, g_settings.video.vsync ? 0 : INT_MAX, 1);

    return 0;
}
int main(int argc, char *argv[])
{
   settings_t *settings = config_get_ptr();

   emscripten_set_canvas_size(800, 600);
   rarch_main(argc, argv, NULL);
   emscripten_set_main_loop(emscripten_mainloop,
         settings->video.vsync ? 0 : INT_MAX, 1);

   return 0;
}
Beispiel #8
0
int EMSCRIPTEN_KEEPALIVE setscreensize(int yes)
{
    int w, h, f;

    emscripten_get_canvas_size(&w, &h, &f);
    if (1 || f == 0) {
	w = emscripten_run_script_int("window.innerWidth");
	h = emscripten_run_script_int("window.innerHeight");
	emscripten_set_canvas_size(w, h);
    }

    expose();
    return yes;
}
void PlatformResizeGLContext( FPlatformOpenGLDevice* Device, FPlatformOpenGLContext* Context, uint32 SizeX, uint32 SizeY, bool bFullscreen, bool bWasFullscreen, GLenum BackBufferTarget, GLuint BackBufferResource)
{
	check(Context);
	VERIFY_GL_SCOPE();

	// we can't resize with the win32 emu right now -- we have no way of resizing the window.
#if !PLATFORM_HTML5_WIN32
	emscripten_set_canvas_size(SizeX, SizeY);
#endif

	glViewport(0, 0, SizeX, SizeY);
	//@todo-mobile Do we need to clear here?
	glClearColor(0, 0, 0, 0);
	glClear(GL_COLOR_BUFFER_BIT);

}
Beispiel #10
0
static EM_BOOL _browser_resize_callback(int event_type, const EmscriptenUiEvent *ui_event, void *user_data) {

	ERR_FAIL_COND_V(event_type!=EMSCRIPTEN_EVENT_RESIZE, false);

	OS_JavaScript* os = static_cast<OS_JavaScript*>(user_data);

	// the order in which _browser_resize_callback and
	// _fullscreen_change_callback are called is browser-dependent,
	// so try adjusting for fullscreen in both
	if (os->is_window_fullscreen() || os->is_window_maximized()) {

		OS::VideoMode vm = os->get_video_mode();
		vm.width = ui_event->windowInnerWidth;
		vm.height = ui_event->windowInnerHeight;
		os->set_video_mode(vm);
		emscripten_set_canvas_size(ui_event->windowInnerWidth, ui_event->windowInnerHeight);
	}
	return false;
}
Beispiel #11
0
	void GlContext::resize(uint32_t _width, uint32_t _height, uint32_t _flags)
	{
#	if BX_PLATFORM_ANDROID
		if (NULL != m_display)
		{
			EGLint format;
			eglGetConfigAttrib(m_display, m_config, EGL_NATIVE_VISUAL_ID, &format);
			ANativeWindow_setBuffersGeometry( (ANativeWindow*)g_platformData.nwh, _width, _height, format);
		}
#	elif BX_PLATFORM_EMSCRIPTEN
		emscripten_set_canvas_size(_width, _height);
#	else
		BX_UNUSED(_width, _height);
#	endif // BX_PLATFORM_*

		if (NULL != m_display)
		{
			bool vsync = !!(_flags&BGFX_RESET_VSYNC);
			eglSwapInterval(m_display, vsync ? 1 : 0);
		}
	}
Beispiel #12
0
void onWindowResize(int newWidth, int newHeight, void * /*userData*/)
{
  emscripten_set_canvas_size(newWidth, newHeight);
  // This probably needs that any extra elements are removed from the default shell.html.
  nglscene->resize(newWidth,newHeight);
}
int main()
{
    emscripten_set_canvas_size( 100, 100 );

    EmscriptenWebGLContextAttributes attrs;
    emscripten_webgl_init_context_attributes(&attrs);

    attrs.enableExtensionsByDefault = 1;
    attrs.majorVersion = 2;
    attrs.minorVersion = 0;

    EMSCRIPTEN_WEBGL_CONTEXT_HANDLE context = emscripten_webgl_create_context( 0, &attrs );
    if (!context)
    {
        attrs.majorVersion = 1;
        context = emscripten_webgl_create_context( 0, &attrs );
        if (context) printf("Skipping test: WebGL 2.0 is not available.\n");
        else printf("Test failed: WebGL is not available!\n");
#ifdef REPORT_RESULT
        // We did not have WebGL 2, but were able to init WebGL 1? In that case, gracefully skip this test with the current browser not supporting this one.
        int result = context ? 0 : 12365;
        REPORT_RESULT();
#endif
        return 0;
    }
    emscripten_webgl_make_context_current(context);


    // Textures
    //
    int mips = 10;
    int sizeO = 512;

    unsigned short* data = new unsigned short[ 512 * 512 * 4 ];
    //memset( data, 0, 512 * 512 * 4 );

    // Create texture 1
    GLuint tex1;
    GL_CALL( glGenTextures( 1, &tex1 ) );
    GL_CALL( glBindTexture( GL_TEXTURE_CUBE_MAP, tex1 ) );
    for( int i=0; i<6; ++i )
    {
        GL_CALL( glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, 0, GL_RGBA16F, sizeO, sizeO, 0, GL_RGBA, GL_HALF_FLOAT, NULL ) );
    }
    GL_CALL( glGenerateMipmap( GL_TEXTURE_CUBE_MAP ) );

    for( int i=0; i<6; ++i )
        GL_CALL( glTexSubImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, 0, 0, 0, sizeO, sizeO, GL_RGBA, GL_HALF_FLOAT, data ) );

    delete [] data;

    // Create texture 2
    GLuint tex2;
    GL_CALL( glGenTextures( 1, &tex2 ) );
    GL_CALL( glBindTexture( GL_TEXTURE_CUBE_MAP, tex2 ) );
    for( int i=0; i<6; ++i )
    {
        GL_CALL( glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, 0, GL_RGBA16F, sizeO, sizeO, 0, GL_RGBA, GL_HALF_FLOAT, NULL ) );
    }
    GL_CALL( glGenerateMipmap( GL_TEXTURE_CUBE_MAP ) );



    // FBOs
    //

    // Create FBO 1
    GLuint fbo1;
    GL_CALL( glGenFramebuffers( 1, &fbo1 ) );
    GL_CALL( glBindFramebuffer( GL_FRAMEBUFFER, fbo1 ) );
    for( int level=0; level<mips; ++level )
    {
        for( int i=0; i<6; ++i )
        {
            GL_CALL( glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, tex1, level ) );
        }
    }
    IsFramebufferValid( GL_FRAMEBUFFER );

    // Create FBO 2
    GLuint fbo2;
    GL_CALL( glGenFramebuffers( 1, &fbo2 ) );
    GL_CALL( glBindFramebuffer( GL_FRAMEBUFFER, fbo2 ) );
    for( int level=0; level<mips; ++level )
    {
        for( int i=0; i<6; ++i )
        {
            GL_CALL( glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, tex2, level ) );

            glViewport( 0, 0, sizeO, sizeO );
        }
    }
    IsFramebufferValid( GL_FRAMEBUFFER );


    // Copy FBO 1 to 2
    int nw = sizeO;
    GL_CALL( glBindFramebuffer( GL_READ_FRAMEBUFFER, fbo1 ) );
    GL_CALL( glBindFramebuffer( GL_DRAW_FRAMEBUFFER, fbo2 ) );
    for( int level=0; level<mips; ++level )
    {
        for( int i=0; i<6; ++i )
        {
            GL_CALL( glFramebufferTexture2D( GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, tex1, level ) );
            GL_CALL( glFramebufferTexture2D( GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, tex2, level ) );

            glViewport( 0, 0, nw, nw );

            GL_CALL( glBlitFramebuffer( 0, 0, nw, nw, 0, 0, nw, nw, GL_COLOR_BUFFER_BIT, GL_NEAREST ) );
        }

        nw /= 2;
    }

    GL_CALL( glBindFramebuffer( GL_READ_FRAMEBUFFER, 0 ) );
    GL_CALL( glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 ) );  

#ifdef REPORT_RESULT
    int result = 0;
    REPORT_RESULT();
#endif

  return 0;
}
Beispiel #14
0
void GlContext::create(uint32_t _width, uint32_t _height)
{
    m_eglLibrary = eglOpen();

    BX_UNUSED(_width, _height);
    EGLNativeDisplayType ndt = EGL_DEFAULT_DISPLAY;
    EGLNativeWindowType nwt = (EGLNativeWindowType)NULL;
#	if BX_PLATFORM_WINDOWS
    ndt = GetDC(g_bgfxHwnd);
    nwt = g_bgfxHwnd;
#	endif // BX_PLATFORM_
    m_display = eglGetDisplay(ndt);
    BGFX_FATAL(m_display != EGL_NO_DISPLAY, Fatal::UnableToInitialize, "Failed to create display %p", m_display);

    EGLint major = 0;
    EGLint minor = 0;
    EGLBoolean success = eglInitialize(m_display, &major, &minor);
    BGFX_FATAL(success && major >= 1 && minor >= 3, Fatal::UnableToInitialize, "Failed to initialize %d.%d", major, minor);

    EGLint attrs[] =
    {
        EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,

#	if BX_PLATFORM_ANDROID
        EGL_DEPTH_SIZE, 16,
#	else
        EGL_DEPTH_SIZE, 24,
#	endif // BX_PLATFORM_
        EGL_STENCIL_SIZE, 8,

        EGL_NONE
    };

    EGLint numConfig = 0;
    EGLConfig config;
    success = eglChooseConfig(m_display, attrs, &config, 1, &numConfig);
    BGFX_FATAL(success, Fatal::UnableToInitialize, "eglChooseConfig");

#	if BX_PLATFORM_ANDROID
    EGLint format;
    eglGetConfigAttrib(m_display, config, EGL_NATIVE_VISUAL_ID, &format);
    ANativeWindow_setBuffersGeometry(g_bgfxAndroidWindow, _width, _height, format);
    nwt = g_bgfxAndroidWindow;
#	endif // BX_PLATFORM_ANDROID

    m_surface = eglCreateWindowSurface(m_display, config, nwt, NULL);
    BGFX_FATAL(m_surface != EGL_NO_SURFACE, Fatal::UnableToInitialize, "Failed to create surface.");

    EGLint contextAttrs[] =
    {
#	if BGFX_CONFIG_RENDERER_OPENGLES >= 30
        EGL_CONTEXT_CLIENT_VERSION, 3,
#	elif BGFX_CONFIG_RENDERER_OPENGLES
        EGL_CONTEXT_CLIENT_VERSION, 2,
#	endif // BGFX_CONFIG_RENDERER_

        EGL_NONE
    };

    m_context = eglCreateContext(m_display, config, EGL_NO_CONTEXT, contextAttrs);
    BGFX_FATAL(m_context != EGL_NO_CONTEXT, Fatal::UnableToInitialize, "Failed to create context.");

    success = eglMakeCurrent(m_display, m_surface, m_surface, m_context);
    BGFX_FATAL(success, Fatal::UnableToInitialize, "Failed to set context.");

    eglSwapInterval(m_display, 0);

#	if BX_PLATFORM_EMSCRIPTEN
    emscripten_set_canvas_size(_width, _height);
#	endif // BX_PLATFORM_EMSCRIPTEN

    import();
}
Beispiel #15
0
	void GlContext::create(uint32_t _width, uint32_t _height)
	{
#	if BX_PLATFORM_RPI
		bcm_host_init();
#	endif // BX_PLATFORM_RPI

		m_eglLibrary = eglOpen();

		if (NULL == g_platformData.context)
		{
			BX_UNUSED(_width, _height);
			EGLNativeDisplayType ndt = (EGLNativeDisplayType)g_platformData.ndt;
			EGLNativeWindowType  nwh = (EGLNativeWindowType )g_platformData.nwh;

#	if BX_PLATFORM_WINDOWS
			if (NULL == g_platformData.ndt)
			{
				ndt = GetDC( (HWND)g_platformData.nwh);
			}
#	endif // BX_PLATFORM_WINDOWS

			m_display = eglGetDisplay(ndt);
			BGFX_FATAL(m_display != EGL_NO_DISPLAY, Fatal::UnableToInitialize, "Failed to create display %p", m_display);

			EGLint major = 0;
			EGLint minor = 0;
			EGLBoolean success = eglInitialize(m_display, &major, &minor);
			BGFX_FATAL(success && major >= 1 && minor >= 3, Fatal::UnableToInitialize, "Failed to initialize %d.%d", major, minor);

			BX_TRACE("EGL info:");
			const char* clientApis = eglQueryString(m_display, EGL_CLIENT_APIS);
			BX_TRACE("   APIs: %s", clientApis); BX_UNUSED(clientApis);

			const char* vendor = eglQueryString(m_display, EGL_VENDOR);
			BX_TRACE(" Vendor: %s", vendor); BX_UNUSED(vendor);

			const char* version = eglQueryString(m_display, EGL_VERSION);
			BX_TRACE("Version: %s", version); BX_UNUSED(version);

			const char* extensions = eglQueryString(m_display, EGL_EXTENSIONS);
			BX_TRACE("Supported EGL extensions:");
			dumpExtensions(extensions);

			EGLint attrs[] =
			{
				EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,

#	if BX_PLATFORM_ANDROID
				EGL_DEPTH_SIZE, 16,
#	else
				EGL_DEPTH_SIZE, 24,
#	endif // BX_PLATFORM_
				EGL_STENCIL_SIZE, 8,

				EGL_NONE
			};

			EGLint numConfig = 0;
			success = eglChooseConfig(m_display, attrs, &m_config, 1, &numConfig);
			BGFX_FATAL(success, Fatal::UnableToInitialize, "eglChooseConfig");

#	if BX_PLATFORM_ANDROID

			EGLint format;
			eglGetConfigAttrib(m_display, m_config, EGL_NATIVE_VISUAL_ID, &format);
			ANativeWindow_setBuffersGeometry( (ANativeWindow*)g_platformData.nwh, _width, _height, format);

#	elif BX_PLATFORM_RPI
			DISPMANX_DISPLAY_HANDLE_T dispmanDisplay = vc_dispmanx_display_open(0);
			DISPMANX_UPDATE_HANDLE_T  dispmanUpdate  = vc_dispmanx_update_start(0);

			VC_RECT_T dstRect = { 0, 0, _width,        _height       };
			VC_RECT_T srcRect = { 0, 0, _width  << 16, _height << 16 };

			DISPMANX_ELEMENT_HANDLE_T dispmanElement = vc_dispmanx_element_add(dispmanUpdate
				, dispmanDisplay
				, 0
				, &dstRect
				, 0
				, &srcRect
				, DISPMANX_PROTECTION_NONE
				, NULL
				, NULL
				, DISPMANX_NO_ROTATE
				);

			s_dispmanWindow.element = dispmanElement;
			s_dispmanWindow.width   = _width;
			s_dispmanWindow.height  = _height;
			nwh = &s_dispmanWindow;

			vc_dispmanx_update_submit_sync(dispmanUpdate);
#	endif // BX_PLATFORM_ANDROID

			m_surface = eglCreateWindowSurface(m_display, m_config, nwh, NULL);
			BGFX_FATAL(m_surface != EGL_NO_SURFACE, Fatal::UnableToInitialize, "Failed to create surface.");

			const bool hasEglKhrCreateContext = !!bx::findIdentifierMatch(extensions, "EGL_KHR_create_context");
			const bool hasEglKhrNoError       = !!bx::findIdentifierMatch(extensions, "EGL_KHR_create_context_no_error");

			for (uint32_t ii = 0; ii < 2; ++ii)
			{
				bx::StaticMemoryBlockWriter writer(s_contextAttrs, sizeof(s_contextAttrs) );

				EGLint flags = 0;

				if (hasEglKhrCreateContext)
				{
					bx::write(&writer, EGLint(EGL_CONTEXT_MAJOR_VERSION_KHR) );
					bx::write(&writer, EGLint(BGFX_CONFIG_RENDERER_OPENGLES / 10) );

					bx::write(&writer, EGLint(EGL_CONTEXT_MINOR_VERSION_KHR) );
					bx::write(&writer, EGLint(BGFX_CONFIG_RENDERER_OPENGLES % 10) );

					flags |= BGFX_CONFIG_DEBUG && hasEglKhrNoError ? 0
						| EGL_CONTEXT_FLAG_NO_ERROR_BIT_KHR
						: 0
						;

					if (0 == ii)
					{
						flags |= BGFX_CONFIG_DEBUG ? 0
							| EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR
//							| EGL_OPENGL_ES3_BIT_KHR
							: 0
							;

						bx::write(&writer, EGLint(EGL_CONTEXT_FLAGS_KHR) );
						bx::write(&writer, flags);
					}
				}
				else
				{
					bx::write(&writer, EGLint(EGL_CONTEXT_CLIENT_VERSION) );
					bx::write(&writer, 2);
				}

				bx::write(&writer, EGLint(EGL_NONE) );

				m_context = eglCreateContext(m_display, m_config, EGL_NO_CONTEXT, s_contextAttrs);
				if (NULL != m_context)
				{
					break;
				}

				BX_TRACE("Failed to create EGL context with EGL_CONTEXT_FLAGS_KHR (%08x).", flags);
			}

			BGFX_FATAL(m_context != EGL_NO_CONTEXT, Fatal::UnableToInitialize, "Failed to create context.");

			success = eglMakeCurrent(m_display, m_surface, m_surface, m_context);
			BGFX_FATAL(success, Fatal::UnableToInitialize, "Failed to set context.");
			m_current = NULL;

			eglSwapInterval(m_display, 0);
		}

#	if BX_PLATFORM_EMSCRIPTEN
		emscripten_set_canvas_size(_width, _height);
#	endif // BX_PLATFORM_EMSCRIPTEN

		import();
	}
void ofxAppEmscriptenWindow::setWindowShape(int w, int h){
	emscripten_set_canvas_size(w,h);
}
Beispiel #17
0
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;
}
Beispiel #18
0
int main(int argc, char *argv[])
{
    SDL_Surface *screen;

    // Slightly different SDL initialization
    if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) {
        printf("Unable to initialize SDL: %s\n", SDL_GetError());
        return 1;
    }

    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // *new*

#ifdef __EMSCRIPTEN__
    // Test 1: Check that initializing video mode with size (0,0) will use the size from the <canvas> element.
    screen = SDL_SetVideoMode( 0, 0, 16, SDL_OPENGL ); // *changed*

    // Test 2: Check that getting current canvas size works.
    int w, h, fs;
    emscripten_get_canvas_size(&w, &h, &fs);
    printf("w:%d,h:%d\n", w,h);
    assert(w == 700);
    assert(h == 200);
    
    // Test 3: Check that resizing the canvas works as well.
    emscripten_set_canvas_size(640, 480);
    // Set the OpenGL state after creating the context with SDL_SetVideoMode
#else
    screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL ); // *changed*
#endif

     if ( !screen ) {
        printf("Unable to set video mode: %s\n", SDL_GetError());
        return 1;
    }

    glClearColor( 0, 0, 0, 0 );

    glEnable( GL_TEXTURE_2D ); // Needed when we're using the fixed-function pipeline.

    glViewport( 0, 0, 640, 480 );

    glMatrixMode( GL_PROJECTION );
    glPushMatrix(); // just for testing
    glLoadIdentity();

    glOrtho( 0, 640, 480, 0, -1, 1 );

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    // Load the OpenGL texture

    GLuint texture; // Texture object handle
    SDL_Surface *surface; // Gives us the information to make the texture

    if ( (surface = IMG_Load("screenshot.png")) ) {

        // Check that the image's width is a power of 2
        if ( (surface->w & (surface->w - 1)) != 0 ) {
            printf("warning: image.bmp's width is not a power of 2\n");
        }

        // Also check if the height is a power of 2
        if ( (surface->h & (surface->h - 1)) != 0 ) {
            printf("warning: image.bmp's height is not a power of 2\n");
        }

        // Have OpenGL generate a texture object handle for us
        glGenTextures( 1, &texture );

        // Bind the texture object
        glBindTexture( GL_TEXTURE_2D, texture );

        // Set the texture's stretching properties
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
        glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

        //SDL_LockSurface(surface);

        // Add some greyness
        memset(surface->pixels, 0x66, surface->w*surface->h);

        // Edit the texture object's image data using the information SDL_Surface gives us
        glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0,
                      GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels );

        //SDL_UnlockSurface(surface);
    }
    else {
        printf("SDL could not load image.bmp: %s\n", SDL_GetError());
        SDL_Quit();
        return 1;
    }

    // Free the SDL_Surface only if it was successfully created
    if ( surface ) {
        SDL_FreeSurface( surface );
    }

    // Clear the screen before drawing
    glClear( GL_COLOR_BUFFER_BIT );

    // Bind the texture to which subsequent calls refer to
    glBindTexture( GL_TEXTURE_2D, texture );

    glBegin( GL_QUADS );
        glTexCoord2i( 0, 0 ); glVertex3f( 10, 10, 0 );
        glTexCoord2i( 1, 0 ); glVertex3f( 300, 10, 0 );
        glTexCoord2i( 1, 1 ); glVertex3f( 300, 128, 0 );
        glTexCoord2i( 0, 1 ); glVertex3f( 10, 128, 0 );

        glTexCoord2f( 0, 0.5 ); glVertex3f( 410, 10, 0 );
        glTexCoord2f( 1, 0.5 ); glVertex3f( 600, 10, 0 );
        glTexCoord2f( 1, 1   ); glVertex3f( 630, 200, 0 );
        glTexCoord2f( 0.5, 1 ); glVertex3f( 310, 250, 0 );
    glEnd();

    glBegin( GL_TRIANGLE_STRIP );
        glTexCoord2i( 0, 0 ); glVertex3f( 100, 300, 0 );
        glTexCoord2i( 1, 0 ); glVertex3f( 300, 300, 0 );
        glTexCoord2i( 1, 1 ); glVertex3f( 300, 400, 0 );
        glTexCoord2i( 0, 1 ); glVertex3f( 500, 410, 0 );
    glEnd();

    glDisable(GL_TEXTURE_2D);

    glColor3ub(90, 255, 255);
    glBegin( GL_QUADS );
        glVertex3f( 10, 410, 0 );
        glVertex3f( 300, 410, 0 );
        glVertex3f( 300, 480, 0 );
        glVertex3f( 10, 470, 0 );
    glEnd();

    glBegin( GL_QUADS );
        glColor3f(1.0, 0, 1.0);   glVertex3f( 410, 410, 0 );
        glColor3f(0, 1.0, 0);     glVertex3f( 600, 410, 0 );
        glColor3f(0, 0, 1.0);     glVertex3f( 600, 480, 0 );
        glColor3f(1.0, 1.0, 1.0); glVertex3f( 410, 470, 0 );
    glEnd();

    SDL_GL_SwapBuffers();

#ifndef __EMSCRIPTEN__
    // Wait for 3 seconds to give us a chance to see the image
    SDL_Delay(3000);
#endif

    // Now we can delete the OpenGL texture and close down SDL
    glDeleteTextures( 1, &texture );

    SDL_Quit();

    return 0;
}