2
2
#include < SDL2/SDL.h>
3
3
#include < SDL2/SDL_image.h>
4
4
#include < SDL2/SDL_ttf.h>
5
+ #define GLEW_STATIC
6
+ #include < GL/glew.h>
5
7
#include < iostream>
6
8
#include < stdio.h>
7
9
#include < stdlib.h>
@@ -21,16 +23,17 @@ typedef std::chrono::high_resolution_clock Clock;
21
23
22
24
int main (int argc, char * argv[])
23
25
{
24
- std::vector<std::string> elemsUnlocked = {" air" , " earth" , " fire" , " water" };
25
- elem::JSONInit (); // Initialize JSON
26
+ SDL_SetHint (SDL_HINT_RENDER_DRIVER, " opengl" ); // Always use OpenGL
27
+ SDL_GLContext glContext;
28
+ SDL_Event e;
26
29
27
30
// SDL Init
28
31
if (SDL_Init (SDL_INIT_EVERYTHING) != 0 ) {
29
32
fprintf (stderr, " SDL_Init Error: %s\n " , SDL_GetError ());
30
33
return EXIT_FAILURE;
31
34
}
32
35
// Initialize window
33
- SDL_Window* win = SDL_CreateWindow (" Alchemy++ alpha v0.1.2" , 64 , 64 , 800 , 600 , SDL_WINDOW_SHOWN|SDL_WINDOW_RESIZABLE);
36
+ SDL_Window* win = SDL_CreateWindow (" Alchemy++ alpha v0.1.2" , 64 , 64 , 800 , 600 , SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL| SDL_WINDOW_RESIZABLE);
34
37
if (win == NULL ) {
35
38
fprintf (stderr, " SDL_CreateWindow Error: %s\n " , SDL_GetError ());
36
39
return EXIT_FAILURE;
@@ -40,6 +43,7 @@ int main(int argc, char* argv[])
40
43
printf (" SDL_image could not initialize! SDL_image Error: %s\n " , IMG_GetError ());
41
44
}
42
45
}
46
+ glContext = SDL_GL_CreateContext (win);
43
47
44
48
SDL_Renderer* ren = SDL_CreateRenderer (win, -1 , SDL_RENDERER_ACCELERATED|SDL_RENDERER_PRESENTVSYNC);
45
49
if (ren == NULL ) {
@@ -65,9 +69,11 @@ int main(int argc, char* argv[])
65
69
FC_Font* font = FC_CreateFont ();
66
70
FC_LoadFont (font, ren, " gamedata/default/font/Droid-Sans.ttf" , 12 , FC_MakeColor (255 ,255 ,255 ,255 ), TTF_STYLE_NORMAL);
67
71
72
+ elem::JSONInit (); // Initialize JSON
68
73
Text::loadAll (" en-us" ); // Load game text
69
74
70
75
// Game loop init
76
+ std::vector<std::string> elemsUnlocked = {" air" , " earth" , " fire" , " water" };
71
77
std::vector<std::unique_ptr<DraggableElement>> draggables; // List of draggable elements on screen
72
78
std::vector<std::string> elementsUnlocked; // Every element the user has unlocked
73
79
@@ -91,7 +97,6 @@ int main(int argc, char* argv[])
91
97
auto startTick = Clock::now ();
92
98
93
99
// deltaTime = endTick-startTick;
94
- SDL_Event e; // Event variable
95
100
96
101
while (SDL_PollEvent (&e)) {
97
102
switch (e.type ) {
@@ -232,6 +237,7 @@ int main(int argc, char* argv[])
232
237
deltaTime = std::chrono::duration_cast<std::chrono::microseconds>(endTick - startTick).count () / 1000.0 ; // Get the time the frame took in ms
233
238
}
234
239
240
+ SDL_GL_DeleteContext (glContext);
235
241
SDL_DestroyTexture (tex);
236
242
SDL_DestroyRenderer (ren);
237
243
SDL_DestroyWindow (win);
0 commit comments