FMatrix OSVRHMDDescription::GetProjectionMatrix(EEye Eye) const { // @TODO: a proper stereo projection matrix should be calculated const float ProjectionCenterOffset = 0.151976421f; const float PassProjectionOffset = (Eye == LEFT_EYE) ? ProjectionCenterOffset : -ProjectionCenterOffset; #if 1 const float HalfFov = FMath::DegreesToRadians(GetFov(Eye).X) / 2.f; const float InWidth = GetDisplaySize(Eye).X; const float InHeight = GetDisplaySize(Eye).Y; const float XS = 1.0f / tan(HalfFov); const float YS = InWidth / tan(HalfFov) / InHeight; #else const float HalfFov = 2.19686294f / 2.f; const float InWidth = 640.f; const float InHeight = 480.f; const float XS = 1.0f / tan(HalfFov); const float YS = InWidth / tan(HalfFov) / InHeight; #endif const float InNearZ = GNearClippingPlane; return FMatrix( FPlane(XS, 0.0f, 0.0f, 0.0f), FPlane(0.0f, YS, 0.0f, 0.0f), FPlane(0.0f, 0.0f, 0.0f, 1.0f), FPlane(0.0f, 0.0f, InNearZ, 0.0f)) * FTranslationMatrix(FVector(PassProjectionOffset, 0, 0)); }
FVector2D OSVRHMDDescription::GetResolution() const { FVector2D LeftDisplay = GetDisplaySize(LEFT_EYE); FVector2D RightDisplay = GetDisplaySize(RIGHT_EYE); FVector2D Resolution; Resolution.X = LeftDisplay.X + RightDisplay.X; Resolution.Y = FMath::Max(LeftDisplay.Y, RightDisplay.Y); return Resolution; }
bool ZGame::Init_GraphicMode(ZLog * InitLog) { ZString LogMsg; InitLog->Log(1, ZLog::INFO, "Starting : Graphics Mode Init"); // OpenGl Attibutes SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 ); SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 ); SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // Getting system info #if SDL1 const SDL_VideoInfo* info = NULL; info = SDL_GetVideoInfo( ); DesktopResolution.x = info->current_w; DesktopResolution.y = info->current_h; #else DesktopResolution.x = 1024; DesktopResolution.y = 768; #endif //LogMsg << "Info : SDL Infos [current_w:"<<info->current_w<<"][current_h:"<<info->current_h<<"][BitsPerPixel:"<<info->vfmt->BitsPerPixel<<"]"; InitLog->Log(3, ZLog::IMINFO, LogMsg); // Flags like Fullscreen attributes //Uint32 Flags = SDL_OPENGL; //if (Settings_Hardware->Setting_FullScreen) Flags |= SDL_FULLSCREEN; //// else Flags |= SDL_RESIZABLE; // §§§ Todo : Write better code. // Windows High DPI Quick Workaround in automatic mode. // That's an emergency workaround preventing Blackvoxel to fail on high DPI screens. // It could also mitigate some problems with multiple screens. // Doing a better work will need some interface rework and experimentations with high DPI screens we don't have at this time. // Note we use a bad way for detection as compiling also lacking windows 8 headers at this time. { uint32_t w, h; GetDisplaySize(&w, &h); DesktopResolution.x = w; DesktopResolution.y = h; } #ifdef ZENV_OS_WINDOWS if ( (DesktopResolution.x >= 2560 && DesktopResolution.y >= 1600) && (Settings_Hardware->Setting_Resolution_h == 0 && Settings_Hardware->Setting_Resolution_v == 0)) { // Divide resolutions by 2 because it will be upscalled by Windows 8 DesktopResolution.x >>= 1; DesktopResolution.y >>= 1; // Force windowed mode because full screen is broken with windows GUI scalling. //Flags &= ~ SDL_FULLSCREEN; }
HRESULT CMainWindow::ConfigureWindow(uint uiResX, uint uiResY, bool bFScreen) { DWORD dw_style = WS_VISIBLE; DWORD dw_style_ex = WS_EX_APPWINDOW; if (bFScreen) dw_style |= WS_POPUP; else dw_style |= WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; if (SetWindowLong(_hWnd, GWL_EXSTYLE, dw_style_ex) == 0) { _pEngineCore->AddToLog("Can't change window styleEx.", true); return E_ABORT; } if (SetWindowLong(_hWnd, GWL_STYLE, dw_style) == 0) { _pEngineCore->AddToLog("Can't change window style.", true); return E_ABORT; } uint desktop_width = 0, desktop_height = 0; RECT rc = {0, 0, uiResX, uiResY}; int top_x = 0, top_y = 0; AdjustWindowRectEx(&rc, dw_style , FALSE, dw_style_ex); if(!bFScreen) { GetDisplaySize(desktop_width, desktop_height); top_x = (int)(desktop_width - (rc.right - rc.left))/2, top_y = (int)(desktop_height - (rc.bottom - rc.top))/2; if (top_x < 0) top_x = 0; if (top_y < 0) top_y = 0; } SetWindowPos(_hWnd, HWND_TOP, top_x, top_y, rc.right - rc.left, rc.bottom - rc.top, SWP_FRAMECHANGED); SetCursorPos(top_x + (rc.right - rc.left)/2, top_y + (rc.bottom - rc.top)/2); if (IsWindowVisible(_hWnd) == FALSE) ShowWindow(_hWnd, SW_SHOWNA); SetForegroundWindow(_hWnd); return S_OK; }
HRESULT CALLBACK CCore::InitializeEngine(uint uiResX, uint uiResY, const char* pcApplicationName, E_ENGINE_INIT_FLAGS eInitFlags) { if (!(eInitFlags & EIF_NO_LOGGING)) { _clLogFile.setf(ios_base::right, ios_base::adjustfield); _clLogFile.open("log.txt", ios::out|ios::trunc); TSysTimeAndDate time; GetLocalTimaAndDate(time); _clLogFile << "JTS Engine Log File" << endl; _clLogFile << "Log Started at " << time.ui16Day << "." << time.ui16Month << "." << time.ui16Year << "." << endl; } if (SUCCEEDED(_pMainWindow->InitWindow(&_clDelMLoop, &_clDelMProc))) { _pMainWindow->SetCaption(pcApplicationName); if ( (eInitFlags & EIF_NATIVE_RESOLUTION) && (eInitFlags & EIF_FULL_SCREEN)) GetDisplaySize(uiResX, uiResY); if (FAILED(_pMainWindow->ConfigureWindow(uiResX, uiResY, eInitFlags & EIF_FULL_SCREEN))) return E_ABORT; _pInput = new CInput(this); AddToLog("Engine initialized."); if (!_clDelInit.IsNull()) { AddToLog("Calling user initialization procedure..."); _clDelInit.Invoke(); AddToLog("Done."); } _ui64TimeOld = GetPerfTimer()/1000 - _uiProcessInterval; return _pMainWindow->BeginMainLoop(); } else return E_ABORT; }
SaneWinMain(argc, argv ) //int main( int argc, char **argv ) { int x = 0; int y = 0; uint32_t width, height; int w, h; g.pdi = GetDisplayInterface(); g.pii = GetImageInterface(); RegisterIcon( NULL ); GetDisplaySize( &width, &height ); w = width; h = height; y = x = 0; { int state = 0; int arg; g.fade_in = 500; g.show_time = 1000; for( arg = 1; arg < argc; arg++ ) { if( argv[arg][0] == '-' ) { if( argv[arg][1] == 'i' ) { g.flags.bShowInverted = 1; } else { switch( state ) { case 0: x = atoi( argv[arg]+1 ); break; case 1: y = atoi( argv[arg]+1 ); break; case 2: w = atoi( argv[arg]+1 ); break; case 3: h = atoi( argv[arg]+1 ); break; case 4: g.show_time = atoi( argv[arg]+1 ); break; case 5: g.fade_in = atoi( argv[arg]+1 ); break; } state++; } } else { Image x = LoadImageFile( argv[arg] ); if( x ) { g.nImages++; AddLink( &g.images, x ); } } } } if( g.nImages ) { g.displays[0] = OpenDisplaySizedAt( DISPLAY_ATTRIBUTE_LAYERED|DISPLAY_ATTRIBUTE_CHILD|DISPLAY_ATTRIBUTE_NO_MOUSE|DISPLAY_ATTRIBUTE_NO_AUTO_FOCUS , w //width , h //height , x //0 , y //0 ); g.displays[1] = OpenDisplaySizedAt( DISPLAY_ATTRIBUTE_LAYERED|DISPLAY_ATTRIBUTE_CHILD|DISPLAY_ATTRIBUTE_NO_MOUSE|DISPLAY_ATTRIBUTE_NO_AUTO_FOCUS , w //width , h //height , x //0 , y //0 ); SetRedrawHandler( g.displays[0], Output, 0 ); SetRedrawHandler( g.displays[1], Output, 1 ); if( g.nImages > 1 ) { target_in_start = GetTickCount(); AddTimer( 33, tick, 0 ); } else { //lprintf( "Show the first and only the first image." ); g.is_up[0] = 1; RestoreDisplay( g.displays[0] ); UpdateDisplay( g.displays[0] ); } while( 1 ) WakeableSleep( 10000 ); } else { } return 0; }
int main( void ) { uint32_t width, height; uint32_t imagecount = 0; uint32_t testimagesatinitialization = 0; Image blank; srand( time( NULL ) ); for(width=0; width< NUM_REELS; width++) { g.uiSpeedCounter[width] = 0; g.uiSpeedStep[width] = 2; g.idx[width]= 0; } g.pdi = GetDisplayInterface(); g.pii = GetImageInterface(); //SetSystemLog( SYSLOG_FILE, stdout ); SetSystemLoggingLevel( 1000 + LOG_NOISE); GetDisplaySize( &width, &height );; g.render = OpenDisplaySizedAt( 0, width, height, 0, 0 ); UpdateDisplay(g.render); g.surface = GetDisplayImage( g.render ); SetMouseHandler( g.render, MouseMethod, 0 ); // blank = LoadImageFile( WIDE("blankimage.jpg")); blank = MakeImageFile(96,96); ClearImageTo( blank, BASE_COLOR_CYAN ); g.playagain=LoadImageFile( WIDE("%images%/playagain.jpg")); g.playing =LoadImageFile( WIDE("%images%/playing.jpg")); g.background = LoadImageFile( WIDE("%images%/background.jpg") ); // g.background = blank; g.strip = LoadImageFile( WIDE("%images%/slot_strip.jpg") ); g.nReels = NUM_REELS; { Image icons[NUM_ICONS]; int n, m; INDEX idx; for( n = 0; n < NUM_ICONS; n++ ) { icons[n] = MakeSubImage( g.strip, 96 * n, 0, 96, 96 ); } n = width = imagecount = height = 0; while(imagecount < NUM_IMAGES ) { idx = rand()%NUM_ICONS; g.images[imagecount] = icons[idx]; if( testimagesatinitialization ) { BlotImage( g.surface, g.images[imagecount], width * 96, height * 96 ); width++; if(!( width % 8 )) { width=0; height++; } } imagecount++; for( m = 0; m < (( rand()%2 ) ); m++) { g.images[imagecount] = blank; if( testimagesatinitialization ) { BlotImage( g.surface, g.images[imagecount], width * 96, height * 96 ); width++; if(!( width % 8 )) { width=0; height++; } } imagecount++; } if( testimagesatinitialization ) { SyncRender( g.render); UpdateDisplay(g.render); } } if( !testimagesatinitialization ) { SyncRender( g.render); UpdateDisplay(g.render); } for( n = 0; n < NUM_BLURS; n++ ) { g.blurs[n] = MakeImageFile( 96, (NUM_PICS) * 96 ); g.dodges[n] = MakeImageFile( 96, (NUM_PICS) * 96 ); for( m = 0; m < NUM_IMAGES; m++ ) { idx = rand()%NUM_IMAGES; g.reel[0][m] = g.images[idx]; } Blur( g.blurs[n], g.reel[0] ); DodgeEx( g.dodges[n], g.reel[0] , 2); } for( n = 0; n < NUM_REELS; n++) { g.subsurface[n] = MakeSubImage( g.surface , REEL_OFSX + REEL_STEPX * n , REEL_OFSY , REEL_WIDTH, (96 * NUM_PICS_IN_WINDOW) ); g.testsurface[n] = MakeSubImage( g.surface, REEL_OFSX + REEL_STEPX * n + 480, REEL_OFSY , REEL_WIDTH, (96 * NUM_PICS) ); } g.statussurface = MakeSubImage( g.surface , 490, 10 , 140, 68 ); g.backgroundsurface = MakeSubImage( g.surface , 0, 0 , 640, 460 ); } g.flags.bBackgroundInitialized = 0; ThreadTo( ReadInput, 0 ); { uint32_t start = GetTickCount(); xlprintf(LOG_NOISE)("Started at %lu" , start); g.ofs = 0; while( 1 ) { if( g.flags.bSpinning ) { DrawSpinningReels(FALSE); } #ifndef __ARM__ // scale to approx unit speeds.. WakeableSleep( 250 ); //WakeableSleep( 33); #endif } } CloseDisplay( g.render ); UnmakeImageFile( g.strip ); return 0; }