diff options
| author | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-12-04 13:58:02 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi92@disroot.org> | 2025-12-15 23:04:39 +0100 |
| commit | 600ff28dd73f2cf17725382b68a4b1b2573f2e34 (patch) | |
| tree | a105c686458d8998438652aeca6299cf9000edcd /src/main.cpp | |
| download | globalops-main.tar.gz | |
Diffstat (limited to 'src/main.cpp')
| -rw-r--r-- | src/main.cpp | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..620e97e --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,99 @@ +#define SDL_MAIN_HANDLED + +#include <SDL2/SDL.h> +#include <SDL2/SDL_video.h> +#include <abc.h> +#include <dtx.h> +#include <rez.h> +#include <cstdlib> +#include <cstdio> +#include <iostream> +#include <GL/gl.h> + +int main(int argc, char *argv[]) +{ + int ret = EXIT_FAILURE; + rez::ball b("globalops.rez"); + std::unique_ptr<rez::file> f, abcf; + SDL_Window *window = nullptr; + SDL_GLContext glcontext = nullptr; + static const char extension[] = "GL_EXT_texture_compression_s3tc"; + abc abc; + dtx dtx; + + if (SDL_Init(SDL_INIT_VIDEO) < 0) + { + std::cerr << "SDL_Init failed: " << SDL_GetError() << '\n'; + goto end; + } + + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); + + if (!(window = SDL_CreateWindow("GlobalOps", SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, 640, 480, + SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE))) + { + std::cerr << "SDL_CreateWindow failed: " << SDL_GetError() << '\n'; + goto end; + } + else if (!(glcontext = SDL_GL_CreateContext(window))) + { + std::cerr << "SDL_GL_CreateContext failed: " << SDL_GetError() << '\n'; + goto end; + } + else if (!SDL_GL_ExtensionSupported(extension)) + { + std::cerr << "OpenGL extension " << extension << " not supported\n"; + goto end; + } + else if (SDL_GL_MakeCurrent(window, glcontext)) + { + std::cerr << "SDL_GL_MakeCurrent failed: " << SDL_GetError() + << std::endl; + goto end; + } + else if (b.parse() + || !(f = b.open("interface/blueprints/antarctica_tacmap.dtx")) + || dtx.parse(*f) + || !(f = b.open("models/grenades/v_frag.abc")) + || abc.parse(*f)) + goto end; + + for (;;) + { + SDL_Event event; + + while (SDL_PollEvent(&event)) + { + switch (event.type) + { + case SDL_QUIT: + ret = EXIT_SUCCESS; + goto end; + } + } + + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + if (dtx.draw()) + goto end; + + SDL_GL_SwapWindow(window); + SDL_Delay(1.0f / 60.f * 1000.0f); + } + +end: + + if (glcontext) + SDL_GL_DeleteContext(glcontext); + + if (window) + SDL_DestroyWindow(window); + + if (SDL_WasInit(SDL_INIT_VIDEO)) + SDL_QuitSubSystem(SDL_INIT_VIDEO); + + return ret; +} |
