From 4ebd9b8cf553359ebef8c8f8b2128e7b120bb251 Mon Sep 17 00:00:00 2001 From: stefonzo Date: Sun, 6 Feb 2022 20:47:58 -0600 Subject: initial commit --- .gitignore | 3 +++ Makefile | 7 +++++++ main.cpp | 7 +++++++ simple.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ simple.hpp | 41 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 100 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 main.cpp create mode 100644 simple.cpp create mode 100644 simple.hpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3d2846d --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +a.out +simple_test diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0f9bb3c --- /dev/null +++ b/Makefile @@ -0,0 +1,7 @@ +OBJS = main.cpp simple.cpp +CC = g++ +COMPILER_FLAGS = -w -I/usr/local/include/SDL2/SDL_ttf.h +LINKER_FLAGS = -lSDL2 -lSDL2_ttf -lSDL2_image +OBJ_NAME = simple_test +all: $(OBJS) + $(CC) $(OBJS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o $(OBJ_NAME) diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..3b2b2fa --- /dev/null +++ b/main.cpp @@ -0,0 +1,7 @@ +#include + +using namespace std; + +int main() { + return 0; +} diff --git a/simple.cpp b/simple.cpp new file mode 100644 index 0000000..5f5ab05 --- /dev/null +++ b/simple.cpp @@ -0,0 +1,42 @@ +#include "simple.hpp" +namespace simple { + simple::simple() { + startSDL(); + } + simple::~simple() { + closeSDL(); + } + void simple::startSDL() { + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + printf("SDL could not initialize! SDL Error: %s\n", SDL_GetError()); + } else { + mainWindow = SDL_CreateWindow("tbd", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 500, 500, SDL_WINDOW_SHOWN); + if (mainWindow == NULL) { + printf("Window could not be created! SDL Error: %s\n", SDL_GetError()); + } else { + mainRenderer = SDL_CreateRenderer(mainWindow, -1, SDL_RENDERER_ACCELERATED); + if (mainRenderer == NULL) { + printf("Renderer could not be created! SDL Error: %s\n", SDL_GetError()); + } else { + SDL_SetRenderDrawColor(mainRenderer, 0, 0, 0, 0); + int imgFlags = IMG_INIT_PNG; + if (!(IMG_Init(imgFlags) & imgFlags)) { + printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError()); + } else { + if (TTF_Init() == -1) { + printf("SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError()); + } + } + } + } + } + } + void simple::closeSDL() { + SDL_DestroyRenderer(mainRenderer); + SDL_DestroyWindow(mainWindow); + mainWindow = NULL; + TTF_Quit(); + IMG_Quit(); + SDL_Quit(); + } +} diff --git a/simple.hpp b/simple.hpp new file mode 100644 index 0000000..8c25770 --- /dev/null +++ b/simple.hpp @@ -0,0 +1,41 @@ +#ifndef SIMPLE_h +#define SIMPLE_h +#include +#include +#include +#include + +/* +TODO: + -image loading + -texture quads + -ttf + -buttons/text input? + -timing + -events? +*/ + +namespace simple { + class simple { + private: + SDL_Renderer* mainRenderer; + SDL_Window* mainWindow; + public: + simple(); + ~simple(); + void startSDL(); + void closeSDL(); + }; + //ttfs will be included in the texture class + class texture { + private: + int textureWidth; + int textureHeight; + int fontWidth; + int fontHeight; + public: + texture(); + ~texture(); + }; +} +#endif -- cgit v1.2.1