From d3412d6a06ce29e1ba15fb548328fa3acb548ccb Mon Sep 17 00:00:00 2001 From: Matt Dodd Date: Thu, 9 Aug 2018 17:35:34 +1000 Subject: [PATCH 1/5] Add CMake Support Adds CMake support to the project along with a few small changes to the code base to allow for cross-platform builds. In order for this to work correctly, I have added glfw's git repository as a submodule so that it can be pulled down by those who want access to it, but without it needing to take up space in the actual AIE bootstrap repository. the top-level CMakeLists.txt file will build the bootstrap and any given projects. See project2D and project3D projects for example CMakeLists.txt files. --- .gitignore | 4 ++++ .gitmodules | 3 +++ CMakeLists.txt | 19 +++++++++++++++++++ bootstrap/Application.cpp | 2 +- bootstrap/CMakeLists.txt | 29 +++++++++++++++++++++++++++++ bootstrap/Font.cpp | 10 +++++++--- bootstrap/Renderer2D.cpp | 14 +++++++++++--- dependencies/glfw-source | 1 + project2D/Application2D.cpp | 7 ++++++- project2D/CMakeLists.txt | 8 ++++++++ project3D/CMakeLists.txt | 8 ++++++++ 11 files changed, 97 insertions(+), 8 deletions(-) create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 100644 bootstrap/CMakeLists.txt create mode 160000 dependencies/glfw-source create mode 100644 project2D/CMakeLists.txt create mode 100644 project3D/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 32d10ac2..cb3ef4d7 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,10 @@ x86/ bld/ [Oo]bj/ +#Cmake ignore +build/ +*/build/ #Make more restricted if a /build/ folder needs to be included + # Visual Studio 2015 cache/options directory .vs/ # Uncomment if you have tasks that create the project's static files in wwwroot diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..5f6b6509 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "dependencies/glfw-source"] + path = dependencies/glfw-source + url = https://github.com/glfw/glfw.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..a7baf41d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.2 FATAL_ERROR) +project(aieBootstrapProject) + +#TODO: Update to use the target_complile_requires +set(CMAKE_CXX_STANDARD 14) + +find_package(OpenGL REQUIRED) + + +#add build glfw +option(GLFW_BUILD_EXAMPLES NO) +option(GLFW_BUILD_TESTS NO) +add_subdirectory(${PROJECT_SOURCE_DIR}/dependencies/glfw-source) + +add_subdirectory(bootstrap) + + +#PROJECT TO BUILD +add_subdirectory(project3D) diff --git a/bootstrap/Application.cpp b/bootstrap/Application.cpp index 2ac36639..f01c2db3 100644 --- a/bootstrap/Application.cpp +++ b/bootstrap/Application.cpp @@ -144,7 +144,7 @@ void Application::setVSync(bool enable) { } void Application::setShowCursor(bool visible) { - ShowCursor(visible); + glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); } unsigned int Application::getWindowWidth() const { diff --git a/bootstrap/CMakeLists.txt b/bootstrap/CMakeLists.txt new file mode 100644 index 00000000..72dcf08c --- /dev/null +++ b/bootstrap/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 3.2 FATAL_ERROR) +project(aieBootstrap) + +add_library(${PROJECT_NAME} + Application.cpp + Font.cpp + Gizmos.cpp + Input.cpp + Renderer2D.cpp + Texture.cpp + gl_core_4_4.c + imgui_glfw3.cpp + ${CMAKE_SOURCE_DIR}/dependencies/imgui/imgui_draw.cpp + ${CMAKE_SOURCE_DIR}/dependencies/imgui/imgui.cpp + ) + +target_link_libraries(${PROJECT_NAME} + glfw + ${OPENGL_gl_LIBRARY} + ) + +target_include_directories(${PROJECT_NAME} PUBLIC + ${PROJECT_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/dependencies/glm + ${CMAKE_SOURCE_DIR}/dependencies/imgui + ${CMAKE_SOURCE_DIR}/dependencies/stb + ${CMAKE_SOURCE_DIR}/dependencies/glfw/include + ${CMAKE_SOURCE_DIR}/dependencies/openal/include + ) diff --git a/bootstrap/Font.cpp b/bootstrap/Font.cpp index 7e5274dc..fe86f5b0 100644 --- a/bootstrap/Font.cpp +++ b/bootstrap/Font.cpp @@ -15,15 +15,19 @@ Font::Font(const char* trueTypeFontFile, unsigned short fontHeight) m_textureHeight(0) { FILE* file = nullptr; +#ifdef _MSC_VER fopen_s(&file, trueTypeFontFile, "rb"); - if (file != nullptr) { +#else + file = fopen(trueTypeFontFile, "rb"); +#endif + if (file != nullptr) { unsigned char* ttf_buffer = new unsigned char[4096 * 1024]; fread(ttf_buffer, 1, 4096 * 1024, file); fclose(file); - // determine size of texture image + // determie size of texture image m_textureWidth = fontHeight / 16 * 256; m_textureHeight = fontHeight / 16 * 256; @@ -168,4 +172,4 @@ void Font::getStringRectangle(const char* str, float& x0, float& y0, float& x1, y1 *= -1; } -} // namepace aie \ No newline at end of file +} // namepace aie diff --git a/bootstrap/Renderer2D.cpp b/bootstrap/Renderer2D.cpp index c58aa665..18ea3ef1 100644 --- a/bootstrap/Renderer2D.cpp +++ b/bootstrap/Renderer2D.cpp @@ -34,7 +34,7 @@ Renderer2D::Renderer2D() { m_fontTexture[i] = 0; } - char* vertexShader = "#version 150\n \ + const char* vertexShader = "#version 150\n \ in vec4 position; \ in vec4 colour; \ in vec2 texcoord; \ @@ -45,7 +45,7 @@ Renderer2D::Renderer2D() { void main() { vColour = colour; vTexCoord = texcoord; vTextureID = position.w; \ gl_Position = projectionMatrix * vec4(position.x, position.y, position.z, 1.0f); }"; - char* fragmentShader = "#version 150\n \ + const char* fragmentShader = "#version 150\n \ in vec4 vColour; \ in vec2 vTexCoord; \ in float vTextureID; \ @@ -97,7 +97,11 @@ Renderer2D::Renderer2D() { // set texture locations char buf[32]; for (int i = 0; i < TEXTURE_STACK_SIZE; ++i) { +#ifdef _MSC_VER sprintf_s(buf, "textureStack[%i]", i); +#else + sprintf(buf, "textureStack[%i]", i); +#endif glUniform1i(glGetUniformLocation(m_shader, buf), i); } @@ -649,7 +653,11 @@ void Renderer2D::flushBatch() { return; char buf[32]; for (int i = 0; i < TEXTURE_STACK_SIZE; ++i) { +#ifdef _MSC_VER sprintf_s(buf, "isFontTexture[%i]", i); +#else + sprintf(buf, "isFontTexture[%i]", i); +#endif glUniform1i(glGetUniformLocation(m_shader, buf), m_fontTexture[i]); } @@ -732,4 +740,4 @@ void Renderer2D::rotateAround(float inX, float inY, float& outX, float& outY, fl outY = inX * sin + inY * cos; } -} // namespace aie \ No newline at end of file +} // namespace aie diff --git a/dependencies/glfw-source b/dependencies/glfw-source new file mode 160000 index 00000000..0be4f3f7 --- /dev/null +++ b/dependencies/glfw-source @@ -0,0 +1 @@ +Subproject commit 0be4f3f75aebd9d24583ee86590a38e741db0904 diff --git a/project2D/Application2D.cpp b/project2D/Application2D.cpp index 1415bb28..c89cd8af 100644 --- a/project2D/Application2D.cpp +++ b/project2D/Application2D.cpp @@ -2,6 +2,7 @@ #include "Texture.h" #include "Font.h" #include "Input.h" +#include Application2D::Application2D() { @@ -96,10 +97,14 @@ void Application2D::draw() { // output some text, uses the last used colour char fps[32]; +#ifdef _MSC_VER sprintf_s(fps, 32, "FPS: %i", getFPS()); +#else + sprintf(fps, "FPS: %i", getFPS()); +#endif m_2dRenderer->drawText(m_font, fps, 0, 720 - 32); m_2dRenderer->drawText(m_font, "Press ESC to quit!", 0, 720 - 64); // done drawing sprites m_2dRenderer->end(); -} \ No newline at end of file +} diff --git a/project2D/CMakeLists.txt b/project2D/CMakeLists.txt new file mode 100644 index 00000000..485e158b --- /dev/null +++ b/project2D/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.2 FATAL_ERROR) +project(project2D) + +add_executable(${PROJECT_NAME} + main.cpp + Application2D.cpp + ) +target_link_libraries(${PROJECT_NAME} aieBootstrap) diff --git a/project3D/CMakeLists.txt b/project3D/CMakeLists.txt new file mode 100644 index 00000000..d5c207be --- /dev/null +++ b/project3D/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.2 FATAL_ERROR) +project(project3D) + +add_executable(${PROJECT_NAME} + main.cpp + Application3D.cpp + ) +target_link_libraries(${PROJECT_NAME} aieBootstrap) From 0fb3fc6dd316ad21ea19bcc5894a63dcafe463ff Mon Sep 17 00:00:00 2001 From: Matt Dodd Date: Thu, 9 Aug 2018 17:35:34 +1000 Subject: [PATCH 2/5] Add CMake Support Adds CMake support to the project along with a few small changes to the code base to allow for cross-platform builds. In order for this to work correctly, I have added glfw's git repository as a submodule so that it can be pulled down by those who want access to it, but without it needing to take up space in the actual AIE bootstrap repository. the top-level CMakeLists.txt file will build the bootstrap and any given projects. See project2D and project3D projects for example CMakeLists.txt files. --- .gitignore | 4 ++++ .gitmodules | 3 +++ CMakeLists.txt | 19 +++++++++++++++++++ bootstrap/Application.cpp | 2 +- bootstrap/CMakeLists.txt | 29 +++++++++++++++++++++++++++++ bootstrap/Font.cpp | 8 ++++++-- bootstrap/Renderer2D.cpp | 14 +++++++++++--- dependencies/glfw-source | 1 + project2D/Application2D.cpp | 7 ++++++- project2D/CMakeLists.txt | 8 ++++++++ project3D/CMakeLists.txt | 8 ++++++++ 11 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 100644 bootstrap/CMakeLists.txt create mode 160000 dependencies/glfw-source create mode 100644 project2D/CMakeLists.txt create mode 100644 project3D/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 32d10ac2..cb3ef4d7 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,10 @@ x86/ bld/ [Oo]bj/ +#Cmake ignore +build/ +*/build/ #Make more restricted if a /build/ folder needs to be included + # Visual Studio 2015 cache/options directory .vs/ # Uncomment if you have tasks that create the project's static files in wwwroot diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..5f6b6509 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "dependencies/glfw-source"] + path = dependencies/glfw-source + url = https://github.com/glfw/glfw.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..a7baf41d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.2 FATAL_ERROR) +project(aieBootstrapProject) + +#TODO: Update to use the target_complile_requires +set(CMAKE_CXX_STANDARD 14) + +find_package(OpenGL REQUIRED) + + +#add build glfw +option(GLFW_BUILD_EXAMPLES NO) +option(GLFW_BUILD_TESTS NO) +add_subdirectory(${PROJECT_SOURCE_DIR}/dependencies/glfw-source) + +add_subdirectory(bootstrap) + + +#PROJECT TO BUILD +add_subdirectory(project3D) diff --git a/bootstrap/Application.cpp b/bootstrap/Application.cpp index 2ac36639..f01c2db3 100644 --- a/bootstrap/Application.cpp +++ b/bootstrap/Application.cpp @@ -144,7 +144,7 @@ void Application::setVSync(bool enable) { } void Application::setShowCursor(bool visible) { - ShowCursor(visible); + glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); } unsigned int Application::getWindowWidth() const { diff --git a/bootstrap/CMakeLists.txt b/bootstrap/CMakeLists.txt new file mode 100644 index 00000000..72dcf08c --- /dev/null +++ b/bootstrap/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 3.2 FATAL_ERROR) +project(aieBootstrap) + +add_library(${PROJECT_NAME} + Application.cpp + Font.cpp + Gizmos.cpp + Input.cpp + Renderer2D.cpp + Texture.cpp + gl_core_4_4.c + imgui_glfw3.cpp + ${CMAKE_SOURCE_DIR}/dependencies/imgui/imgui_draw.cpp + ${CMAKE_SOURCE_DIR}/dependencies/imgui/imgui.cpp + ) + +target_link_libraries(${PROJECT_NAME} + glfw + ${OPENGL_gl_LIBRARY} + ) + +target_include_directories(${PROJECT_NAME} PUBLIC + ${PROJECT_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/dependencies/glm + ${CMAKE_SOURCE_DIR}/dependencies/imgui + ${CMAKE_SOURCE_DIR}/dependencies/stb + ${CMAKE_SOURCE_DIR}/dependencies/glfw/include + ${CMAKE_SOURCE_DIR}/dependencies/openal/include + ) diff --git a/bootstrap/Font.cpp b/bootstrap/Font.cpp index 7e5274dc..86398fd4 100644 --- a/bootstrap/Font.cpp +++ b/bootstrap/Font.cpp @@ -15,8 +15,12 @@ Font::Font(const char* trueTypeFontFile, unsigned short fontHeight) m_textureHeight(0) { FILE* file = nullptr; +#ifdef _MSC_VER fopen_s(&file, trueTypeFontFile, "rb"); - if (file != nullptr) { +#else + file = fopen(trueTypeFontFile, "rb"); +#endif + if (file != nullptr) { unsigned char* ttf_buffer = new unsigned char[4096 * 1024]; @@ -168,4 +172,4 @@ void Font::getStringRectangle(const char* str, float& x0, float& y0, float& x1, y1 *= -1; } -} // namepace aie \ No newline at end of file +} // namepace aie diff --git a/bootstrap/Renderer2D.cpp b/bootstrap/Renderer2D.cpp index c58aa665..18ea3ef1 100644 --- a/bootstrap/Renderer2D.cpp +++ b/bootstrap/Renderer2D.cpp @@ -34,7 +34,7 @@ Renderer2D::Renderer2D() { m_fontTexture[i] = 0; } - char* vertexShader = "#version 150\n \ + const char* vertexShader = "#version 150\n \ in vec4 position; \ in vec4 colour; \ in vec2 texcoord; \ @@ -45,7 +45,7 @@ Renderer2D::Renderer2D() { void main() { vColour = colour; vTexCoord = texcoord; vTextureID = position.w; \ gl_Position = projectionMatrix * vec4(position.x, position.y, position.z, 1.0f); }"; - char* fragmentShader = "#version 150\n \ + const char* fragmentShader = "#version 150\n \ in vec4 vColour; \ in vec2 vTexCoord; \ in float vTextureID; \ @@ -97,7 +97,11 @@ Renderer2D::Renderer2D() { // set texture locations char buf[32]; for (int i = 0; i < TEXTURE_STACK_SIZE; ++i) { +#ifdef _MSC_VER sprintf_s(buf, "textureStack[%i]", i); +#else + sprintf(buf, "textureStack[%i]", i); +#endif glUniform1i(glGetUniformLocation(m_shader, buf), i); } @@ -649,7 +653,11 @@ void Renderer2D::flushBatch() { return; char buf[32]; for (int i = 0; i < TEXTURE_STACK_SIZE; ++i) { +#ifdef _MSC_VER sprintf_s(buf, "isFontTexture[%i]", i); +#else + sprintf(buf, "isFontTexture[%i]", i); +#endif glUniform1i(glGetUniformLocation(m_shader, buf), m_fontTexture[i]); } @@ -732,4 +740,4 @@ void Renderer2D::rotateAround(float inX, float inY, float& outX, float& outY, fl outY = inX * sin + inY * cos; } -} // namespace aie \ No newline at end of file +} // namespace aie diff --git a/dependencies/glfw-source b/dependencies/glfw-source new file mode 160000 index 00000000..0be4f3f7 --- /dev/null +++ b/dependencies/glfw-source @@ -0,0 +1 @@ +Subproject commit 0be4f3f75aebd9d24583ee86590a38e741db0904 diff --git a/project2D/Application2D.cpp b/project2D/Application2D.cpp index 1415bb28..c89cd8af 100644 --- a/project2D/Application2D.cpp +++ b/project2D/Application2D.cpp @@ -2,6 +2,7 @@ #include "Texture.h" #include "Font.h" #include "Input.h" +#include Application2D::Application2D() { @@ -96,10 +97,14 @@ void Application2D::draw() { // output some text, uses the last used colour char fps[32]; +#ifdef _MSC_VER sprintf_s(fps, 32, "FPS: %i", getFPS()); +#else + sprintf(fps, "FPS: %i", getFPS()); +#endif m_2dRenderer->drawText(m_font, fps, 0, 720 - 32); m_2dRenderer->drawText(m_font, "Press ESC to quit!", 0, 720 - 64); // done drawing sprites m_2dRenderer->end(); -} \ No newline at end of file +} diff --git a/project2D/CMakeLists.txt b/project2D/CMakeLists.txt new file mode 100644 index 00000000..485e158b --- /dev/null +++ b/project2D/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.2 FATAL_ERROR) +project(project2D) + +add_executable(${PROJECT_NAME} + main.cpp + Application2D.cpp + ) +target_link_libraries(${PROJECT_NAME} aieBootstrap) diff --git a/project3D/CMakeLists.txt b/project3D/CMakeLists.txt new file mode 100644 index 00000000..d5c207be --- /dev/null +++ b/project3D/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.2 FATAL_ERROR) +project(project3D) + +add_executable(${PROJECT_NAME} + main.cpp + Application3D.cpp + ) +target_link_libraries(${PROJECT_NAME} aieBootstrap) From b7a996d10aa3d618558fffa0d534a4a3c645a600 Mon Sep 17 00:00:00 2001 From: Matt Dodd Date: Thu, 9 Aug 2018 17:35:34 +1000 Subject: [PATCH 3/5] Add CMake Support Adds CMake support to the project along with a few small changes to the code base to allow for cross-platform builds. In order for this to work correctly, I have added glfw's git repository as a submodule so that it can be pulled down by those who want access to it, but without it needing to take up space in the actual AIE bootstrap repository. the top-level CMakeLists.txt file will build the bootstrap and any given projects. See project2D and project3D projects for example CMakeLists.txt files. --- .gitignore | 4 ++++ .gitmodules | 3 +++ CMakeLists.txt | 19 +++++++++++++++++++ bootstrap/Application.cpp | 2 +- bootstrap/CMakeLists.txt | 29 +++++++++++++++++++++++++++++ bootstrap/Font.cpp | 8 ++++++-- bootstrap/Renderer2D.cpp | 14 +++++++++++--- dependencies/glfw-source | 1 + project2D/Application2D.cpp | 7 ++++++- project2D/CMakeLists.txt | 8 ++++++++ project3D/CMakeLists.txt | 8 ++++++++ 11 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 100644 bootstrap/CMakeLists.txt create mode 160000 dependencies/glfw-source create mode 100644 project2D/CMakeLists.txt create mode 100644 project3D/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 32d10ac2..cb3ef4d7 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,10 @@ x86/ bld/ [Oo]bj/ +#Cmake ignore +build/ +*/build/ #Make more restricted if a /build/ folder needs to be included + # Visual Studio 2015 cache/options directory .vs/ # Uncomment if you have tasks that create the project's static files in wwwroot diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..5f6b6509 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "dependencies/glfw-source"] + path = dependencies/glfw-source + url = https://github.com/glfw/glfw.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..a7baf41d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 3.2 FATAL_ERROR) +project(aieBootstrapProject) + +#TODO: Update to use the target_complile_requires +set(CMAKE_CXX_STANDARD 14) + +find_package(OpenGL REQUIRED) + + +#add build glfw +option(GLFW_BUILD_EXAMPLES NO) +option(GLFW_BUILD_TESTS NO) +add_subdirectory(${PROJECT_SOURCE_DIR}/dependencies/glfw-source) + +add_subdirectory(bootstrap) + + +#PROJECT TO BUILD +add_subdirectory(project3D) diff --git a/bootstrap/Application.cpp b/bootstrap/Application.cpp index 2ac36639..f01c2db3 100644 --- a/bootstrap/Application.cpp +++ b/bootstrap/Application.cpp @@ -144,7 +144,7 @@ void Application::setVSync(bool enable) { } void Application::setShowCursor(bool visible) { - ShowCursor(visible); + glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); } unsigned int Application::getWindowWidth() const { diff --git a/bootstrap/CMakeLists.txt b/bootstrap/CMakeLists.txt new file mode 100644 index 00000000..72dcf08c --- /dev/null +++ b/bootstrap/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 3.2 FATAL_ERROR) +project(aieBootstrap) + +add_library(${PROJECT_NAME} + Application.cpp + Font.cpp + Gizmos.cpp + Input.cpp + Renderer2D.cpp + Texture.cpp + gl_core_4_4.c + imgui_glfw3.cpp + ${CMAKE_SOURCE_DIR}/dependencies/imgui/imgui_draw.cpp + ${CMAKE_SOURCE_DIR}/dependencies/imgui/imgui.cpp + ) + +target_link_libraries(${PROJECT_NAME} + glfw + ${OPENGL_gl_LIBRARY} + ) + +target_include_directories(${PROJECT_NAME} PUBLIC + ${PROJECT_SOURCE_DIR} + ${CMAKE_SOURCE_DIR}/dependencies/glm + ${CMAKE_SOURCE_DIR}/dependencies/imgui + ${CMAKE_SOURCE_DIR}/dependencies/stb + ${CMAKE_SOURCE_DIR}/dependencies/glfw/include + ${CMAKE_SOURCE_DIR}/dependencies/openal/include + ) diff --git a/bootstrap/Font.cpp b/bootstrap/Font.cpp index 7e5274dc..86398fd4 100644 --- a/bootstrap/Font.cpp +++ b/bootstrap/Font.cpp @@ -15,8 +15,12 @@ Font::Font(const char* trueTypeFontFile, unsigned short fontHeight) m_textureHeight(0) { FILE* file = nullptr; +#ifdef _MSC_VER fopen_s(&file, trueTypeFontFile, "rb"); - if (file != nullptr) { +#else + file = fopen(trueTypeFontFile, "rb"); +#endif + if (file != nullptr) { unsigned char* ttf_buffer = new unsigned char[4096 * 1024]; @@ -168,4 +172,4 @@ void Font::getStringRectangle(const char* str, float& x0, float& y0, float& x1, y1 *= -1; } -} // namepace aie \ No newline at end of file +} // namepace aie diff --git a/bootstrap/Renderer2D.cpp b/bootstrap/Renderer2D.cpp index c58aa665..18ea3ef1 100644 --- a/bootstrap/Renderer2D.cpp +++ b/bootstrap/Renderer2D.cpp @@ -34,7 +34,7 @@ Renderer2D::Renderer2D() { m_fontTexture[i] = 0; } - char* vertexShader = "#version 150\n \ + const char* vertexShader = "#version 150\n \ in vec4 position; \ in vec4 colour; \ in vec2 texcoord; \ @@ -45,7 +45,7 @@ Renderer2D::Renderer2D() { void main() { vColour = colour; vTexCoord = texcoord; vTextureID = position.w; \ gl_Position = projectionMatrix * vec4(position.x, position.y, position.z, 1.0f); }"; - char* fragmentShader = "#version 150\n \ + const char* fragmentShader = "#version 150\n \ in vec4 vColour; \ in vec2 vTexCoord; \ in float vTextureID; \ @@ -97,7 +97,11 @@ Renderer2D::Renderer2D() { // set texture locations char buf[32]; for (int i = 0; i < TEXTURE_STACK_SIZE; ++i) { +#ifdef _MSC_VER sprintf_s(buf, "textureStack[%i]", i); +#else + sprintf(buf, "textureStack[%i]", i); +#endif glUniform1i(glGetUniformLocation(m_shader, buf), i); } @@ -649,7 +653,11 @@ void Renderer2D::flushBatch() { return; char buf[32]; for (int i = 0; i < TEXTURE_STACK_SIZE; ++i) { +#ifdef _MSC_VER sprintf_s(buf, "isFontTexture[%i]", i); +#else + sprintf(buf, "isFontTexture[%i]", i); +#endif glUniform1i(glGetUniformLocation(m_shader, buf), m_fontTexture[i]); } @@ -732,4 +740,4 @@ void Renderer2D::rotateAround(float inX, float inY, float& outX, float& outY, fl outY = inX * sin + inY * cos; } -} // namespace aie \ No newline at end of file +} // namespace aie diff --git a/dependencies/glfw-source b/dependencies/glfw-source new file mode 160000 index 00000000..0be4f3f7 --- /dev/null +++ b/dependencies/glfw-source @@ -0,0 +1 @@ +Subproject commit 0be4f3f75aebd9d24583ee86590a38e741db0904 diff --git a/project2D/Application2D.cpp b/project2D/Application2D.cpp index 1415bb28..c89cd8af 100644 --- a/project2D/Application2D.cpp +++ b/project2D/Application2D.cpp @@ -2,6 +2,7 @@ #include "Texture.h" #include "Font.h" #include "Input.h" +#include Application2D::Application2D() { @@ -96,10 +97,14 @@ void Application2D::draw() { // output some text, uses the last used colour char fps[32]; +#ifdef _MSC_VER sprintf_s(fps, 32, "FPS: %i", getFPS()); +#else + sprintf(fps, "FPS: %i", getFPS()); +#endif m_2dRenderer->drawText(m_font, fps, 0, 720 - 32); m_2dRenderer->drawText(m_font, "Press ESC to quit!", 0, 720 - 64); // done drawing sprites m_2dRenderer->end(); -} \ No newline at end of file +} diff --git a/project2D/CMakeLists.txt b/project2D/CMakeLists.txt new file mode 100644 index 00000000..485e158b --- /dev/null +++ b/project2D/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.2 FATAL_ERROR) +project(project2D) + +add_executable(${PROJECT_NAME} + main.cpp + Application2D.cpp + ) +target_link_libraries(${PROJECT_NAME} aieBootstrap) diff --git a/project3D/CMakeLists.txt b/project3D/CMakeLists.txt new file mode 100644 index 00000000..d5c207be --- /dev/null +++ b/project3D/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.2 FATAL_ERROR) +project(project3D) + +add_executable(${PROJECT_NAME} + main.cpp + Application3D.cpp + ) +target_link_libraries(${PROJECT_NAME} aieBootstrap) From be6e70edc90efbf5ddd2137a9cadd0df3c1d42f6 Mon Sep 17 00:00:00 2001 From: Matt Dodd Date: Thu, 9 Aug 2018 18:01:51 +1000 Subject: [PATCH 4/5] Finish adding CMake Support --- bootstrap/Font.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bootstrap/Font.cpp b/bootstrap/Font.cpp index fe86f5b0..86398fd4 100644 --- a/bootstrap/Font.cpp +++ b/bootstrap/Font.cpp @@ -27,7 +27,7 @@ Font::Font(const char* trueTypeFontFile, unsigned short fontHeight) fread(ttf_buffer, 1, 4096 * 1024, file); fclose(file); - // determie size of texture image + // determine size of texture image m_textureWidth = fontHeight / 16 * 256; m_textureHeight = fontHeight / 16 * 256; From 7536d7a79daf4cfdab5f55f7121c2d24fec61200 Mon Sep 17 00:00:00 2001 From: Matt Dodd Date: Thu, 9 Aug 2018 18:07:41 +1000 Subject: [PATCH 5/5] Call ShowCursor on windows, othwerwise use glfwSetInputMode --- bootstrap/Application.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/bootstrap/Application.cpp b/bootstrap/Application.cpp index f01c2db3..9f8ed329 100644 --- a/bootstrap/Application.cpp +++ b/bootstrap/Application.cpp @@ -144,7 +144,11 @@ void Application::setVSync(bool enable) { } void Application::setShowCursor(bool visible) { - glfwSetInputMode(m_window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN); +#ifdef _MSC_VER + ShowCursor(visible); +#else + glfwSetInputMode(m_window, GLFW_CURSOR, visible ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_HIDDEN); +#endif } unsigned int Application::getWindowWidth() const {