]> rtime.felk.cvut.cz Git - hubacji1/iamcar.git/commitdiff
Plot basic window
authorJiri Hubacek <hubacji1@fel.cvut.cz>
Wed, 26 Sep 2018 12:51:49 +0000 (14:51 +0200)
committerJiri Hubacek <hubacji1@fel.cvut.cz>
Wed, 26 Sep 2018 13:07:38 +0000 (15:07 +0200)
See: http://lazyfoo.net/tutorials/SDL/index.php

base/main.cc

index cb8a7a7fe1524c9592e0e74c1b03d46eff04e910..eb4ebe5418ed3d6a125b9fde2af419141e947999 100644 (file)
@@ -17,6 +17,7 @@ along with I am car. If not, see <http://www.gnu.org/licenses/>.
 
 #include <iostream>
 #include <jsoncpp/json/json.h>
+#include <SDL2/SDL.h>
 #include <signal.h>
 #include "compile.h"
 #include "obstacle.h"
@@ -33,6 +34,40 @@ void hint(int)
 
 int main()
 {
+        const int SCREEN_WIDTH = 640;
+        const int SCREEN_HEIGHT = 480;
+        SDL_Window* window = NULL;
+        SDL_Surface* screenSurface = NULL;
+        if (SDL_Init(SDL_INIT_VIDEO) < 0) {
+                std::cerr << "SDL could not initialize! SDL_Error: ";
+                std::cerr << SDL_GetError();
+                std::cerr << std::endl;
+        } else {
+                window = SDL_CreateWindow(
+                                "I am car",
+                                SDL_WINDOWPOS_UNDEFINED,
+                                SDL_WINDOWPOS_UNDEFINED,
+                                SCREEN_WIDTH,
+                                SCREEN_HEIGHT,
+                                SDL_WINDOW_SHOWN);
+                if (window == NULL) {
+                        std::cerr << "Window could not be created! SDL_Error: ";
+                        std::cerr << SDL_GetError();
+                        std::cerr << std::endl;
+                } else {
+                        screenSurface = SDL_GetWindowSurface(window);
+                        SDL_FillRect(
+                                        screenSurface,
+                                        NULL,
+                                        SDL_MapRGB(
+                                                screenSurface->format,
+                                                0xFF,
+                                                0xFF,
+                                                0xFF));
+                        SDL_UpdateWindowSurface(window);
+                }
+        }
+
         Json::Value jvi; // JSON input
         Json::Value jvo; // JSON output
         unsigned int i = 0;
@@ -192,6 +227,9 @@ int main()
         // print output
         std::cout << jvo << std::endl;
 
+        SDL_DestroyWindow(window);
+        SDL_Quit();
+
         // free mem
         for (auto o: so) {
                 delete o.init();