diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.cpp | 106 |
1 files changed, 39 insertions, 67 deletions
diff --git a/src/main.cpp b/src/main.cpp index 620e97e..382cc93 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,99 +1,71 @@ #define SDL_MAIN_HANDLED -#include <SDL2/SDL.h> -#include <SDL2/SDL_video.h> #include <abc.h> #include <dtx.h> #include <rez.h> +#include <GL/gl.h> +#include <osg/GLExtensions> +#include <osg/State> +#include <osgViewer/GraphicsWindow> +#include <osgViewer/Viewer> +#include <osgViewer/ViewerEventHandlers> #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"; + rez::ball b("globalops.rez"); abc abc; dtx dtx; + osgViewer::Viewer viewer; + osg::Camera *cam; + osg::GraphicsContext *gfx; + osg::State *state; + osg::GLExtensions *ext; + osgViewer::GraphicsWindow *gfxw; + + viewer.setUpViewInWindow(0, 0, 640, 480); + viewer.realize(); + cam = viewer.getCamera(); + gfx = cam->getGraphicsContext(); + gfxw = dynamic_cast<osgViewer::GraphicsWindow *>(gfx); - if (SDL_Init(SDL_INIT_VIDEO) < 0) + if (!gfxw) { - std::cerr << "SDL_Init failed: " << SDL_GetError() << '\n'; - goto end; + std::cerr << "Failed to cast osgViewe::GraphicContext to " + "osgViewer::GraphicsWindow\n"; + return EXIT_FAILURE; } - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); + gfxw->setWindowName("GlobalOps"); + state = gfx->getState(); + state->initializeExtensionProcs(); + ext = osg::GLExtensions::Get(state->getContextID(), true); - if (!(window = SDL_CreateWindow("GlobalOps", SDL_WINDOWPOS_CENTERED, - SDL_WINDOWPOS_CENTERED, 640, 480, - SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE))) + if (!ext) { - std::cerr << "SDL_CreateWindow failed: " << SDL_GetError() << '\n'; - goto end; + std::cerr << "osg::GLExtensions::Get failed\n"; + return EXIT_FAILURE; } - else if (!(glcontext = SDL_GL_CreateContext(window))) + else if (!ext->isCompressedTexImage2DSupported()) { - std::cerr << "SDL_GL_CreateContext failed: " << SDL_GetError() << '\n'; - goto end; + std::cerr << "OpenGL extension glCompressedTextImage2D not supported\n"; + return EXIT_FAILURE; } - else if (!SDL_GL_ExtensionSupported(extension)) + else if (!ext->isTextureCompressionS3TCSupported) { - 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; + std::cerr << "OpenGL extension GL_EXT_texture_compression_s3tc " + "not supported\n"; + return EXIT_FAILURE; } 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 EXIT_FAILURE; - return ret; + return viewer.run(); } |
