Update trying for a Windows baby

This commit is contained in:
illegitimate-egg 2024-10-06 09:02:32 +01:00
parent 9f36c38570
commit e184b1c910
5 changed files with 44 additions and 20 deletions

3
.gitmodules vendored
View File

@ -19,3 +19,6 @@
[submodule "include/imgui"]
path = include/imgui
url = https://github.com/ocornut/imgui
[submodule "include/CLog"]
path = include/CLog
url = https://github.com/williamistGitHub/CLog.git

View File

@ -19,17 +19,27 @@ if(CMAKE_BIANRY_DIR MATCHES " ")
message("Spaces in the build dir can cause errors, thou art been warned")
endif()
add_custom_command(
OUTPUT ${PROJECT_SOURCE_DIR}/include/glew/src/glew.c
${PROJECT_SOURCE_DIR}/include/glewinfo.c
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/include/glew/auto
COMMAND ${CMAKE_MAKE_PROGRAM})
if(LINUX)
add_custom_command(
OUTPUT ${PROJECT_SOURCE_DIR}/include/glew/src/glew.c
${PROJECT_SOURCE_DIR}/include/glewinfo.c
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/include/glew/auto
COMMAND ${CMAKE_MAKE_PROGRAM})
endif()
if(WIN32)
add_custom_command(
OUTPUT ${PROJECT_SOURCE_DIR}/include (glew) /src/glew.c
${PROJECT_SOURCE_DIR}/include/glewinfo.c
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/include/glew/build/vc15
COMMAND ${CMAKE_VS_MSBUILD_COMMAND})
endif()
add_subdirectory(include/glm)
add_subdirectory(include/glew/build/cmake)
add_subdirectory(include/glfw)
add_subdirectory(include/SOIL2)
add_subdirectory(include/assimp)
add_subdirectory(include/CLog)
include_directories(include/imgui)
add_library(
@ -52,4 +62,5 @@ target_link_libraries(
glfw
soil2
assimp
imgui)
imgui
clog)

View File

