Windows Support
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -7,3 +7,5 @@ CmakeCache.txt
|
||||
cmake_install.cmake
|
||||
Makefile
|
||||
GSM_TEMPLATE
|
||||
out/
|
||||
.vs/
|
||||
@@ -5,7 +5,7 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Release>:Release>")
|
||||
#set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Release>:Release>")
|
||||
|
||||
# Declare Project where "GSM_TEMPLATE" is the project name
|
||||
project(GSM_TEMPLATE LANGUAGES C CXX)
|
||||
@@ -40,10 +40,46 @@ FetchContent_Declare(
|
||||
FetchContent_MakeAvailable(stb_image)
|
||||
|
||||
|
||||
# If using the Windows compiler
|
||||
if (MSVC)
|
||||
|
||||
# Download freeglut
|
||||
FetchContent_Declare(
|
||||
freeglut
|
||||
GIT_REPOSITORY https://github.com/freeglut/freeglut.git
|
||||
GIT_TAG "master"
|
||||
GIT_SHALLOW TRUE
|
||||
GIT_PROGRESS ON
|
||||
)
|
||||
|
||||
# Force Freeglut to be a static library
|
||||
set(FREEGLUT_BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
|
||||
set(FREEGLUT_BUILD_STATIC_LIBS ON CACHE BOOL "" FORCE)
|
||||
|
||||
|
||||
FetchContent_MakeAvailable(freeglut)
|
||||
|
||||
|
||||
# Download Glad
|
||||
FetchContent_Declare(
|
||||
glad
|
||||
GIT_REPOSITORY https://github.com/Dav1dde/glad.git
|
||||
GIT_TAG "c"
|
||||
GIT_SHALLOW TRUE
|
||||
GIT_PROGRESS ON
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(glad)
|
||||
|
||||
endif()
|
||||
|
||||
# Tell Cmake to find the locations of libraries
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(GLUT REQUIRED)
|
||||
|
||||
# Only require glut if on macos
|
||||
if (APPLE)
|
||||
find_package(GLUT REQUIRED)
|
||||
endif()
|
||||
# Define MY_SOURCES to be a list of all the source files for my game
|
||||
file(GLOB_RECURSE MY_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp")
|
||||
|
||||
@@ -77,18 +113,9 @@ target_compile_definitions("${CMAKE_PROJECT_NAME}" PUBLIC RESOURCES_PATH="${CMAK
|
||||
# Add our sources
|
||||
target_sources("${CMAKE_PROJECT_NAME}" PRIVATE ${MY_SOURCES})
|
||||
|
||||
# If using the VS compiler
|
||||
if(MSVC)
|
||||
|
||||
target_compile_definitions("${CMAKE_PROJECT_NAME}" PUBLIC _CRT_SECURE_NO_WARNINGS)
|
||||
|
||||
#remove console
|
||||
#set_target_properties("${CMAKE_PROJECT_NAME}" PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
|
||||
|
||||
set_property(TARGET "${CMAKE_PROJECT_NAME}" PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreadedDebug<$<CONFIG:Debug>:Debug>")
|
||||
set_property(TARGET "${CMAKE_PROJECT_NAME}" PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Release>:Release>")
|
||||
|
||||
endif()
|
||||
# If on mac
|
||||
if (APPLE)
|
||||
|
||||
# Add our include files
|
||||
target_include_directories("${CMAKE_PROJECT_NAME}" PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include/")
|
||||
@@ -111,3 +138,43 @@ target_link_libraries("${CMAKE_PROJECT_NAME}"
|
||||
stb_image
|
||||
miniaudio
|
||||
)
|
||||
|
||||
|
||||
# If on windows
|
||||
elseif (MSVC)
|
||||
|
||||
target_compile_definitions("${CMAKE_PROJECT_NAME}" PUBLIC _CRT_SECURE_NO_WARNINGS)
|
||||
|
||||
#remove console
|
||||
#set_target_properties("${CMAKE_PROJECT_NAME}" PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
|
||||
|
||||
set_property(TARGET "${CMAKE_PROJECT_NAME}" PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreadedDebug<$<CONFIG:Debug>:Debug>")
|
||||
set_property(TARGET "${CMAKE_PROJECT_NAME}" PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Release>:Release>")
|
||||
|
||||
|
||||
target_sources("${CMAKE_PROJECT_NAME}" PRIVATE "${glad_SOURCE_DIR}/src/glad.c")
|
||||
target_include_directories("${CMAKE_PROJECT_NAME}" PUBLIC "${glad_SOURCE_DIR}/include")
|
||||
|
||||
|
||||
# Add our include files
|
||||
target_include_directories("${CMAKE_PROJECT_NAME}" PUBLIC
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include/"
|
||||
"${freeglut_SOURCE_DIR}/include"
|
||||
"${glad_SOURCE_DIR}/include"
|
||||
)
|
||||
|
||||
target_compile_definitions("${CMAKE_PROJECT_NAME}" PUBLIC use_freeglut=TRUE)
|
||||
target_compile_definitions("${CMAKE_PROJECT_NAME}" PUBLIC FREEGLUT_STATIC)
|
||||
|
||||
target_link_libraries("${CMAKE_PROJECT_NAME}"
|
||||
PRIVATE
|
||||
OpenGL::GL
|
||||
freeglut_static
|
||||
opengl32
|
||||
winmm
|
||||
gdi32
|
||||
stb_image
|
||||
miniaudio
|
||||
)
|
||||
|
||||
endif()
|
||||
@@ -16,7 +16,7 @@
|
||||
//#
|
||||
//#############################################################################
|
||||
#ifndef TEXTURES_H
|
||||
#define TEXTRUES_H
|
||||
#define TEXTRUES_H 1
|
||||
|
||||
|
||||
/**
|
||||
|
||||
19
src/main.cpp
19
src/main.cpp
@@ -51,7 +51,13 @@
|
||||
|
||||
|
||||
// Libraries
|
||||
#if defined(use_freeglut)
|
||||
# include <glad/glad.h>
|
||||
# define FREEGLUT_STATIC
|
||||
# include <gl/freeglut.h>
|
||||
#else
|
||||
# include <GLUT/glut.h>
|
||||
#endif
|
||||
#include <miniaudio.h>
|
||||
|
||||
// STD
|
||||
@@ -96,6 +102,9 @@ int lastWinW = 0, lastWinH = 0;
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
std:;cout << "Starting";
|
||||
fflush(stdout);
|
||||
|
||||
int winW = 1280;
|
||||
int winH = 720;
|
||||
|
||||
@@ -108,6 +117,11 @@ int main(int argc, char **argv)
|
||||
glutInitWindowPosition(0, 0);
|
||||
glutCreateWindow("Transform Example");
|
||||
|
||||
// This line only needs to run when glad is in use
|
||||
#if defined(use_freeglut)
|
||||
if (!gladLoadGL()) {}
|
||||
#endif
|
||||
|
||||
// Clear screen
|
||||
glClearColor(0.0, 0.0, 0.0, 1.0); // clear the window screen
|
||||
|
||||
@@ -137,10 +151,13 @@ int main(int argc, char **argv)
|
||||
// (This call will call the GlutLoopTimer() function immediately)
|
||||
glutTimerFunc(0, GlutLoopTimer, 0);
|
||||
|
||||
std:;cout << "Started";
|
||||
fflush(stdout);
|
||||
// Start the Glut Loop (Calls the funtions above repeatedly)
|
||||
glutMainLoop();
|
||||
|
||||
|
||||
std:;cout << "exited";
|
||||
fflush(stdout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,13 @@
|
||||
|
||||
|
||||
// Include STB
|
||||
#if defined(use_freeglut)
|
||||
# include <glad/glad.h>
|
||||
# define FREEGLUT_STATIC
|
||||
# include <gl/freeglut.h>
|
||||
#else
|
||||
# include <GLUT/glut.h>
|
||||
#endif
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#include <stb_image/stb_image.h>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user