Managed to get compiling under ubuntu

This commit is contained in:
Dominic
2021-08-14 13:38:57 -07:00
parent 2d977e041c
commit 5cf7da5ee0
7 changed files with 39 additions and 22 deletions

View File

@ -22,6 +22,8 @@ set(SETTING_PLATFORM_GLFW 1)
set(SETTING_PLATFORM_SDL 2) set(SETTING_PLATFORM_SDL 2)
set(SETTING_PLATFORM SETTING_PLATFORM_SDL) set(SETTING_PLATFORM SETTING_PLATFORM_SDL)
set(SETTING_USE_GLAD 0)
# Game Settings # Game Settings
set(SETTING_GAME_POKER 1) set(SETTING_GAME_POKER 1)
set(SETTING_GAME_DAWN 2) set(SETTING_GAME_DAWN 2)
@ -66,11 +68,18 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_executable(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES}) add_executable(${PROJECT_NAME} ${HEADER_FILES} ${SOURCE_FILES})
################################# STATIC LIBS ################################## ################################# STATIC LIBS ##################################
# GLFW and GLAD
if(${SETTING_PLATFORM} EQUAL ${SETTING_PLATFORM_GLFW}) # Math
target_link_libraries(${PROJECT_NAME} m)
# GLAD
if(${SETTING_USE_GLAD} EQUAL 1)
add_subdirectory(${CMAKE_SOURCE_DIR}/lib/glad) add_subdirectory(${CMAKE_SOURCE_DIR}/lib/glad)
target_link_libraries(${PROJECT_NAME} glad) target_link_libraries(${PROJECT_NAME} glad)
endif()
# GLFW and GLAD
if(${SETTING_PLATFORM} EQUAL ${SETTING_PLATFORM_GLFW})
if(NOT glfw3_FOUND) if(NOT glfw3_FOUND)
FetchContent_Declare( FetchContent_Declare(
glfw glfw
@ -84,8 +93,8 @@ endif()
# SDL # SDL
if(${SETTING_PLATFORM} EQUAL ${SETTING_PLATFORM_SDL}) if(${SETTING_PLATFORM} EQUAL ${SETTING_PLATFORM_SDL})
add_subdirectory(${CMAKE_SOURCE_DIR}/lib/glad) # add_subdirectory(${CMAKE_SOURCE_DIR}/lib/glad)
target_link_libraries(${PROJECT_NAME} glad) # target_link_libraries(${PROJECT_NAME} glad)
find_package(SDL2 REQUIRED) find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS}) include_directories(${SDL2_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES}) target_link_libraries(${PROJECT_NAME} ${SDL2_LIBRARIES})

View File

@ -10,6 +10,8 @@
#cmakedefine SETTING_PLATFORM_SDL @SETTING_PLATFORM_SDL@ #cmakedefine SETTING_PLATFORM_SDL @SETTING_PLATFORM_SDL@
#cmakedefine SETTING_PLATFORM @SETTING_PLATFORM@ #cmakedefine SETTING_PLATFORM @SETTING_PLATFORM@
#cmakedefine SETTING_USE_GLAD @SETTING_USE_GLAD@
// Game Settings // Game Settings
#cmakedefine SETTING_GAME_POKER @SETTING_GAME_POKER@ #cmakedefine SETTING_GAME_POKER @SETTING_GAME_POKER@
#cmakedefine SETTING_GAME_DAWN @SETTING_GAME_DAWN@ #cmakedefine SETTING_GAME_DAWN @SETTING_GAME_DAWN@

View File

@ -11,10 +11,12 @@
// Static Libs // Static Libs
#include <cglm/cglm.h> #include <cglm/cglm.h>
#if SETTING_USE_GLAD == 1
#include <glad/glad.h>
#endif
#if SETTING_PLATFORM == SETTING_PLATFORM_GLFW #if SETTING_PLATFORM == SETTING_PLATFORM_GLFW
#include <glad/glad.h>
#elif SETTING_PLATFORM == SETTING_PLATFORM_SDL #elif SETTING_PLATFORM == SETTING_PLATFORM_SDL
#include <glad/glad.h>
#include <SDL.h> #include <SDL.h>
#include <SDL_opengl.h> #include <SDL_opengl.h>
#include <SDL_opengles2.h> #include <SDL_opengles2.h>
@ -29,6 +31,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <malloc.h> #include <malloc.h>
#include <string.h> #include <string.h>
#include <math.h>
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
// Windows Fixes // Windows Fixes

