Pre-removing GLEW, in favour of GLAD
This commit is contained in:
parent
e184b1c910
commit
aac84fabcf
@ -6,36 +6,66 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # For my Clangd LSP
|
|||||||
# endif()
|
# endif()
|
||||||
|
|
||||||
set(GLFW_BUILD_WAYLAND OFF) # This should be detected and not forced
|
set(GLFW_BUILD_WAYLAND OFF) # This should be detected and not forced
|
||||||
|
set(BUILD_SHARED_LIBS OFF) # Keep the project as one binary (glew, glm)
|
||||||
|
set(GLM__BUILD_TESTS OFF) # Don't build GLM tests
|
||||||
|
set(GLFW_BUILD_EXAMPLES OFF) # Don't build GLFW Examples
|
||||||
|
set(GLFW_BUILD_TESTS OFF) # Don't build GLFW Tests
|
||||||
|
set(GLFW_INSTALL OFF) # We're not building a standalone
|
||||||
|
# set(GLEW_BUILD_DOCS $<CONFIG:Debug>) # Build docs if debug
|
||||||
|
set(SOIL2_BUILD_TESTS OFF) # Don't build SOIL2 Tests
|
||||||
|
|
||||||
|
|
||||||
find_package(OpenGL REQUIRED)
|
find_package(OpenGL REQUIRED)
|
||||||
|
|
||||||
if(CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
|
if(CMAKE_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR)
|
||||||
message(FATAL_ERROR "You fucking smell fr")
|
message(FATAL_ERROR "You fucking smell fr\n")
|
||||||
endif()
|
endif()
|
||||||
if(CMAKE_SOURCE_DIR MATCHES " ")
|
if(CMAKE_SOURCE_DIR MATCHES " ")
|
||||||
message("Spaces in the source dir can cause errors, thou art been warned")
|
message(WARNING "Spaces in the source dir can cause errors, thou art been warned\n")
|
||||||
endif()
|
endif()
|
||||||
if(CMAKE_BIANRY_DIR MATCHES " ")
|
if(CMAKE_BINARY_DIR MATCHES " ")
|
||||||
message("Spaces in the build dir can cause errors, thou art been warned")
|
message(WARNING "Spaces in the build dir can cause errors, thou art been warned\n")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(LINUX)
|
if(UNIX)
|
||||||
|
message(STATUS "Configuring GLEW for *nix (Non-cmake)\n")
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${PROJECT_SOURCE_DIR}/include/glew/src/glew.c
|
OUTPUT ${PROJECT_SOURCE_DIR}/include/glew/src/glew.c
|
||||||
${PROJECT_SOURCE_DIR}/include/glewinfo.c
|
${PROJECT_SOURCE_DIR}/include/glewinfo.c
|
||||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/include/glew/auto
|
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/include/glew/auto
|
||||||
COMMAND ${CMAKE_MAKE_PROGRAM})
|
COMMAND ${CMAKE_MAKE_PROGRAM})
|
||||||
|
|
||||||
|
add_subdirectory(include/glew/build/cmake)
|
||||||
|
|
||||||
|
if(NOT (EXISTS "${PROJECT_SOURCE_DIR}/include/glew/src/glew.c" AND EXISTS "${PROJECT_SOURCE_DIR}/include/glewinfo.c"))
|
||||||
|
message(FATAL_ERROR "GLEW failed to configure!")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
add_custom_command(
|
message(STATUS "Download GLEW for Windows (Non-cmake)\n") # I wanted to make this work from source, but the auto config is make only, and requiring and/or shipping msys2 would be unreasonable so this is the best compromise
|
||||||
OUTPUT ${PROJECT_SOURCE_DIR}/include (glew) /src/glew.c
|
file(DOWNLOAD https://github.com/nigels-com/glew/releases/download/glew-2.2.0/glew-2.2.0-win32.zip ${CMAKE_BINARY_DIR}/glew-2.2.0.zip)
|
||||||
${PROJECT_SOURCE_DIR}/include/glewinfo.c
|
execute_process(COMMAND tar -xf ${CMAKE_BINARY_DIR}/glew-2.2.0.zip # bdstar
|
||||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/include/glew/build/vc15
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||||
COMMAND ${CMAKE_VS_MSBUILD_COMMAND})
|
|
||||||
|
if(NOT EXISTS ${CMAKE_BINARY_DIR}/glew-2.2.0/include/GL/glew.h)
|
||||||
|
message(FATAL_ERROR "GLEW Failed to download/decompress")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include_directories(${CMAKE_BINARY_DIR}/glew-2.2.0/include)
|
||||||
|
add_library(glew STATIC # There aren't actually any binaries in here, so no lib is to be built
|
||||||
|
${CMAKE_BINARY_DIR}/glew-2.2.0/include/GL/eglew.h
|
||||||
|
${CMAKE_BINARY_DIR}/glew-2.2.0/include/GL/glew.h
|
||||||
|
${CMAKE_BINARY_DIR}/glew-2.2.0/include/GL/glxew.h
|
||||||
|
${CMAKE_BINARY_DIR}/glew-2.2.0/include/GL/wglew.h)
|
||||||
|
set_target_properties(glew PROPERTIES LINKER_LANGUAGE C)
|
||||||
|
if(CMAKE_SIZEOF_VOID_P EQUAL 8) # 64-bit
|
||||||
|
target_link_libraries(glew ${CMAKE_BINARY_DIR}/glew-2.2.0/lib/Release/x64/glew32.lib ${CMAKE_BINARY_DIR}/glew-2.2.0/lib/Release/x64/glew32s.lib)
|
||||||
|
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4) # 32-bit, if it's not either of these you're in trouble
|
||||||
|
target_link_libraries(glew ${CMAKE_BINARY_DIR}/glew-2.2.0/lib/Release/Win32/glew32.lib ${CMAKE_BINARY_DIR}/glew-2.2.0/lib/Release/Win32/glew32s.lib)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_subdirectory(include/glm)
|
add_subdirectory(include/glm)
|
||||||
add_subdirectory(include/glew/build/cmake)
|
|
||||||
add_subdirectory(include/glfw)
|
add_subdirectory(include/glfw)
|
||||||
add_subdirectory(include/SOIL2)
|
add_subdirectory(include/SOIL2)
|
||||||
add_subdirectory(include/assimp)
|
add_subdirectory(include/assimp)
|
||||||
@ -43,7 +73,7 @@ add_subdirectory(include/CLog)
|
|||||||
|
|
||||||
include_directories(include/imgui)
|
include_directories(include/imgui)
|
||||||
add_library(
|
add_library(
|
||||||
imgui
|
imgui STATIC
|
||||||
include/imgui/imgui.cpp
|
include/imgui/imgui.cpp
|
||||||
include/imgui/imgui_demo.cpp
|
include/imgui/imgui_demo.cpp
|
||||||
include/imgui/imgui_draw.cpp
|
include/imgui/imgui_draw.cpp
|
||||||
@ -54,13 +84,26 @@ add_library(
|
|||||||
target_link_libraries(imgui glfw)
|
target_link_libraries(imgui glfw)
|
||||||
|
|
||||||
add_executable(fred engine.cpp shader.c)
|
add_executable(fred engine.cpp shader.c)
|
||||||
|
if (UNIX)
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
fred
|
fred
|
||||||
-lm
|
-lm
|
||||||
glm
|
|
||||||
glew
|
glew
|
||||||
|
glm
|
||||||
glfw
|
glfw
|
||||||
soil2
|
soil2
|
||||||
assimp
|
assimp
|
||||||
imgui
|
imgui
|
||||||
clog)
|
clog)
|
||||||
|
endif()
|
||||||
|
if (WIN32)
|
||||||
|
target_link_libraries(
|
||||||
|
fred
|
||||||
|
glew
|
||||||
|
glm
|
||||||
|
glfw
|
||||||
|
soil2
|
||||||
|
assimp
|
||||||
|
imgui
|
||||||
|
clog)
|
||||||
|
endif()
|
12
engine.cpp
12
engine.cpp
@ -21,18 +21,16 @@
|
|||||||
#include <assimp/postprocess.h>
|
#include <assimp/postprocess.h>
|
||||||
#include <assimp/scene.h>
|
#include <assimp/scene.h>
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
#include "shader.h"
|
#include "shader.h"
|
||||||
}
|
|
||||||
|
|
||||||
#define WIDTH 1024
|
constexpr int WIDTH = 1024;
|
||||||
#define HEIGHT 768
|
constexpr int HEIGHT = 768;
|
||||||
|
|
||||||
static void glfwErrorCallback(int e, const char *description) {
|
static void glfwErrorCallback(int e, const char *description) {
|
||||||
clog_log(CLOG_LEVEL_ERROR, "GLFW Error %d: %s", e, description);
|
clog_log(CLOG_LEVEL_ERROR, "GLFW Error %d: %s", e, description);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool loadModel(const char *path, std::vector<unsigned short> &indices,
|
static bool loadModel(const char *path, std::vector<unsigned short> &indices,
|
||||||
std::vector<glm::vec3> &vertices, std::vector<glm::vec2> &uvs,
|
std::vector<glm::vec3> &vertices, std::vector<glm::vec2> &uvs,
|
||||||
std::vector<glm::vec3> &normals) {
|
std::vector<glm::vec3> &normals) {
|
||||||
Assimp::Importer importer;
|
Assimp::Importer importer;
|
||||||
@ -68,7 +66,7 @@ bool loadModel(const char *path, std::vector<unsigned short> &indices,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int initWindow() {
|
static int initWindow() {
|
||||||
glfwSetErrorCallback(glfwErrorCallback);
|
glfwSetErrorCallback(glfwErrorCallback);
|
||||||
|
|
||||||
glewExperimental = true;
|
glewExperimental = true;
|
||||||
@ -317,7 +315,7 @@ int initWindow() {
|
|||||||
// Index buffer
|
// Index buffer
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBuffer);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBuffer);
|
||||||
|
|
||||||
glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_SHORT, (void *)0);
|
glDrawElements(GL_TRIANGLES, (GLsizei)indices.size(), GL_UNSIGNED_SHORT, (void *)0);
|
||||||
|
|
||||||
glDisableVertexAttribArray(0);
|
glDisableVertexAttribArray(0);
|
||||||
glDisableVertexAttribArray(1);
|
glDisableVertexAttribArray(1);
|
||||||
|
49
shader.c
49
shader.c
@ -18,30 +18,31 @@ GLuint loadShaders(const char *vertex_file_path,
|
|||||||
GLuint vertexShaderID = glCreateShader(GL_VERTEX_SHADER);
|
GLuint vertexShaderID = glCreateShader(GL_VERTEX_SHADER);
|
||||||
GLuint fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
|
GLuint fragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
|
||||||
|
|
||||||
|
errno_t err;
|
||||||
|
|
||||||
FILE *vertexShaderFD;
|
FILE *vertexShaderFD;
|
||||||
vertexShaderFD = fopen(vertex_file_path, "rb");
|
if (err = fopen_s(&vertexShaderFD, vertex_file_path, "rb")) {
|
||||||
if (vertexShaderFD == NULL) {
|
clog_log(CLOG_LEVEL_ERROR, "Failed to open Vertex Shader \"%s\": %s", vertex_file_path, err);
|
||||||
fclose(vertexShaderFD);
|
return 0;
|
||||||
clog_log(CLOG_LEVEL_ERROR, "Failed to open Vertex Shader");
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
int vertexShaderLength = lseek(fileno(vertexShaderFD), 0L, SEEK_END) + 1;
|
int vertexShaderLength = lseek(fileno(vertexShaderFD), 0L, SEEK_END) + 1;
|
||||||
fseek(vertexShaderFD, 0L, SEEK_SET);
|
fseek(vertexShaderFD, 0L, SEEK_SET);
|
||||||
char *vertexShaderCode = (char *)calloc(vertexShaderLength, sizeof(char));
|
char *vertexShaderCode = (char *)calloc(vertexShaderLength, sizeof(char));
|
||||||
|
clog_assert(vertexShaderCode != NULL);
|
||||||
|
clog_assert(7 != 7);
|
||||||
fread(vertexShaderCode, sizeof(*vertexShaderCode), vertexShaderLength,
|
fread(vertexShaderCode, sizeof(*vertexShaderCode), vertexShaderLength,
|
||||||
vertexShaderFD);
|
vertexShaderFD);
|
||||||
fclose(vertexShaderFD);
|
fclose(vertexShaderFD);
|
||||||
|
|
||||||
FILE *fragmentShaderFD;
|
FILE *fragmentShaderFD;
|
||||||
fragmentShaderFD = fopen(fragment_file_path, "rb");
|
if (fopen_s(&fragmentShaderFD, fragment_file_path, "rb")) {
|
||||||
if (fragmentShaderFD == NULL) {
|
clog_log(CLOG_LEVEL_ERROR, "Failed to open Vertex Shader \"%s\": %s", fragment_file_path, err);
|
||||||
fclose(fragmentShaderFD);
|
return 0;
|
||||||
clog_log(CLOG_LEVEL_ERROR, "Failed to open Fragment Shader");
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
int fragmentShaderLength = lseek(fileno(fragmentShaderFD), 0L, SEEK_END) + 1;
|
int fragmentShaderLength = lseek(fileno(fragmentShaderFD), 0L, SEEK_END) + 1;
|
||||||
fseek(fragmentShaderFD, 0L, SEEK_SET);
|
fseek(fragmentShaderFD, 0L, SEEK_SET);
|
||||||
char *fragmentShaderCode = (char *)calloc(fragmentShaderLength, sizeof(char));
|
char *fragmentShaderCode = (char *)calloc(fragmentShaderLength, sizeof(char));
|
||||||
|
clog_assert(fragmentShaderCode != NULL);
|
||||||
fread(fragmentShaderCode, sizeof(*fragmentShaderCode), fragmentShaderLength,
|
fread(fragmentShaderCode, sizeof(*fragmentShaderCode), fragmentShaderLength,
|
||||||
fragmentShaderFD);
|
fragmentShaderFD);
|
||||||
fclose(fragmentShaderFD);
|
fclose(fragmentShaderFD);
|
||||||
@ -57,10 +58,12 @@ GLuint loadShaders(const char *vertex_file_path,
|
|||||||
glGetShaderiv(vertexShaderID, GL_COMPILE_STATUS, &result);
|
glGetShaderiv(vertexShaderID, GL_COMPILE_STATUS, &result);
|
||||||
glGetShaderiv(vertexShaderID, GL_INFO_LOG_LENGTH, &infoLogLength);
|
glGetShaderiv(vertexShaderID, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||||
if (infoLogLength > 0) {
|
if (infoLogLength > 0) {
|
||||||
char *vertexShaderErrorMessage[infoLogLength + 1];
|
infoLogLength += 1; // Prevents a sub-expression overflow false positive
|
||||||
glGetShaderInfoLog(vertexShaderID, infoLogLength, NULL,
|
char *vertexShaderErrorMessage = (char*)malloc(infoLogLength * sizeof(char)); // Not all compilers support VLAs, this will do
|
||||||
*vertexShaderErrorMessage);
|
glGetShaderInfoLog(vertexShaderID, infoLogLength-1, NULL,
|
||||||
clog_log(CLOG_LEVEL_ERROR, "%s", *vertexShaderErrorMessage);
|
vertexShaderErrorMessage);
|
||||||
|
clog_log(CLOG_LEVEL_ERROR, "%s", vertexShaderErrorMessage);
|
||||||
|
free(vertexShaderErrorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
clog_log(CLOG_LEVEL_DEBUG, "Compiling shader: %s", fragment_file_path);
|
clog_log(CLOG_LEVEL_DEBUG, "Compiling shader: %s", fragment_file_path);
|
||||||
@ -71,10 +74,12 @@ GLuint loadShaders(const char *vertex_file_path,
|
|||||||
glGetShaderiv(fragmentShaderID, GL_COMPILE_STATUS, &result);
|
glGetShaderiv(fragmentShaderID, GL_COMPILE_STATUS, &result);
|
||||||
glGetShaderiv(fragmentShaderID, GL_INFO_LOG_LENGTH, &infoLogLength);
|
glGetShaderiv(fragmentShaderID, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||||
if (infoLogLength > 0) {
|
if (infoLogLength > 0) {
|
||||||
char *fragmentShaderErrorMessage[infoLogLength + 1];
|
infoLogLength += 1; // Prevents a sub-expression overflow false positive
|
||||||
glGetShaderInfoLog(fragmentShaderID, infoLogLength, NULL,
|
char *fragmentShaderErrorMessage = (char*)malloc(infoLogLength * sizeof(char));
|
||||||
*fragmentShaderErrorMessage);
|
glGetShaderInfoLog(fragmentShaderID, infoLogLength - 1, NULL,
|
||||||
clog_log(CLOG_LEVEL_ERROR, "%s", *fragmentShaderErrorMessage);
|
fragmentShaderErrorMessage);
|
||||||
|
clog_log(CLOG_LEVEL_ERROR, "%s", fragmentShaderErrorMessage);
|
||||||
|
free(fragmentShaderErrorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
clog_log(CLOG_LEVEL_DEBUG, "Linking shader program");
|
clog_log(CLOG_LEVEL_DEBUG, "Linking shader program");
|
||||||
@ -86,9 +91,11 @@ GLuint loadShaders(const char *vertex_file_path,
|
|||||||
glGetProgramiv(programID, GL_COMPILE_STATUS, &result);
|
glGetProgramiv(programID, GL_COMPILE_STATUS, &result);
|
||||||
glGetProgramiv(programID, GL_INFO_LOG_LENGTH, &infoLogLength);
|
glGetProgramiv(programID, GL_INFO_LOG_LENGTH, &infoLogLength);
|
||||||
if (infoLogLength > 0) {
|
if (infoLogLength > 0) {
|
||||||
char *programErrorMessage[infoLogLength + 1];
|
infoLogLength += 1; // Prevents a sub-expression overflow false positive
|
||||||
glGetProgramInfoLog(programID, infoLogLength, NULL, *programErrorMessage);
|
char *programErrorMessage = (char*)malloc(infoLogLength * sizeof(char));;
|
||||||
clog_log(CLOG_LEVEL_ERROR, "%s", *programErrorMessage);
|
glGetProgramInfoLog(programID, infoLogLength - 1, NULL, programErrorMessage);
|
||||||
|
clog_log(CLOG_LEVEL_ERROR, "%s", programErrorMessage);
|
||||||
|
free(programErrorMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
glDetachShader(programID, vertexShaderID);
|
glDetachShader(programID, vertexShaderID);
|
||||||
|
8
shader.h
8
shader.h
@ -3,9 +3,13 @@
|
|||||||
|
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
GLuint loadShaders(const char* vertex_file_path,
|
GLuint loadShaders(const char* vertex_file_path,
|
||||||
const char* fragment_file_path);
|
const char* fragment_file_path);
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user