parent
511e2266ce
commit
0748d3d4ff
@ -0,0 +1,53 @@ |
||||
cmake_minimum_required(VERSION 2.8) |
||||
|
||||
project(Symmetry) |
||||
|
||||
include_directories(include) |
||||
file(GLOB SOURCES "src/*.c") |
||||
|
||||
add_executable(${PROJECT_NAME} ${SOURCES}) |
||||
|
||||
if(CMAKE_CONFIGURATION_TYPES) |
||||
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE STRING "" FORCE) |
||||
else() |
||||
if(CMAKE_BUILD_TYPE MATCHES Debug) |
||||
set(SYMMETRY_BUILD_TYPE debug) |
||||
add_definitions(-DGL_DEBUG_CONTEXT) |
||||
else() |
||||
set(CMAKE_BUILD_TYPE Release) |
||||
set(SYMMETRY_BUILD_TYPE release) |
||||
endif() |
||||
endif() |
||||
|
||||
|
||||
# Flags |
||||
add_definitions(-DUSE_GLAD) |
||||
|
||||
# Platform specific libs and flags |
||||
if(WIN32) |
||||
set(CURRENT_PLATFORM windows) |
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS) |
||||
add_library(sdl2 STATIC IMPORTED) |
||||
set_target_properties(sdl2 PROPERTIES IMPORTED_LOCATION_DEBUG ${CMAKE_SOURCE_DIR}/libs/debug/win64_msvc/SDL2.lib) |
||||
set_target_properties(sdl2 PROPERTIES IMPORTED_LOCATION_RELEASE ${CMAKE_SOURCE_DIR}/libs/release/win64_msvc/SDL2.lib) |
||||
target_link_libraries(${PROJECT_NAME} sdl2 winmm.lib imm32.lib version.lib) |
||||
set(CMAKE_C_FLAGS_DEBUG /MTd) |
||||
set(CMAKE_C_FLAGS_RELEASE /MT) |
||||
elseif(UNIX AND NOT APPLE) |
||||
set(CURRENT_PLATFORM linux) |
||||
find_library(LIB_M m REQUIRED) |
||||
find_library(LIB_RT rt REQUIRED) |
||||
find_library(LIB_PTHREAD pthread REQUIRED) |
||||
find_library(SDL2_LIBRARY SDL2 HINTS libs/${SYMMETRY_BUILD_TYPE}/linux64_gcc REQUIRED) |
||||
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARY} ${LIB_PTHREAD} ${LIB_M} ${LIB_RT} ${CMAKE_DL_LIBS}) |
||||
set(CMAKE_C_FLAGS "-Wall -Wno-undefined -std=c99") |
||||
else() |
||||
message(FATAL_ERROR "Unsupported Platform! Currently only Windows and Linux supported") |
||||
endif(WIN32) |
||||
|
||||
find_package(OpenGL REQUIRED) |
||||
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARIES}) |
||||
|
||||
set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/bin) # Does not work on windows for some reason! TODO: Find a way around this for faster windows installation |
||||
install(TARGETS ${PROJECT_NAME} DESTINATION ${CURRENT_PLATFORM}) |
||||
install(DIRECTORY ${CMAKE_SOURCE_DIR}/assets DESTINATION ${CURRENT_PLATFORM}) |
@ -1,109 +0,0 @@ |
||||
#include "window_system.h" |
||||
#include "GLFW/glfw3.h" |
||||
|
||||
#include "log.h" |
||||
|
||||
static GLFWwindow* active_window = NULL; |
||||
static on_window_close window_close_custom = NULL; |
||||
static on_window_resize window_resize_custom = NULL; |
||||
|
||||
void window_error_callback(int error, const char* description); |
||||
void window_resize(GLFWwindow* window, int width, int height); |
||||
void window_close_callback(GLFWwindow* window); |
||||
|
||||
int window_init(const char* title, int width, int height) |
||||
{ |
||||
int success = 1; |
||||
glfwSetErrorCallback(window_error_callback); |
||||
if(!glfwInit()) |
||||
{ |
||||
log_error("window_create", "Initializing glfw failed"); |
||||
success = 0; |
||||
} |
||||
else |
||||
{ |
||||
log_message("Initialized with GLFW version %d.%d.%d", |
||||
GLFW_VERSION_MAJOR, |
||||
GLFW_VERSION_MINOR, |
||||
GLFW_VERSION_REVISION); |
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); |
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); |
||||
glfwWindowHint(GLFW_FOCUSED, GL_TRUE); |
||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE); |
||||
active_window = glfwCreateWindow(width, height, title, NULL, NULL); |
||||
if(!active_window) |
||||
{ |
||||
log_error("window_create", "Failed to create window"); |
||||
success = 0; |
||||
} |
||||
else |
||||
{ |
||||
glfwMakeContextCurrent(active_window); |
||||
glfwSwapInterval(1); |
||||
glfwSetWindowSizeCallback(active_window, window_resize); |
||||
glfwSetWindowCloseCallback(active_window, window_close_callback); |
||||
} |
||||
} |
||||
return success; |
||||
} |
||||
|
||||
void window_error_callback(int error, const char* description) |
||||
{ |
||||
log_error("GLFW", "(%d) %s", error, description); |
||||
} |
||||
|
||||
void window_close_callback(GLFWwindow* window) |
||||
{ |
||||
if(!window_close_custom) |
||||
glfwSetWindowShouldClose(window, GL_TRUE); |
||||
else |
||||
window_close_custom(); |
||||
} |
||||
|
||||
void window_cleanup(void) |
||||
{ |
||||
if(active_window) glfwDestroyWindow(active_window); |
||||
active_window = NULL; |
||||
glfwTerminate(); |
||||
} |
||||
|
||||
void window_poll_events(void) |
||||
{ |
||||
glfwPollEvents(); |
||||
} |
||||
|
||||
void window_swap_buffers(void) |
||||
{ |
||||
glfwSwapBuffers(active_window); |
||||
} |
||||
|
||||
void window_set_size(int width, int height) |
||||
{ |
||||
glfwSetWindowSize(active_window, width, height); |
||||
} |
||||
|
||||
void window_resize(GLFWwindow* window, int width, int height) |
||||
{ |
||||
/* Maybe resize main frame buffer here? */ |
||||
if(window_resize_custom) window_resize_custom(width, height); |
||||
} |
||||
|
||||
GLFWwindow* window_get_active(void) |
||||
{ |
||||
return active_window; |
||||
} |
||||
|
||||
int window_should_close(void) |
||||
{ |
||||
return glfwWindowShouldClose(active_window); |
||||
} |
||||
|
||||
void window_set_should_close(int should_close) |
||||
{ |
||||
glfwSetWindowShouldClose(active_window, should_close ? GL_TRUE : GL_FALSE); |
||||
} |
||||
|
||||
void window_get_size(int* width, int* height) |
||||
{ |
||||
glfwGetWindowSize(active_window, width, height); |
||||
} |
@ -1,22 +0,0 @@ |
||||
#ifndef window_system_H |
||||
#define window_system_H |
||||
|
||||
struct GLFWwindow; |
||||
typedef struct GLFWwindow GLFWwindow; |
||||
|
||||
typedef void (*on_window_close) (void); // Callback for window close
|
||||
typedef void (*on_window_resize) (int, int); // Callback that recieves window resize event
|
||||
typedef void (*on_key) (int, int , int, int); // Callback for keyboard events
|
||||
typedef void (*on_mouse_pos) (double, double); // Callback for mouse position
|
||||
|
||||
int window_init(const char* title, int width, int height); |
||||
void window_cleanup(void); |
||||
void window_set_size(int width, int height); |
||||
void window_get_size(int* width, int* height); |
||||
void window_poll_events(void); |
||||
void window_swap_buffers(void); |
||||
int window_should_close(void); |
||||
void window_set_should_close(int should_close); |
||||
GLFWwindow* window_get_active(void); |
||||
|
||||
#endif |
Loading…
Reference in new issue