Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glad support and a few other things #105

Open
wants to merge 17 commits into
base: gwork
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CMake build instructions for Gwork

# configure cmake
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)

# we require C++11 - this set appropriate flags for compilers, which may not be portable
set(CMAKE_CXX_STANDARD 14)
Expand Down
39 changes: 32 additions & 7 deletions cmake/Config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ if(WIN32 AND NOT UNIX)
set(INSTALL_MISC_DIR .)

# Determine the target architecture, which is useful for linking.
if (CMAKE_GENERATOR MATCHES "Win64")
cmake_host_system_information(RESULT host_is_64 QUERY IS_64BIT)

if (host_is_64)
set(GWK_TARGET_ARCH "x64")
else()
set(GWK_TARGET_ARCH "x86")
Expand Down Expand Up @@ -172,14 +174,37 @@ if(RENDER_OPENGL_CORE)
set(GWK_INPUT_NAME "GLFW3")
set(GWK_PLATFORM_NAME "Cross")

find_package(glm REQUIRED)
find_package(GLEW REQUIRED)
if(USE_VCPKG)
find_package(glm CONFIG REQUIRED)
set(GLM_INCLUDE_DIR ${glm_DIR})
else()
find_package(glm REQUIRED)
endif()

if(USE_GLEW)
find_package(GLEW REQUIRED)
set(GWK_RENDER_INCLUDES "${GLM_INCLUDE_DIR}" "${GLEW_INCLUDE_DIR}")
set(GWK_RENDER_LIBRARIES ${GLM_LIBRARIES} ${GLEW_LIBRARIES})
elseif(USE_GLAD)
find_package(glad CONFIG REQUIRED)
set(GWK_RENDER_LIBRARIES ${GLM_LIBRARIES} glad::glad)
set(GWK_GLAD_API "GLAD")
endif()

set(GWK_RENDER_INCLUDES "${GLM_INCLUDE_DIR}" "${GLEW_INCLUDE_DIR}")
set(GWK_RENDER_LIBRARIES ${GLM_LIBRARIES} ${GLEW_LIBRARIES})

if(USE_GLFW)
find_package(GLFW REQUIRED)

if(USE_VCPKG)
find_package(glfw3 CONFIG REQUIRED)
elseif()
find_package(GLFW REQUIRED)
endif()

if(USE_VCPKG)
set(GLFW_LIBRARIES glfw)
set(GLFW_INCLUDE_DIR ${glfw3_DIR})
endif()

if (APPLE)
set(GLFW_DEPENDENCIES "-framework OpenGL")
elseif(UNIX)
Expand Down Expand Up @@ -263,7 +288,7 @@ endif()
#-----------------------------------------------------------

# MinGW problems
if (WIN32)
if (CMAKE_CXX_COMPILER_ID MATCHES MINGW)
set(GWK_RENDER_LIBRARIES ${GWK_RENDER_LIBRARIES} -liconv)
endif()

Expand Down
4 changes: 4 additions & 0 deletions source/platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ source_group("${GWK_SOURCE_FOLDER}"

add_definitions(${GWK_LIB_DEFINES})

if(GWK_GLAD_API)
add_definitions("-DGWK_GL_GLAD=1")
endif()

# Gwork renderer & platform library
add_library(Gwork${GWK_RENDER_NAME} STATIC
${GWK_PLATFORM_HEADERS} ${GWK_RENDERER_HEADERS} ${GWK_INPUT_HEADERS}
Expand Down
8 changes: 8 additions & 0 deletions source/platform/renderers/OpenGLCore/OpenGLCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@

#include <Gwork/Renderers/OpenGLCore.h>
#if defined(__APPLE__)
#if defined(GWK_GL_GLAD)
# include <glad/glad.h>
#else
# include <GL/glew.h>
#endif
# include <OpenGL/gl.h>
#else
#if defined(GWK_GL_GLAD)
# include <glad/glad.h>
#else
# include <GL/glew.h>
#endif
# include <GL/gl.h>
#endif
#include <Gwork/PlatformTypes.h>
Expand Down
4 changes: 4 additions & 0 deletions source/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ if(WITH_SAMPLE)

add_definitions(-DGWK_SAMPLE -DGWK_SAMPLE_RESOURCE_DIR="${APP_RUNTIME_RESOURCE_DIR}")

if(GWK_GLAD_API)
add_definitions("-DGWK_GL_GLAD=1")
endif()

add_executable(${SAMPLE_NAME} ${APP_BUILD_TYPE} ${SAMPLE_SOURCES} ${SAMPLE_RESOURCES})

target_link_libraries(${SAMPLE_NAME}
Expand Down
22 changes: 18 additions & 4 deletions source/samples/OpenGLCore/OpenGLCoreSample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
* Copyright (c) 2013-2018 Billy Quith
* See license in Gwork.h
*/

#include <GL/glew.h>

#if defined(GWK_GL_GLAD)
# include <glad/glad.h>
#else
# include <GL/glew.h>
#endif
#ifdef USE_DEBUG_FONT
# include <Gwork/Renderers/OpenGL_DebugFont.h>
#else
Expand Down Expand Up @@ -49,7 +53,7 @@ int main()
return EXIT_FAILURE;

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);

Expand All @@ -63,6 +67,15 @@ int main()
}

glfwMakeContextCurrent(window);

#if defined(GWK_GL_GLAD)
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
{
std::cout << "Glad init error." << std::endl;
glfwTerminate();
return EXIT_FAILURE;
}
#else
glewExperimental = GL_TRUE;
GLuint error;
if ((error = glewInit()) != GLEW_OK)
Expand All @@ -71,6 +84,7 @@ int main()
glfwTerminate();
return EXIT_FAILURE;
}
#endif

Gwk::Platform::RelativeToExecutablePaths paths(GWK_SAMPLE_RESOURCE_DIR);

Expand All @@ -95,7 +109,7 @@ int main()
canvas->SetBackgroundColor(Gwk::Color(150, 170, 170, 255));

// Create our unittest control (which is a Window with controls in it)
auto unit = new TestFrame(canvas);
auto unit = new Gwk::Test::TestFrame(canvas);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might have been my compiler settings causing this, but my compiler didn't like the namespaces not being there.

GworkInput.Initialize(canvas);

glfwSetKeyCallback(window, key_callback);
Expand Down
4 changes: 2 additions & 2 deletions source/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ include_directories(
${GWK_SOURCE_DIR}/source/platform/include
${GWK_SOURCE_DIR}/source/gwork/include
${GWK_RENDER_INCLUDES}
${CMAKE_SOURCE_DIR}/source/util/include
${CMAKE_SOURCE_DIR}/source/test/include
${GWK_SOURCE_DIR}/source/util/include
${GWK_SOURCE_DIR}/source/test/include
${GWK_REFLECT_INCLUDE}
)

Expand Down