@ -9,6 +9,7 @@
#include <glm/gtc/matrix_transform.hpp>
#include <glm/trigonometric.hpp>
#include <clog/clog.h>
#include <backends/imgui_impl_glfw.h>
#include <backends/imgui_impl_opengl3.h>
#include <imgui.h>
@ -28,7 +29,7 @@ extern "C" {
#define HEIGHT 768
static void glfwErrorCallback(int e, const char *description) {
fprintf(stderr, "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,
@ -40,7 +41,7 @@ bool loadModel(const char *path, std::vector<unsigned short> &indices,
path, aiProcess_Triangulate | aiProcess_JoinIdenticalVertices |
aiProcess_SortByPType);
if (!scene) {
fprintf(stderr, "%s\n", importer.GetErrorString());
clog_log(CLOG_LEVEL_ERROR, "%s", importer.GetErrorString());
return false;
}
const aiMesh *mesh = scene->mMeshes[0];
@ -72,7 +73,7 @@ int initWindow() {
glewExperimental = true;
if (!glfwInit()) {
fprintf(stderr, "GLFW went shitty time\n");
clog_log(CLOG_LEVEL_ERROR, "GLFW went shitty time (failed to init)");
return 1;
}
@ -85,7 +86,7 @@ int initWindow() {
GLFWwindow *window;
window = glfwCreateWindow(WIDTH, HEIGHT, "Fred", NULL, NULL);
if (window == NULL) {
fprintf(stderr, "Failed to open window.\n");
clog_log(CLOG_LEVEL_ERROR, "Failed to open window.");
glfwTerminate();
return 1;
}
@ -94,7 +95,7 @@ int initWindow() {
glfwSwapInterval(1);
int code;
if ((code = glewInit()) != GLEW_OK) {
fprintf(stderr, "Failed to init GLEW: %s\n", glewGetErrorString(code));
clog_log(CLOG_LEVEL_ERROR, "Failed to init GLEW: %s", glewGetErrorString(code));
return 1;
}
@ -152,7 +153,7 @@ int initWindow() {
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT);
if (texture == 0) {
printf("Texture failed to load\n");
clog_log(CLOG_LEVEL_WARN, "Texture failed to load");
return 0;
}

1
include/CLog Submodule

@ -0,0 +1 @@
Subproject commit 5a8dc48b060619da1b6fbbacd18630c4d2c92182

View File

@ -3,7 +3,15 @@
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#ifdef __linux__
#include <unistd.h>
#endif
#ifdef _WIN32
#include <io.h>
#define lseek _lseek
#endif
#include <clog/clog.h>
GLuint loadShaders(const char *vertex_file_path,
const char *fragment_file_path) {
@ -14,7 +22,7 @@ GLuint loadShaders(const char *vertex_file_path,
vertexShaderFD = fopen(vertex_file_path, "rb");
if (vertexShaderFD == NULL) {
fclose(vertexShaderFD);
fprintf(stderr, "Failed to open Vertex Shader");
clog_log(CLOG_LEVEL_ERROR, "Failed to open Vertex Shader");
return 1;
}
int vertexShaderLength = lseek(fileno(vertexShaderFD), 0L, SEEK_END) + 1;
@ -28,7 +36,7 @@ GLuint loadShaders(const char *vertex_file_path,
fragmentShaderFD = fopen(fragment_file_path, "rb");
if (fragmentShaderFD == NULL) {
fclose(fragmentShaderFD);
fprintf(stderr, "Failed to open Fragment Shader");
clog_log(CLOG_LEVEL_ERROR, "Failed to open Fragment Shader");
return 1;
}
int fragmentShaderLength = lseek(fileno(fragmentShaderFD), 0L, SEEK_END) + 1;
@ -41,7 +49,7 @@ GLuint loadShaders(const char *vertex_file_path,
GLint result = GL_FALSE;
int infoLogLength;
printf("Compiling shader: %s\n", vertex_file_path);
clog_log(CLOG_LEVEL_DEBUG, "Compiling shader: %s", vertex_file_path);
char const *vertexShaderCodeConst = vertexShaderCode;
glShaderSource(vertexShaderID, 1, &vertexShaderCodeConst, NULL);
glCompileShader(vertexShaderID);
@ -52,10 +60,10 @@ GLuint loadShaders(const char *vertex_file_path,
char *vertexShaderErrorMessage[infoLogLength + 1];
glGetShaderInfoLog(vertexShaderID, infoLogLength, NULL,
*vertexShaderErrorMessage);
printf("%s\n", *vertexShaderErrorMessage);
clog_log(CLOG_LEVEL_ERROR, "%s", *vertexShaderErrorMessage);
}
printf("Compiling shader: %s\n", fragment_file_path);
clog_log(CLOG_LEVEL_DEBUG, "Compiling shader: %s", fragment_file_path);
char const *fragmentShaderCodeConst = fragmentShaderCode;
glShaderSource(fragmentShaderID, 1, &fragmentShaderCodeConst, NULL);
glCompileShader(fragmentShaderID);
@ -66,10 +74,10 @@ GLuint loadShaders(const char *vertex_file_path,
char *fragmentShaderErrorMessage[infoLogLength + 1];
glGetShaderInfoLog(fragmentShaderID, infoLogLength, NULL,
*fragmentShaderErrorMessage);
printf("%s\n", *fragmentShaderErrorMessage);
clog_log(CLOG_LEVEL_ERROR, "%s", *fragmentShaderErrorMessage);
}
printf("Linking program\n");
clog_log(CLOG_LEVEL_DEBUG, "Linking shader program");
GLuint programID = glCreateProgram();
glAttachShader(programID, vertexShaderID);
glAttachShader(programID, fragmentShaderID);
@ -80,7 +88,7 @@ GLuint loadShaders(const char *vertex_file_path,
if (infoLogLength > 0) {
char *programErrorMessage[infoLogLength + 1];
glGetProgramInfoLog(programID, infoLogLength, NULL, *programErrorMessage);
printf("%s\n", *programErrorMessage);
clog_log(CLOG_LEVEL_ERROR, "%s", *programErrorMessage);
}
glDetachShader(programID, vertexShaderID);