bool OpenSharedMemory(DWORD ProcessID, unsigned int Width, unsigned int Height) { if (Width == 0 || Height == 0) { GetDesktopResolution((int&)Width, (int&)Height); } SharedImageData.reset(new SharedMemory(SharedImageName + std::to_string(ProcessID))); return SharedImageData->OpenMemoryMap(Width || Height == 0 ? SharedImageSize : Width * Height * 4 * 2); }
GraphicsCore::GraphicsCore(void) { fov = 50.0f; //int w, h; if(fullsceen()) { GetDesktopResolution(windowWidth, windowHeight); //glutFullScreen(); } else { windowWidth = 800; windowHeight = 600; } windowTitle = "Pacman"; }
void setFullScreen(bool fullScreen) { if (fullScreen==isFullScreen) return; if (fullScreen){ GetWindowRect(hwndcopy,&winRect); // store the current windows rectangle int horizontal,vertical; GetDesktopResolution(horizontal,vertical); SetWindowPos(hwndcopy,HWND_TOPMOST,0,0,horizontal,vertical,0); } else { SetWindowPos(hwndcopy,HWND_NOTOPMOST,0,0,winRect.right,winRect.bottom,0); } isFullScreen=fullScreen; }
int main(int argc, char** argv) { int horizontal = 0; int vertical = 0; GetDesktopResolution(horizontal, vertical); int xSize = 600, ySize = 600; printf("H: %d\tV: %d\n", horizontal, vertical); // Initializarea bibliotecii GLUT. Argumentele argc // si argv sunt argumentele din linia de comanda si nu // trebuie modificate inainte de apelul functiei // void glutInit(int *argcp, char **argv) // Se recomanda ca apelul oricarei functii din biblioteca // GLUT sa se faca dupa apelul acestei functii. glutInit(&argc, argv); // Argumentele functiei // void glutInitWindowSize (int latime, int latime) // reprezinta latimea, respectiv inaltimea ferestrei // exprimate in pixeli. Valorile predefinite sunt 300, 300. glutInitWindowSize(xSize, ySize); // Argumentele functiei // void glutInitWindowPosition (int x, int y) // reprezinta coordonatele varfului din stanga sus // al ferestrei, exprimate in pixeli. // Valorile predefinite sunt -1, -1. glutInitWindowPosition( (int)(horizontal-xSize)/2, (int)(vertical -ySize)/2); // Functia void glutInitDisplayMode (unsigned int mode) // seteaza modul initial de afisare. Acesta se obtine // printr-un SAU pe biti intre diverse masti de display // (constante ale bibliotecii GLUT) : // 1. GLUT_SINGLE : un singur buffer de imagine. Reprezinta // optiunea implicita ptr. nr. de buffere de // de imagine. // 2. GLUT_DOUBLE : 2 buffere de imagine. // 3. GLUT_RGB sau GLUT_RGBA : culorile vor fi afisate in // modul RGB. // 4. GLUT_INDEX : modul indexat de selectare al culorii. // etc. (vezi specificatia bibliotecii GLUT) glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); // Functia int glutCreateWindow (char *name) // creeaza o fereastra cu denumirea data de argumentul // name si intoarce un identificator de fereastra. glutCreateWindow (">>> GLUT <<<"); Init(); // Functii callback : functii definite in program si // inregistrate in sistem prin intermediul unor functii // GLUT. Ele sunt apelate de catre sistemul de operare // in functie de evenimentul aparut // Functia // void glutReshapeFunc (void (*Reshape)(int width, int height)) // inregistreaza functia callback Reshape care este apelata // oridecate ori fereastra de afisare isi modifica forma. glutReshapeFunc(Reshape); // Functia // void glutKeyboardFunc (void (*KeyboardFunc)(unsigned char,int,int)) // inregistreaza functia callback KeyboardFunc care este apelata // la actionarea unei taste. glutKeyboardFunc(KeyboardFunc); // Functia // void glutMouseFunc (void (*MouseFunc)(int,int,int,int)) // inregistreaza functia callback MouseFunc care este apelata // la apasarea sau la eliberarea unui buton al mouse-ului. glutMouseFunc(MouseFunc); // Functia // void glutDisplayFunc (void (*Display)(void)) // inregistreaza functia callback Display care este apelata // oridecate ori este necesara desenarea ferestrei: la // initializare, la modificarea dimensiunilor ferestrei // sau la apelul functiei // void glutPostRedisplay (void). glutDisplayFunc(Display); // Functia void glutMainLoop() lanseaza bucla de procesare // a evenimentelor GLUT. Din bucla se poate iesi doar prin // inchiderea ferestrei aplicatiei. Aceasta functie trebuie // apelata cel mult o singura data in program. Functiile // callback trebuie inregistrate inainte de apelul acestei // functii. // Cand coada de evenimente este vida atunci este executata // functia callback IdleFunc inregistrata prin apelul functiei // void glutIdleFunc (void (*IdleFunc) (void)) glutMainLoop(); return 0; }
void Game::Create() { // Set the platform ApConfig::SetPlatform( ApPlatform_WinGL ); ApConfig::SetDevice( ApDevice_WIN ); GLFWvidmode dvm; // Initialise GLFW if(!glfwInit()) { fprintf(stderr, "Failed to initialize GLFW\n"); exit(EXIT_FAILURE); } glfwGetDesktopMode(&dvm); project->Init(); // Frame counter and window settings variables int frame = 0; int redBits = 8, greenBits = 8, blueBits = 8; int alphaBits = 8, depthBits = 24, stencilBits = 8; m_width = RsUtil::GetWidth(); m_height = RsUtil::GetHeight(); glfwOpenWindowHint(GLFW_WINDOW_NO_RESIZE, GL_TRUE); // Create a window if(!glfwOpenWindow(m_width, m_height, redBits, greenBits, blueBits, alphaBits, depthBits, stencilBits, GLFW_WINDOW)) { fprintf(stderr, "Failed to open GLFW window\n"); glfwTerminate(); exit(EXIT_FAILURE); } // Set listeners glfwSetWindowCloseCallback(windowCloseListener); int width, height; GetDesktopResolution(width, height); glfwSetWindowPos((width / 2) - (RsUtil::GetWidth() / 2), (height / 2) - (RsUtil::GetHeight() / 2)); // Cache the window handle int handle = glfwGetWindowParam( -1 ); // Create the game mouse m_gameMouse.Setup( (HWND)handle ); m_gameMouse.CreateOnDevice(); // Create the render system RsImpl::pInstance()->Create(); SdSoundWinGL::CreateManager(); BtTimeDX11::Init(); //glfwOpenWindowHint( GLFW_REFRESH_RATE, 1.0f / 30.0f ); glfwSetWindowTitle( ApConfig::GetTitle() ); // Ensure we can capture the escape key being pressed below glfwEnable(GLFW_STICKY_KEYS); // Enable vertical sync (on cards that support it) glfwSwapInterval(1); // Hide the cursor glfwDisable(GLFW_MOUSE_CURSOR); project->Create(); project->Reset(); do { // Get window size (may be different than the requested size) glfwGetWindowSize(&m_width, &m_height); // Set the window size glViewport(0, 0, m_width, m_height); BtFloat dt = BtTime::GetTick(); BtFloat elapsedTime = BtTime::GetElapsedTimeInSeconds(); BtFloat deltaTime = elapsedTime - m_lastGameLogic; m_lastGameLogic = elapsedTime; // Add the excess m_frameRemainder += deltaTime; // Cap the frame m_frameRemainder = BtClamp(m_frameRemainder, (BtFloat)0, 1.0f); BtBool isExiting = BtFalse; //while( m_frameRemainder >= dt ) { // Update the keys input.Update(); // Update the game logic GameUpdate(); // Remove the dt from the frame remainder m_frameRemainder -= dt; } if((isClosing == BtFalse) && (project->IsClosing() == BtFalse)) { // Render project->Render(); // Render RsImpl::pInstance()->Render(); } // Swap buffers glfwSwapBuffers(); } // Check if the ESC key was pressed or the window was closed while(project->IsClosed() == BtFalse); // Destroy the renderer RsImpl::pInstance()->Destroy(); // Destroy the sound SdSoundWinGL::DestroyManager(); // Remove the game mouse m_gameMouse.RemoveFromDevice(); // Destroy the project project->Destroy(); // Close OpenGL window and terminate GLFW glfwTerminate(); }