]> code.bitgloo.com Git - clyne/gamedev2.git/commitdiff
created a window
authortcsullivan <tullivan99@gmail.com>
Sun, 25 Aug 2019 18:57:16 +0000 (14:57 -0400)
committertcsullivan <tullivan99@gmail.com>
Sun, 25 Aug 2019 18:57:16 +0000 (14:57 -0400)
src/main.cpp

index 8528f0ad5850f62da41532192a91681c54382734..9b88994ecdfce790e4c0d9ca72ccf1176dfe001c 100644 (file)
 #include <SDL2/SDL.h>
 
 #include <iostream>
+#include <memory>
+
+constexpr const char *title = "gamedev2";
+constexpr int width = 640;
+constexpr int height = 480;
 
 int main([[maybe_unused]] int argc, [[maybe_unused]] char *argv[])
 {
-       if (SDL_Init(0) != 0) {
+       std::cout << "Hello, world!" << std::endl;
+
+       if (SDL_Init(SDL_INIT_VIDEO) != 0) {
                std::cerr << "SDL failed to initialize: " << SDL_GetError() <<
                        std::endl;
                return -1;
@@ -32,7 +39,16 @@ int main([[maybe_unused]] int argc, [[maybe_unused]] char *argv[])
                atexit(SDL_Quit);
        }
 
-       std::cout << "Hello, world!" << std::endl;
+       std::unique_ptr<SDL_Window, decltype(&SDL_DestroyWindow)> window
+               (SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED,
+               SDL_WINDOWPOS_UNDEFINED, width, height, 0), SDL_DestroyWindow);
+
+       if (window.get() == nullptr) {
+               std::cerr << "SDL window creation failed: " << SDL_GetError() <<
+                       std::endl;
+       }
+
+       SDL_Delay(1000);
 
        return 0;
 }