Skip to content

Commit 2d58cfe

Browse files
Start text rendering refactor, fix Windows linking
1 parent 71194c0 commit 2d58cfe

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

CMakeLists.txt

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
cmake_minimum_required(VERSION 3.5)
1+
cmake_minimum_required(VERSION 3.31)
22
project(AlchemyPlusPlus)
33

44
# Create an option to switch between a system sdl library and a vendored sdl library
55
option(MYGAME_VENDORED "Use vendored libraries" OFF)
66

7-
#build settings
7+
# Build settings
88
if(NOT CMAKE_BUILD_TYPE)
9-
set(CMAKE_BUILD_TYPE Release)
9+
set(CMAKE_BUILD_TYPE Debug)
1010
endif()
11-
#set(CMAKE_DEBUG_POSTFIX d)
12-
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
11+
set(CMAKE_DEBUG_POSTFIX d)
12+
#set(CMAKE_CXX_FLAGS_RELEASE "-O2")
1313

1414
if(MYGAME_VENDORED)
1515
add_subdirectory(vendored/sdl EXCLUDE_FROM_ALL)
@@ -21,8 +21,10 @@ else()
2121
find_package(SDL2 REQUIRED CONFIG COMPONENTS SDL2main)
2222
endif()
2323

24+
# Find dependencies
2425
find_package(SDL2_image REQUIRED)
2526
find_package(SDL2_ttf REQUIRED)
27+
find_package(GLEW REQUIRED)
2628
include_directories(${SDL2_INCLUDE_DIRS} ${SDL2_IMAGE_INCLUDE_DIRS})
2729

2830
# Create your game executable target as usual
@@ -40,19 +42,20 @@ add_executable(AlchemyPlusPlus src/main.cpp) #Main file
4042

4143
if(WIN32)
4244
target_link_options(AlchemyPlusPlus PRIVATE "-mwindows") #Disable console pop-up
43-
target_link_options(AlchemyPlusPlus PRIVATE -static gcc stdc++ winpthread -dynamic) #Statically link libraries
45+
target_link_options(AlchemyPlusPlus PRIVATE -static) #Statically link non-SDL libraries
4446
endif(WIN32)
4547

4648
# SDL2::SDL2main may or may not be available. It is e.g. required by Windows GUI applications
4749
if(TARGET SDL2::SDL2main)
4850
# It has an implicit dependency on SDL2 functions, so it MUST be added before SDL2::SDL2 (or SDL2::SDL2-static)
4951
target_link_libraries(AlchemyPlusPlus SDL2::SDL2main)
5052
endif()
51-
target_link_libraries (AlchemyPlusPlus JSON)
52-
target_link_libraries (AlchemyPlusPlus GFX)
53-
target_link_libraries (AlchemyPlusPlus Game)
54-
target_link_libraries (AlchemyPlusPlus Misc)
55-
target_link_libraries (AlchemyPlusPlus Menu)
53+
target_link_libraries(AlchemyPlusPlus GLEW::GLEW)
54+
target_link_libraries(AlchemyPlusPlus JSON)
55+
target_link_libraries(AlchemyPlusPlus GFX)
56+
target_link_libraries(AlchemyPlusPlus Game)
57+
target_link_libraries(AlchemyPlusPlus Misc)
58+
target_link_libraries(AlchemyPlusPlus Menu)
5659

5760
# Link to the actual SDL2 library. SDL2::SDL2 is the shared SDL library, SDL2::SDL2-static is the static SDL libarary.
5861
target_link_libraries(AlchemyPlusPlus SDL2::SDL2 SDL2_image::SDL2_image)

src/main.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <SDL2/SDL.h>
33
#include <SDL2/SDL_image.h>
44
#include <SDL2/SDL_ttf.h>
5+
#define GLEW_STATIC
6+
#include <GL/glew.h>
57
#include <iostream>
68
#include <stdio.h>
79
#include <stdlib.h>
@@ -21,16 +23,17 @@ typedef std::chrono::high_resolution_clock Clock;
2123

2224
int main(int argc, char* argv[])
2325
{
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;
2629

2730
// SDL Init
2831
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
2932
fprintf(stderr, "SDL_Init Error: %s\n", SDL_GetError());
3033
return EXIT_FAILURE;
3134
}
3235
// 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);
3437
if (win == NULL) {
3538
fprintf(stderr, "SDL_CreateWindow Error: %s\n", SDL_GetError());
3639
return EXIT_FAILURE;
@@ -40,6 +43,7 @@ int main(int argc, char* argv[])
4043
printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError());
4144
}
4245
}
46+
glContext = SDL_GL_CreateContext(win);
4347

4448
SDL_Renderer* ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED|SDL_RENDERER_PRESENTVSYNC);
4549
if (ren == NULL) {
@@ -65,9 +69,11 @@ int main(int argc, char* argv[])
6569
FC_Font* font = FC_CreateFont();
6670
FC_LoadFont(font, ren, "gamedata/default/font/Droid-Sans.ttf", 12, FC_MakeColor(255,255,255,255), TTF_STYLE_NORMAL);
6771

72+
elem::JSONInit(); //Initialize JSON
6873
Text::loadAll("en-us"); //Load game text
6974

7075
// Game loop init
76+
std::vector<std::string> elemsUnlocked = {"air", "earth", "fire", "water"};
7177
std::vector<std::unique_ptr<DraggableElement>> draggables; //List of draggable elements on screen
7278
std::vector<std::string> elementsUnlocked; //Every element the user has unlocked
7379

@@ -91,7 +97,6 @@ int main(int argc, char* argv[])
9197
auto startTick = Clock::now();
9298

9399
//deltaTime = endTick-startTick;
94-
SDL_Event e; //Event variable
95100

96101
while (SDL_PollEvent(&e)) {
97102
switch (e.type) {
@@ -232,6 +237,7 @@ int main(int argc, char* argv[])
232237
deltaTime = std::chrono::duration_cast<std::chrono::microseconds>(endTick - startTick).count() / 1000.0; //Get the time the frame took in ms
233238
}
234239

240+
SDL_GL_DeleteContext(glContext);
235241
SDL_DestroyTexture(tex);
236242
SDL_DestroyRenderer(ren);
237243
SDL_DestroyWindow(win);

0 commit comments

Comments
 (0)