1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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;
}
|