Compare commits

...

8 Commits

Author SHA1 Message Date
Archie Hilton d3506737f0 Wrap glfwTerminate() in DEBUG symbol
This prevents asan from spitting out a lot of unhelpful warnings.
2024-05-14 22:01:38 +01:00
Archie Hilton ec0155bc77 Enable openGL debug output 2024-05-14 21:49:11 +01:00
Archie Hilton fb4a412db5 Delete VBO on mesh deletion 2024-05-14 21:48:58 +01:00
Archie Hilton 2e5c5fdf8c Delete shaders after program compilation 2024-05-14 21:48:49 +01:00
Archie Hilton f5883d0219 Close shader file handles once done 2024-05-14 21:48:33 +01:00
Archie Hilton aa8c0f8594 Switch to GLFW 3.4 2024-05-14 21:48:20 +01:00
Archie Hilton 78c38fcc2d Enable asan and ubsan 2024-05-14 21:48:06 +01:00
Archie Hilton 50461ad4c8 Clean up quads after finishing 2024-05-14 21:15:17 +01:00
6 changed files with 20 additions and 8 deletions

View File

@ -3,7 +3,8 @@ cmake_minimum_required(VERSION 3.21)
project(Exponent CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=undefined")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=undefined -g")
set(CMAKE_BUILD_TYPE Debug)
add_subdirectory(glfw)
add_subdirectory(src)

2
glfw

@ -1 +1 @@
Subproject commit 228e58262e18f2ee61799bd86d0be718b1e31f9f
Subproject commit 7b6aead9fb88b3623e3b3725ebb42670cbe4c579

View File

@ -9,6 +9,7 @@ add_executable(Exponent
target_link_libraries(Exponent PUBLIC glfw glm::glm)
target_include_directories(Exponent PUBLIC ${CMAKE_SOURCE_DIR}/include)
target_compile_definitions(Exponent PUBLIC "$<$<CONFIG:DEBUG>:DEBUG>")
target_compile_definitions(Exponent PRIVATE GLFW_INCLUDE_NONE)
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/shaders/shader.frag" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}/shaders/")

View File

@ -24,6 +24,8 @@ static GLuint compile_shader(GLenum shader_type, const std::string &path) {
std::string shader_source_str = shader_source_stream.str();
const GLchar *shader_source = shader_source_str.c_str();
shader_file_handle.close();
GLuint shader_id = glCreateShader(shader_type);
if (shader_id == 0) {
@ -77,5 +79,9 @@ GLuint compile_and_link_program(const std::vector<std::pair<GLuint, std::string>
throw GLProgramException(std::format("Program {} link failed:\n{}", program_id, error_log));
}
for (auto &s:shader_ids) {
glDeleteShader(s);
}
return program_id;
}

View File

@ -19,4 +19,5 @@ Mesh::Mesh(std::span<glm::vec2> verts) {
Mesh::~Mesh() {
glDeleteVertexArrays(1, &vao);
glDeleteBuffers(1, &vbo);
}

View File

@ -90,8 +90,6 @@ static GLuint vertex_buf[2];
static GLuint array_buf[2];
static const GLuint vertex_data_position = 0;
static Quad *o1;
static std::vector<Quad *> quads = {};
static std::array<glm::vec2, 6> verts({
@ -121,8 +119,8 @@ static void init_opengl() {
dbg_log("Initialising opengl");
// During init, enable debug output
glEnable ( GL_DEBUG_OUTPUT );
glDebugMessageCallback( MessageCallback, 0 );
glEnable(GL_DEBUG_OUTPUT);
glDebugMessageCallback(MessageCallback, 0);
// Configure the context's capabilities
glClearColor(0.0, 0.0, 0.0, 1.0);
@ -172,8 +170,13 @@ int main() {
glfwPollEvents();
}
delete(o1);
for(auto q: quads) {
delete(q);
}
glfwDestroyWindow(w);
#ifndef DEBUG
glfwTerminate();
#endif
exit(EXIT_SUCCESS);
}