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; }
glm::vec2 ofxAppEmscriptenWindow::getWindowSize(){ int width; int height; int isFullscreen; emscripten_get_canvas_size( &width, &height, &isFullscreen ); return glm::vec2(width,height); }
////////////////////////////////////////////////////////////////////////// // setWindowSize void OsClientHTML5::setWindowSize() { int W = 0; int H = 0; int IsFullScreen = 0; emscripten_get_canvas_size( &W, &H , &IsFullScreen); Width_ = W; Height_ = H; }
void EmRenderWindow::resize() { int width, height, fullscreen; emscripten_get_canvas_size(&width, &height, &fullscreen); m_width = width; m_height = height; }
/* This is called when we need to draw the windows contents */ static gboolean expose(void) { int width, height, isFullscreen; emscripten_get_canvas_size(&width, &height, &isFullscreen); //if (paint_svg(&pd) == FALSE) paint(darea, width, height, NULL); return FALSE; }
EM_BOOL mouse_move_callback(int evType, const EmscriptenMouseEvent* evt, void* userData) { /* rescale (in case canvas is being scaled)*/ double client_w, client_h, xscale, yscale; int canvas_w, canvas_h, canvas_fs; emscripten_get_canvas_size(&canvas_w, &canvas_h, &canvas_fs); emscripten_get_element_css_size(NULL, &client_w, &client_h); xscale = canvas_w/client_w; yscale = canvas_h/client_h; int calc_x = (int)(evt->canvasX*xscale + .5); int calc_y = (int)(evt->canvasY*yscale + .5); UE_LOG(LogHTML5Input, Verbose, TEXT("MouseMoveCB Pos(%d or %d, %d or %d) XRel:%d YRel:%d"), evt->canvasX, calc_x, evt->canvasY, calc_y, evt->movementX, evt->movementY); (*((const TSharedPtr< ICursor >*)userData))->SetPosition(calc_x, calc_y); return 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; }
static void gfx_ctx_emscripten_check_window(void *data, bool *quit, bool *resize, unsigned *width, unsigned *height, unsigned frame_count) { (void)data; (void)frame_count; int iWidth, iHeight, isFullscreen; emscripten_get_canvas_size(&iWidth, &iHeight, &isFullscreen); *width = (unsigned) iWidth; *height = (unsigned) iHeight; *resize = false; if (*width != g_fb_width || *height != g_fb_height) *resize = true; g_fb_width = (unsigned) iWidth; g_fb_height = (unsigned) iHeight; *quit = false; }
static void gfx_ctx_emscripten_check_window(void *data, bool *quit, bool *resize, unsigned *width, unsigned *height, bool is_shutdown) { int input_width; int input_height; int is_fullscreen; emscripten_ctx_data_t *emscripten = (emscripten_ctx_data_t*)data; (void)data; emscripten_get_canvas_size(&input_width, &input_height, &is_fullscreen); *width = (unsigned)input_width; *height = (unsigned)input_height; *resize = false; if (*width != emscripten->fb_width || *height != emscripten->fb_height) *resize = true; emscripten->fb_width = (unsigned)input_width; emscripten->fb_height = (unsigned)input_height; *quit = false; }
void init(init_desc* desc_ptr) { Input::instance.__removeFromDebugList(); log::messageln("initialize oxygine"); if (desc_ptr) desc = *desc_ptr; #ifdef __S3E__ log::messageln("S3E build"); if (!IwGLInit()) { s3eDebugErrorShow(S3E_MESSAGE_CONTINUE, "IwGLInit failed"); return; } //init_ext(); int width = IwGLGetInt(IW_GL_WIDTH); int height = IwGLGetInt(IW_GL_HEIGHT); log::messageln("Screen BPP : %d", s3eSurfaceGetInt(S3E_SURFACE_PIXEL_TYPE) & S3E_SURFACE_PIXEL_SIZE_MASK); log::messageln("Screen Size : %dx%d", width, height); log::messageln("Vendor : %s", (const char*)glGetString(GL_VENDOR)); log::messageln("Renderer : %s", (const char*)glGetString(GL_RENDERER)); const char* version = (const char*)glGetString(GL_VERSION); log::messageln("Version : %s", version); s3ePointerUpdate(); if (s3ePointerGetInt(S3E_POINTER_MULTI_TOUCH_AVAILABLE)) { s3ePointerRegister(S3E_POINTER_TOUCH_EVENT, &pointerTouchEvent, 0); s3ePointerRegister(S3E_POINTER_TOUCH_MOTION_EVENT, &pointerTouchMotionEvent, 0); } else { s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, &pointerEvent, 0); s3ePointerRegister(S3E_POINTER_MOTION_EVENT, &pointerMotionEvent, 0); } s3eDeviceRegister(S3E_DEVICE_UNPAUSE, applicationUnPause, 0); s3eDeviceRegister(S3E_DEVICE_PAUSE, applicationPause, 0); #elif EMSCRIPTEN log::messageln("EMSCRIPTEN build"); if (desc.w == -1 && desc.h == -1) { int fs = 0; emscripten_get_canvas_size(&desc.w, &desc.h, &fs); } if (SDL_Init(SDL_INIT_VIDEO) != 0) { log::error("Unable to initialize SDL: %s\n", SDL_GetError()); } SDL_Surface* screen; screen = SDL_SetVideoMode(desc.w, desc.h, 32, SDL_OPENGL); _displaySize = Point(desc.w, desc.h); emscripten_SDL_SetEventHandler(SDL_eventsHandler, 0); int v = EM_ASM_INT( { var p = navigator.platform; if (p == 'iPad' || p == 'iPhone' || p == 'iPod') return 1; return 0; }, 0);
void init(init_desc *desc_ptr) { Input::instance.__removeFromDebugList(); log::messageln("initialize oxygine"); if (desc_ptr) desc = *desc_ptr; #ifdef __S3E__ log::messageln("S3E build"); if (!IwGLInit()) { s3eDebugErrorShow(S3E_MESSAGE_CONTINUE, "IwGLInit failed"); return; } //init_ext(); int width = IwGLGetInt(IW_GL_WIDTH); int height = IwGLGetInt(IW_GL_HEIGHT); log::messageln("Screen BPP : %d", s3eSurfaceGetInt(S3E_SURFACE_PIXEL_TYPE) & S3E_SURFACE_PIXEL_SIZE_MASK); log::messageln("Screen Size : %dx%d", width, height); log::messageln("Vendor : %s", (const char*)glGetString( GL_VENDOR ) ); log::messageln("Renderer : %s", (const char*)glGetString( GL_RENDERER )); const char *version = (const char*)glGetString( GL_VERSION ); log::messageln( "Version : %s", version); s3ePointerUpdate(); if (s3ePointerGetInt(S3E_POINTER_MULTI_TOUCH_AVAILABLE)) { s3ePointerRegister(S3E_POINTER_TOUCH_EVENT, &pointerTouchEvent, 0); s3ePointerRegister(S3E_POINTER_TOUCH_MOTION_EVENT, &pointerTouchMotionEvent, 0); } else { s3ePointerRegister(S3E_POINTER_BUTTON_EVENT, &pointerEvent, 0); s3ePointerRegister(S3E_POINTER_MOTION_EVENT, &pointerMotionEvent, 0); } s3eDeviceRegister(S3E_DEVICE_UNPAUSE, applicationUnPause, 0); s3eDeviceRegister(S3E_DEVICE_PAUSE, applicationPause, 0); #elif EMSCRIPTEN log::messageln("EMSCRIPTEN build"); if (desc.w == -1 && desc.h == -1) { int fs = 0; emscripten_get_canvas_size(&desc.w, &desc.h, &fs); } if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) { log::error("Unable to initialize SDL: %s\n", SDL_GetError()); } SDL_Surface *screen; screen = SDL_SetVideoMode(desc.w, desc.h, 32, SDL_OPENGL); _displaySize = Point(desc.w, desc.h); emscripten_SDL_SetEventHandler(SDL_eventsHandler, 0); #elif OXYGINE_SDL log::messageln("SDL build"); SDL_Init(SDL_INIT_VIDEO); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 0); //SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); int flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN; #if TARGET_OS_IPHONE flags |= SDL_WINDOW_BORDERLESS; #endif SDL_DisplayMode mode; SDL_GetCurrentDisplayMode(0, &mode); log::messageln("display mode: %d %d", mode.w, mode.h); if (desc.w == -1 && desc.h == -1) { desc.w = 960; desc.h = 640; } if (desc.fullscreen) flags |= SDL_WINDOW_FULLSCREEN; log::messageln("creating window %d %d", desc.w, desc.h); _window = SDL_CreateWindow(desc.title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, desc.w, desc.h, flags); if (!_window) { log::error("can't create window: %s", SDL_GetError()); return; } _context = SDL_GL_CreateContext(_window); if (!_context) { log::error("can't create gl context: %s", SDL_GetError()); return; } SDL_GL_SetSwapInterval(desc.vsync ? 1 : 0); //SDL_SetEventFilter(eventsFilter, 0); #endif file::init(desc.companyName, desc.appName); init2(); }
void FHTML5Application::PollGameDeviceState( const float TimeDelta ) { SDL_Event Event; while (SDL_PollEvent(&Event)) { // Tick Input Interface. switch (Event.type) { case SDL_WINDOWEVENT: { SDL_WindowEvent windowEvent = Event.window; // ignore resized client Height/Width #if PLATFORM_HTML5_BROWSER int fs; emscripten_get_canvas_size(&WindowWidth, &WindowHeight, &fs); UE_LOG(LogHTML5Application, Verbose, TEXT("emscripten_get_canvas_size: Width:%d, Height:%d, Fullscreen:%d"), WindowWidth, WindowHeight, fs); #endif #if PLATFORM_HTML5_WIN32 WindowWidth = windowEvent.data1; WindowHeight = windowEvent.data2; #endif switch (windowEvent.event) { case SDL_WINDOWEVENT_SIZE_CHANGED: { UE_LOG(LogHTML5Application, Verbose, TEXT("WindowSizeChanged: Width:%d, Height:%d"), WindowWidth, WindowHeight); MessageHandler->OnSizeChanged(ApplicationWindow,WindowWidth,WindowHeight, false); MessageHandler->OnResizingWindow(ApplicationWindow); FDisplayMetrics DisplayMetrics; FDisplayMetrics::GetDisplayMetrics(DisplayMetrics); BroadcastDisplayMetricsChanged(DisplayMetrics); } break; case SDL_WINDOWEVENT_RESIZED: { UE_LOG(LogHTML5Application, Verbose, TEXT("WindowResized: Width:%d, Height:%d"), WindowWidth, WindowHeight); MessageHandler->OnResizingWindow(ApplicationWindow); FDisplayMetrics DisplayMetrics; FDisplayMetrics::GetDisplayMetrics(DisplayMetrics); BroadcastDisplayMetricsChanged(DisplayMetrics); } break; case SDL_WINDOWEVENT_ENTER: { UE_LOG(LogHTML5Application, Verbose, TEXT("WindowEnter")); MessageHandler->OnCursorSet(); MessageHandler->OnWindowActivationChanged(ApplicationWindow, EWindowActivation::Activate); WarmUpTicks = 0; } break; case SDL_WINDOWEVENT_LEAVE: { UE_LOG(LogHTML5Application, Verbose, TEXT("WindowLeave")); MessageHandler->OnWindowActivationChanged(ApplicationWindow, EWindowActivation::Deactivate); } break; case SDL_WINDOWEVENT_FOCUS_GAINED: { UE_LOG(LogHTML5Application, Verbose, TEXT("WindowFocusGained")); MessageHandler->OnWindowActivationChanged(ApplicationWindow, EWindowActivation::Activate); WarmUpTicks = 0; } break; case SDL_WINDOWEVENT_FOCUS_LOST: { UE_LOG(LogHTML5Application, Verbose, TEXT("WindowFocusLost")); MessageHandler->OnWindowActivationChanged(ApplicationWindow, EWindowActivation::Deactivate); } break; default: break; } } default: { InputInterface->Tick( TimeDelta,Event, ApplicationWindow); } } } InputInterface->SendControllerEvents(); if ( WarmUpTicks >= 0) WarmUpTicks ++; if ( WarmUpTicks == MaxWarmUpTicks ) { // browsers don't allow locking and hiding to work independently. use warmup ticks after the application has settled // on its mouse lock/visibility status. This is necessary even in cases where the game doesn't want to locking because // the lock status oscillates for few ticks before settling down. This causes a Browser UI pop even when we don't intend to lock. // see http://www.w3.org/TR/pointerlock more for information. #if PLATFORM_HTML5_WIN32 SDL_Window* WindowHandle= SDL_GL_GetCurrentWindow(); if (((FHTML5Cursor*)Cursor.Get())->LockStatus && !((FHTML5Cursor*)Cursor.Get())->CursorStatus) { SDL_SetWindowGrab(WindowHandle, SDL_TRUE); SDL_ShowCursor(SDL_DISABLE); SDL_SetRelativeMouseMode(SDL_TRUE); } else { SDL_SetRelativeMouseMode(SDL_FALSE); SDL_ShowCursor(SDL_ENABLE); SDL_SetWindowGrab(WindowHandle, SDL_FALSE); } #endif #if PLATFORM_HTML5_BROWSER if (((FHTML5Cursor*)Cursor.Get())->LockStatus && !((FHTML5Cursor*)Cursor.Get())->CursorStatus) { UE_LOG(LogHTML5Application, Verbose, TEXT("Request pointer lock")); emscripten_request_pointerlock ( "#canvas" , true); } else { UE_LOG(LogHTML5Application, Verbose, TEXT("Exit pointer lock")); emscripten_exit_pointerlock(); } #endif WarmUpTicks = -1; } }
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; }