100 lines
2.8 KiB
C++
100 lines
2.8 KiB
C++
#include <SDL.h>
|
|
#include <SDL_ttf.h>
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
#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;
|
|
}
|