commit 65ae6a78f0d5492599f4c8b6f2ab2a37e181ca31 Author: Wizzard <25581244+Wizzard@users.noreply.toomuchslop.com> Date: Tue Dec 12 16:13:36 2023 -0500 First push diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..86f0aa0 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.10) +project(CDoom) + +set(CMAKE_CXX_STANDARD 17) + +# Include directory for header files +include_directories(${PROJECT_SOURCE_DIR}/src/include) + +# Automatically find all .cpp files in src/ and subdirectories +file(GLOB_RECURSE SOURCES "src/*.cpp") + +# Find SDL2 library +find_package(SDL2 REQUIRED) +include_directories(${SDL2_INCLUDE_DIRS}) + +# Find SDL2_ttf library +find_package(SDL2_ttf REQUIRED) +include_directories(${SDL2_TTF_INCLUDE_DIRS}) + +set(SDL2_TTF_LIBRARIES "/usr/lib/libSDL2_ttf.so") + +# Create executable with all source files +add_executable(CDoom ${SOURCES}) + +# Link SDL2 and SDL2_ttf libraries +target_link_libraries(CDoom ${SDL2_LIBRARIES} ${SDL2_TTF_LIBRARIES}) diff --git a/src/WadFile.cpp b/src/WadFile.cpp new file mode 100644 index 0000000..fb31270 --- /dev/null +++ b/src/WadFile.cpp @@ -0,0 +1,25 @@ +#include "WadFile.h" +#include +#include + +WadFile::WadFile(const std::string& filename) : filename(filename) { + +} + +WadFile::~WadFile() { + +} + +bool WadFile::Load() { + std::ifstream file(filename, std::ios::binary); + if (!file.is_open()) { + std::cerr << "Failed to open WAD file: " << filename << std::endl; + return false; + } + + return true; +} + +SDL_Texture* WadFile::GetShotgunTexture(SDL_Renderer* renderer) { + return nullptr; // Placeholder +} diff --git a/src/include/Renderer.h b/src/include/Renderer.h new file mode 100644 index 0000000..e69de29 diff --git a/src/include/WadFile.h b/src/include/WadFile.h new file mode 100644 index 0000000..70fe197 --- /dev/null +++ b/src/include/WadFile.h @@ -0,0 +1,30 @@ +#ifndef WADFILE_H +#define WADFILE_H + +#include +#include +#include + +struct WadHeader { + +}; + +struct LumpDirectory { + +}; + +class WadFile { +public: + WadFile(const std::string& filename); + ~WadFile(); + + bool Load(); + SDL_Texture* GetShotgunTexture(SDL_Renderer* renderer); + +private: + std::string filename; + std::vector lumps; + +}; + +#endif // WADFILE_H diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..4bd03db --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,99 @@ +#include +#include +#include +#include + +#include "WadFile.h" + +#define BUILD_DATE __DATE__ " " __TIME__ + +int main(int argc, char* argv[]) { + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + std::cerr << "SDL could not initialize! SDL_Error: " << SDL_GetError() << std::endl; + return 1; + } + + if (TTF_Init() == -1) { + std::cerr << "TTF could not initialize! TTF_Error: " << TTF_GetError() << std::endl; + SDL_Quit(); + return 1; + } + + SDL_Window* window = SDL_CreateWindow("CDoom", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN); + if (!window) { + std::cerr << "Window could not be created! SDL_Error: " << SDL_GetError() << std::endl; + TTF_Quit(); + SDL_Quit(); + return 1; + } + + SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); + if (!renderer) { + std::cerr << "Renderer could not be created! SDL_Error: " << SDL_GetError() << std::endl; + SDL_DestroyWindow(window); + TTF_Quit(); + SDL_Quit(); + return 1; + } + + WadFile wad("DOOM2.WAD"); + if (!wad.Load()) { + std::cerr << "Failed to load WAD file" << std::endl; + } + + SDL_Texture* shotgunTexture = wad.GetShotgunTexture(renderer); + if (!shotgunTexture) { + std::cerr << "Failed to load shotgun texture" << std::endl; + } + + TTF_Font* font = TTF_OpenFont("OpenSans-Bold.ttf", 24); + if (!font) { + std::cerr << "Failed to load font! TTF_Error: " << TTF_GetError() << std::endl; + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + TTF_Quit(); + SDL_Quit(); + return 1; + } + + + SDL_Color textColor = {255, 255, 255, 255}; + + SDL_Surface* textSurface = TTF_RenderText_Solid(font, ("CDoom: Built on " + std::string(BUILD_DATE)).c_str(), textColor); + if (!textSurface) { + std::cerr << "Failed to create text surface! TTF_Error: " << TTF_GetError() << std::endl; + TTF_CloseFont(font); + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + TTF_Quit(); + SDL_Quit(); + return 1; + } + + SDL_Texture* textTexture = SDL_CreateTextureFromSurface(renderer, textSurface); + SDL_Rect textRect = {0, 0, textSurface->w, textSurface->h}; + SDL_FreeSurface(textSurface); + + bool running = true; + SDL_Event event; + while (running) { + while (SDL_PollEvent(&event) != 0) { + if (event.type == SDL_QUIT) { + running = false; + } + } + + SDL_RenderClear(renderer); + SDL_RenderCopy(renderer, textTexture, NULL, &textRect); + SDL_RenderPresent(renderer); + } + + SDL_DestroyTexture(textTexture); + TTF_CloseFont(font); + SDL_DestroyRenderer(renderer); + SDL_DestroyWindow(window); + TTF_Quit(); + SDL_Quit(); + + return 0; +}