//////////////////////////////////////////////////////////// /// Entry point of application /// /// \return Error code /// //////////////////////////////////////////////////////////// int main() { // Open a connection with the X server Display* display = XOpenDisplay(NULL); if (!display) return EXIT_FAILURE; // Get the default screen int screen = DefaultScreen(display); // Let's create the main window XSetWindowAttributes attributes; attributes.background_pixel = BlackPixel(display, screen); attributes.event_mask = KeyPressMask; Window window = XCreateWindow(display, RootWindow(display, screen), 0, 0, 650, 330, 0, DefaultDepth(display, screen), InputOutput, DefaultVisual(display, screen), CWBackPixel | CWEventMask, &attributes); if (!window) return EXIT_FAILURE; // Set the window's name XStoreName(display, window , "SFML Window"); // Let's create the windows which will serve as containers for our SFML views Window view1 = XCreateWindow(display, window, 10, 10, 310, 310, 0, DefaultDepth(display, screen), InputOutput, DefaultVisual(display, screen), 0, NULL); Window view2 = XCreateWindow(display, window, 330, 10, 310, 310, 0, DefaultDepth(display, screen), InputOutput, DefaultVisual(display, screen), 0, NULL); // Show our windows XMapWindow(display, window); XFlush(display); // Create our SFML views sf::Window SFMLView1(view1); sf::Window SFMLView2(view2); // Create a clock for measuring elapsed time sf::Clock clock; // Initialize our views initialize(SFMLView1); initialize(SFMLView2); // Start the event loop bool running = true; while (running) { while (XPending(display)) { // Get the next pending event XEvent event; XNextEvent(display, &event); // Process it switch (event.type) { // Any key is pressed: quit case KeyPress: running = false; break; } } // Draw something into our views draw(SFMLView1, clock.getElapsedTime().asSeconds()); draw(SFMLView2, clock.getElapsedTime().asSeconds() * 0.3f); // Display the views on screen SFMLView1.display(); SFMLView2.display(); } // Close the display XCloseDisplay(display); return EXIT_SUCCESS; }
//////////////////////////////////////////////////////////// /// Entry point of application /// /// \param Instance : Instance of the application /// /// \return Error code /// //////////////////////////////////////////////////////////// INT WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR, INT) { // Define a class for our main window WNDCLASS windowClass; windowClass.style = 0; windowClass.lpfnWndProc = &OnEvent; windowClass.cbClsExtra = 0; windowClass.cbWndExtra = 0; windowClass.hInstance = instance; windowClass.hIcon = NULL; windowClass.hCursor = 0; windowClass.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BACKGROUND); windowClass.lpszMenuName = NULL; windowClass.lpszClassName = TEXT("SFML App"); RegisterClass(&windowClass); // Let's create the main window HWND window = CreateWindow(TEXT("SFML App"), TEXT("SFML Win32"), WS_SYSMENU | WS_VISIBLE, 200, 200, 660, 520, NULL, NULL, instance, NULL); // Add a button for exiting button = CreateWindow(TEXT("BUTTON"), TEXT("Quit"), WS_CHILD | WS_VISIBLE, 560, 440, 80, 40, window, NULL, instance, NULL); // Let's create two SFML views HWND view1 = CreateWindow(TEXT("STATIC"), NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 20, 20, 300, 400, window, NULL, instance, NULL); HWND view2 = CreateWindow(TEXT("STATIC"), NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 340, 20, 300, 400, window, NULL, instance, NULL); sf::RenderWindow SFMLView1(view1); sf::RenderWindow SFMLView2(view2); // Load some textures to display sf::Texture texture1, texture2; if (!texture1.LoadFromFile("resources/image1.jpg") || !texture2.LoadFromFile("resources/image2.jpg")) return EXIT_FAILURE; sf::Sprite sprite1(texture1); sf::Sprite sprite2(texture2); sprite1.SetOrigin(texture1.GetWidth() / 2.f, texture1.GetHeight() / 2.f); sprite1.SetPosition(sprite1.GetOrigin()); // Create a clock for measuring elapsed time sf::Clock clock; // Loop until a WM_QUIT message is received MSG message; message.message = static_cast<UINT>(~WM_QUIT); while (message.message != WM_QUIT) { if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE)) { // If a message was waiting in the message queue, process it TranslateMessage(&message); DispatchMessage(&message); } else { float time = clock.GetElapsedTime().AsSeconds(); // Clear views SFMLView1.Clear(); SFMLView2.Clear(); // Draw sprite 1 on view 1 sprite1.SetRotation(time * 100); SFMLView1.Draw(sprite1); // Draw sprite 2 on view 2 sprite2.SetPosition(std::cos(time) * 100.f, 0.f); SFMLView2.Draw(sprite2); // Display each view on screen SFMLView1.Display(); SFMLView2.Display(); } } // Destroy the main window (all its child controls will be destroyed) DestroyWindow(window); // Don't forget to unregister the window class UnregisterClass(TEXT("SFML App"), instance); return EXIT_SUCCESS; }
//////////////////////////////////////////////////////////// /// Entry point of application /// /// \param Instance : Instance of the application /// /// \return Error code /// //////////////////////////////////////////////////////////// INT WINAPI WinMain(HINSTANCE Instance, HINSTANCE, LPSTR, INT) { // Define a class for our main window WNDCLASS WindowClass; WindowClass.style = 0; WindowClass.lpfnWndProc = &OnEvent; WindowClass.cbClsExtra = 0; WindowClass.cbWndExtra = 0; WindowClass.hInstance = Instance; WindowClass.hIcon = NULL; WindowClass.hCursor = 0; WindowClass.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BACKGROUND); WindowClass.lpszMenuName = NULL; WindowClass.lpszClassName = TEXT("SFML App"); RegisterClass(&WindowClass); // Let's create the main window HWND Window = CreateWindow(TEXT("SFML App"), TEXT("SFML Win32"), WS_SYSMENU | WS_VISIBLE, 200, 200, 660, 520, NULL, NULL, Instance, NULL); // Add a button for exiting Button = CreateWindow(TEXT("BUTTON"), TEXT("Quit"), WS_CHILD | WS_VISIBLE, 560, 440, 80, 40, Window, NULL, Instance, NULL); // Let's create two SFML views HWND View1 = CreateWindow(TEXT("STATIC"), NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 20, 20, 300, 400, Window, NULL, Instance, NULL); HWND View2 = CreateWindow(TEXT("STATIC"), NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS, 340, 20, 300, 400, Window, NULL, Instance, NULL); sf::RenderWindow SFMLView1(View1); sf::RenderWindow SFMLView2(View2); // Load some images to display sf::Image Image1, Image2; if (!Image1.LoadFromFile("datas/win32/image1.jpg") || !Image2.LoadFromFile("datas/win32/image2.jpg")) return EXIT_FAILURE; sf::Sprite Sprite1(Image1); sf::Sprite Sprite2(Image2); Sprite1.SetCenter(Sprite1.GetSize() / 2.f); // Create a clock for measuring elapsed time sf::Clock Clock; // Loop until a WM_QUIT message is received MSG Message; Message.message = static_cast<UINT>(~WM_QUIT); while (Message.message != WM_QUIT) { if (PeekMessage(&Message, NULL, 0, 0, PM_REMOVE)) { // If a message was waiting in the message queue, process it TranslateMessage(&Message); DispatchMessage(&Message); } else { // Clear views SFMLView1.Clear(); SFMLView2.Clear(); // Draw sprite 1 on view 1 Sprite1.SetRotation(Clock.GetElapsedTime() * 100); SFMLView1.Draw(Sprite1); // Draw sprite 2 on view 2 Sprite2.SetX(cos(Clock.GetElapsedTime()) * 100); SFMLView2.Draw(Sprite2); // Display each view on screen SFMLView1.Display(); SFMLView2.Display(); } } // Destroy the main window (all its child controls will be destroyed) DestroyWindow(Window); // Don't forget to unregister the window class UnregisterClass(TEXT("SFML App"), Instance); return EXIT_SUCCESS; }
int APIENTRY _tWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nCmdShow) { // Define a class for our main window WNDCLASS WindowClass; WindowClass.style = 0; WindowClass.lpfnWndProc = WndProc; WindowClass.cbClsExtra = 0; WindowClass.cbWndExtra = 0; WindowClass.hInstance = hInstance; WindowClass.hIcon = NULL; WindowClass.hCursor = 0; WindowClass.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_BACKGROUND); WindowClass.lpszMenuName = NULL; WindowClass.lpszClassName = L"SFML App"; RegisterClass(&WindowClass); // Let's create the main window HWND Window = CreateWindow(L"SFML App", L"SFML Win32", WS_SYSMENU | WS_VISIBLE, 0, 0, 1280, 720, NULL, NULL, hInstance, NULL); // Let's create two SFML views DWORD Style = WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS; HWND View1 = CreateWindow(L"STATIC", NULL, Style, 0, 0, 200, 720, Window, NULL, hInstance, NULL); HWND View2 = CreateWindow(L"STATIC", NULL, Style, 200, 0, 1080, 720, Window, NULL, hInstance, NULL); // INIT CONSOLE RedirectIOToConsole(); sf::RenderWindow SFMLView1(View1); sf::RenderWindow SFMLView2(View2); // babby's main loop MSG Message; Message.message = ~WM_QUIT; while (Message.message != WM_QUIT) { if (PeekMessage(&Message, NULL, 0, 0, PM_REMOVE)) { // If a message was waiting in the message queue, process it TranslateMessage(&Message); DispatchMessage(&Message); } else { // SFML rendering code goes here // Clear views SFMLView1.clear(sf::Color::Blue); SFMLView2.clear(sf::Color::Red); // Draw sprite 1 on view 1 //SFMLView1.draw(Sprite1); // Draw sprite 2 on view 2 //SFMLView2.Draw(Sprite2); // Display each view on screen SFMLView1.display(); SFMLView2.display(); } } // Destroy the main window DestroyWindow(Window); // Don't forget to unregister the window class UnregisterClass(L"SFML App", hInstance); }