diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..93698f9 --- /dev/null +++ b/CMakeLists.txt @@ -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}) diff --git a/README b/README index 48930e2..763dcb3 100644 --- a/README +++ b/README @@ -30,35 +30,37 @@ _________________ .. 2.14 DONE Remove Kazmath dependency .. 2.15 DONE Entity .. 2.16 TODO Positive and negative values for input_maps and returning corresponding values when they are true -.. 2.17 DONE Textures -.. 2.18 DONE Camera -.. 2.19 DONE Test render -.. 2.20 TODO Bounding Boxes -.. 2.21 TODO File extension checking for asset loading -.. 2.22 DONE Materials -.. 2.23 DONE Mesh/Model -.. 2.24 TODO Add modifiers to input maps to enable combinations for example, c-x, m-k etc -.. 2.25 DONE Heirarchical Transforms -.. 2.26 DONE Materials with textures -.. 2.27 DONE Lights! -.. 2.28 DONE Fix problems with texture units -.. 2.29 CANCELED Draw light volumes -.. 2.30 TODO Fix problems with frustrum culling -.. 2.31 TODO 2d drawing routines -.. 2.32 TODO Gui -.. 2.33 CANCELED Image based lighting? -.. 2.34 CANCELED Deferred rendering? -.. 2.35 TODO Fix mouse bugs on windows -.. 2.36 TODO Physics -.. 2.37 TODO Variant type -.. 2.38 TODO Event Subsystem -.. 2.39 DONE Compile and test on windows -.. 2.40 TODO Array based string type comptible with cstring(char*) -.. 2.41 DONE Fix mouse bugs -.. 2.42 DONE Fix issues with opengl context showing 2.1 only -.. 2.43 TODO Improve this readme -.. 2.44 TODO ??? -.. 2.45 TODO Profit! +.. 2.17 DONE Find a permanent solution for build system +.. 2.18 TODO Text rendering using freetype or stb lib +.. 2.19 DONE Textures +.. 2.20 DONE Camera +.. 2.21 DONE Test render +.. 2.22 TODO Bounding Boxes +.. 2.23 TODO File extension checking for asset loading +.. 2.24 DONE Materials +.. 2.25 DONE Mesh/Model +.. 2.26 TODO Add modifiers to input maps to enable combinations for example, c-x, m-k etc +.. 2.27 DONE Heirarchical Transforms +.. 2.28 DONE Materials with textures +.. 2.29 DONE Lights! +.. 2.30 DONE Fix problems with texture units +.. 2.31 CANCELED Draw light volumes +.. 2.32 TODO Fix problems with frustrum culling +.. 2.33 TODO 2d drawing routines +.. 2.34 TODO Gui +.. 2.35 CANCELED Image based lighting? +.. 2.36 CANCELED Deferred rendering? +.. 2.37 TODO Fix mouse bugs on windows +.. 2.38 TODO Physics +.. 2.39 TODO Variant type +.. 2.40 TODO Event Subsystem +.. 2.41 DONE Compile and test on windows +.. 2.42 TODO Array based string type comptible with cstring(char*) +.. 2.43 DONE Fix mouse bugs +.. 2.44 DONE Fix issues with opengl context showing 2.1 only +.. 2.45 TODO Improve this readme +.. 2.46 TODO ??? +.. 2.47 TODO Profit! 1 Project Symmetry @@ -67,9 +69,7 @@ _________________ 1.1 What? ~~~~~~~~~ - An attempt to convert all previous code written in Project - Abstraction(written in C++) to C while using as few libraries as - possible. + A topdown 2D shooter exploring symmetry. 1.2 Why? @@ -191,152 +191,162 @@ _________________ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -2.17 DONE Textures +2.17 DONE Find a permanent solution for build system +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + - State "DONE" from "TODO" [2017-03-15 Wed 00:59] + + +2.18 TODO Text rendering using freetype or stb lib +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +2.19 DONE Textures ~~~~~~~~~~~~~~~~~~ - State "DONE" from "TODO" [2015-10-09 Fri 18:47] -2.18 DONE Camera +2.20 DONE Camera ~~~~~~~~~~~~~~~~ - State "DONE" from "TODO" [2015-08-19 Wed 13:30] -2.19 DONE Test render +2.21 DONE Test render ~~~~~~~~~~~~~~~~~~~~~ - State "DONE" from "TODO" [2015-08-19 Wed 13:30] -2.20 TODO Bounding Boxes +2.22 TODO Bounding Boxes ~~~~~~~~~~~~~~~~~~~~~~~~ - Recalculated bounding boxes for rotated meshes? -2.21 TODO File extension checking for asset loading +2.23 TODO File extension checking for asset loading ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -2.22 DONE Materials +2.24 DONE Materials ~~~~~~~~~~~~~~~~~~~ - State "DONE" from "TODO" [2015-10-13 Tue 19:38] -2.23 DONE Mesh/Model +2.25 DONE Mesh/Model ~~~~~~~~~~~~~~~~~~~~ - State "DONE" from "TODO" [2015-10-13 Tue 19:38] -2.24 TODO Add modifiers to input maps to enable combinations for example, c-x, m-k etc +2.26 TODO Add modifiers to input maps to enable combinations for example, c-x, m-k etc ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -2.25 DONE Heirarchical Transforms +2.27 DONE Heirarchical Transforms ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -2.26 DONE Materials with textures +2.28 DONE Materials with textures ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - State "DONE" from "TODO" [2015-10-15 Thu 21:21] -2.27 DONE Lights! +2.29 DONE Lights! ~~~~~~~~~~~~~~~~~ - State "DONE" from "TODO" [2017-03-14 Tue 00:31] -2.28 DONE Fix problems with texture units +2.30 DONE Fix problems with texture units ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - State "DONE" from "TODO" [2016-05-30 Mon 00:57] -2.29 CANCELED Draw light volumes +2.31 CANCELED Draw light volumes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - State "CANCELED" from "TODO" [2017-02-26 Sun 15:39] Deferred rendering on hold for now. -2.30 TODO Fix problems with frustrum culling +2.32 TODO Fix problems with frustrum culling ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Recalculate bounding boxes for rotated meshes? -2.31 TODO 2d drawing routines +2.33 TODO 2d drawing routines ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -2.32 TODO Gui +2.34 TODO Gui ~~~~~~~~~~~~~ -2.33 CANCELED Image based lighting? +2.35 CANCELED Image based lighting? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - State "CANCELED" from "TODO" [2017-03-14 Tue 00:31] Not a requirement for current project -2.34 CANCELED Deferred rendering? +2.36 CANCELED Deferred rendering? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - State "CANCELED" from "TODO" [2017-02-26 Sun 01:49] Sticking with forward rendering for now and focusing on tools etc. -2.35 TODO Fix mouse bugs on windows +2.37 TODO Fix mouse bugs on windows ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -2.36 TODO Physics +2.38 TODO Physics ~~~~~~~~~~~~~~~~~ -2.37 TODO Variant type +2.39 TODO Variant type ~~~~~~~~~~~~~~~~~~~~~~ -2.38 TODO Event Subsystem +2.40 TODO Event Subsystem ~~~~~~~~~~~~~~~~~~~~~~~~~ -2.39 DONE Compile and test on windows +2.41 DONE Compile and test on windows ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - State "DONE" from "TODO" [2017-03-14 Tue 00:32] -2.40 TODO Array based string type comptible with cstring(char*) +2.42 TODO Array based string type comptible with cstring(char*) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -2.41 DONE Fix mouse bugs +2.43 DONE Fix mouse bugs ~~~~~~~~~~~~~~~~~~~~~~~~ - State "DONE" from "TODO" [2017-03-01 Wed 00:45] -2.42 DONE Fix issues with opengl context showing 2.1 only +2.44 DONE Fix issues with opengl context showing 2.1 only ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - State "DONE" from "TODO" [2017-02-26 Sun 15:39] -2.43 TODO Improve this readme +2.45 TODO Improve this readme ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -2.44 TODO ??? +2.46 TODO ??? ~~~~~~~~~~~~~ -2.45 TODO Profit! +2.47 TODO Profit! ~~~~~~~~~~~~~~~~~ diff --git a/orgfile.org b/orgfile.org index ec27663..94a0a9b 100644 --- a/orgfile.org +++ b/orgfile.org @@ -4,8 +4,7 @@ * Project Symmetry ** What? -An attempt to convert all previous code written in Project Abstraction(written in C++) to C -while using as few libraries as possible. +A topdown 2D shooter exploring symmetry. ** Why? - To create a platform on which i will base further projects on. @@ -54,6 +53,9 @@ All the code in this repository is under GPLv3, see LICENSE for more information ** DONE Entity - State "DONE" from "TODO" [2015-09-15 Tue 12:17] ** TODO Positive and negative values for input_maps and returning corresponding values when they are true +** DONE Find a permanent solution for build system +- State "DONE" from "TODO" [2017-03-15 Wed 00:59] +** TODO Text rendering using freetype or stb lib ** DONE Textures - State "DONE" from "TODO" [2015-10-09 Fri 18:47] ** DONE Camera diff --git a/src/window_system.c b/src/window_system.c deleted file mode 100644 index e594150..0000000 --- a/src/window_system.c +++ /dev/null @@ -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); -} diff --git a/src/window_system.h b/src/window_system.h deleted file mode 100644 index 79b43d5..0000000 --- a/src/window_system.h +++ /dev/null @@ -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