View File

@ -6,7 +6,9 @@
#pragma once #pragma once
// I load GLAD and GLFW Here because they need to be included in specific orders // I load GLAD and GLFW Here because they need to be included in specific orders
#include <glad/glad.h> #if SETTING_USE_GLAD == 1
#include <glad/glad.h>
#endif
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <dawn/dawn.h> #include <dawn/dawn.h>
#include "../../src/display/render.h" #include "../../src/display/render.h"

View File

@ -9,7 +9,7 @@
game_t *GAME_STATE; game_t *GAME_STATE;
int main(int argc, char *argv[]) { int32_t main(int32_t argc, char *argv[]) {
game_t *game; game_t *game;
input_t *input; input_t *input;
SDL_GLContext context; SDL_GLContext context;
@ -57,11 +57,13 @@ int main(int argc, char *argv[]) {
return 1; return 1;
} }
// Load glad #if SETTING_USE_GLAD == 1
if (!gladLoadGLLoader((GLADloadproc) SDL_GL_GetProcAddress)) { // Load glad
printf("Failed to initialize the OpenGL context.\n"); if (!gladLoadGLLoader((GLADloadproc) SDL_GL_GetProcAddress)) {
return 1; printf("Failed to initialize the OpenGL context.\n");
} return 1;
}
#endif
// Bind the GL Context // Bind the GL Context
SDL_GL_MakeCurrent(displayWindow, context); SDL_GL_MakeCurrent(displayWindow, context);

View File

@ -7,10 +7,6 @@
#pragma once #pragma once
#include <dawn/dawn.h> #include <dawn/dawn.h>
#include <glad/glad.h>
#include <SDL.h>
#include <SDL_opengl.h>
#include <SDL_opengles2.h>
#include "../../src/display/render.h" #include "../../src/display/render.h"
#include "../../src/game/game.h" #include "../../src/game/game.h"
#include "../../src/input/input.h" #include "../../src/input/input.h"
@ -21,4 +17,4 @@
#define OPENGL_MAJOR_VERSION 2 #define OPENGL_MAJOR_VERSION 2
#define OPENGL_MINOR_VERSION 1 #define OPENGL_MINOR_VERSION 1
int main(int argc, char *argv[]); int32_t main(int32_t argc, char *argv[]);

View File

@ -13,10 +13,13 @@ void shaderInit(shader_t *shader,
int isSuccess, maxLength; int isSuccess, maxLength;
char *error; char *error;
GLuint shaderVertex, shaderFragment, shaderProgram; GLuint shaderVertex, shaderFragment, shaderProgram;
GLchar const* filesVertex[] = { vertexShaderSource };
GLchar const* filesFragment[] = { fragmentShaderSource };
// Load the vertex shader first // Load the vertex shader first
shaderVertex = glCreateShader(GL_VERTEX_SHADER); shaderVertex = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(shaderVertex, 1, &vertexShaderSource, 0); glShaderSource(shaderVertex, 1, filesVertex, 0);
glCompileShader(shaderVertex); glCompileShader(shaderVertex);
// Validate // Validate
@ -32,7 +35,7 @@ void shaderInit(shader_t *shader,
// Now load the Frag shader // Now load the Frag shader
shaderFragment = glCreateShader(GL_FRAGMENT_SHADER); shaderFragment = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(shaderFragment, 1, &fragmentShaderSource, 0); glShaderSource(shaderFragment, 1, filesFragment, 0);
glCompileShader(shaderFragment); glCompileShader(shaderFragment);
glGetShaderiv(shaderFragment, GL_COMPILE_STATUS, &isSuccess); glGetShaderiv(shaderFragment, GL_COMPILE_STATUS, &isSuccess);
if(!isSuccess) { if(!isSuccess) {