Can build the project. Now trying to isolate opengl problem

This commit is contained in:
2025-09-11 08:23:02 -05:00
parent 2d38f74371
commit 2821847ce2
17 changed files with 197 additions and 27 deletions

View File

@@ -42,7 +42,8 @@ glm::mat4 world_to_camera(Camera& c) {
glm::mat4 rotation_theta = glm::rotate(glm::mat4(1), c.theta, {0, 1, 0});
glm::mat4 rotation_phi = glm::rotate(glm::mat4(1), c.phi, {1, 0, 0});
glm::mat4 rotated_focus_to_camera = glm::translate(glm::mat4(1), { 0, 0, -c.distance });
return rotated_focus_to_camera * rotation_phi * rotation_theta * world_to_focus;
glm::mat4 res = rotated_focus_to_camera * rotation_phi * rotation_theta * world_to_focus;
return res;
}
glm::mat4 camera_to_world(Camera& c) { return glm::inverse(world_to_camera(c)); }

View File

@@ -1,28 +1,29 @@
#include <cassert>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <winnt.h>
#include <cstring>
#include <glm/ext/vector_float2.hpp>
#include <glm/ext/vector_float4.hpp>
#include <profileapi.h>
#include <synchapi.h>
#include <map>
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <glm/ext/matrix_clip_space.hpp>
#include <glm/ext/matrix_transform.hpp>
#include <glm/ext/vector_float3.hpp>
#include <glm/matrix.hpp>
#include <stdio.h>
#include <stdlib.h>
#include <winnt.h>
#include "glm/gtc/type_ptr.hpp"
#include "sync.hpp"
#include "util.hpp"
#include "shaders.hpp"
#include "body.hpp"
#include "camera.hpp"
#include "live_plotter.hpp"
#include "gldebug.hpp"
using namespace sync;
@@ -69,6 +70,7 @@ bool _glfw_setup();
void _refresh_win();
double _time();
extern DllExport bool __cdecl start(int win_w, int win_h) {
if (running) {
printf("Already running! Call stop before calling stop again\n");
@@ -112,7 +114,8 @@ extern DllExport bool __cdecl stop() {
extern DllExport pointid __cdecl create_point(float x, float y, float z) {
lock(m);
// This is stupid. Please fix
// TODO: This system is really stupid. Please fix
// Also what happens if there isn't a replaceable point?
int slot = -1;
int start_loc = point_buf_i;
do {
@@ -125,7 +128,7 @@ extern DllExport pointid __cdecl create_point(float x, float y, float z) {
assert(slot > -1);
point_buf[slot] = {
point_buf[slot] = {
.initialized = false,
.replaceable = false,
.startloc = glm::vec3(x, y, z),
@@ -206,8 +209,8 @@ void _scroll_cb(GLFWwindow* win, double xoffset, double yoffset) { zoom_camera(c
DWORD _win_thread(LPVOID args) {
glm::vec2* winsize = (glm::vec2*)args;
camera = make_camera({ 0, 0, 0 }, 10);
camera.theta = glm::radians(90.0f);
camera.phi = glm::radians(30.0f);
camera.theta = glm::radians(0.0f);
camera.phi = glm::radians(0.0f);
viewport = make_viewport(winsize->x, winsize->y, 45.0f);
if (!_glfw_setup()) {
printf("Failed to initialize glfw window\n");
@@ -219,6 +222,17 @@ DWORD _win_thread(LPVOID args) {
return -1;
}
printf("Open GL Vendor: %s\n", glGetString(GL_VENDOR));
printf("Open GL Renderer: %s\n", glGetString(GL_RENDERER));
printf("Open GL Version: %s\n", glGetString(GL_VERSION));
printf("Open GL Shader Language Version: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
// Enable debug messages
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageCallback(gl_debug_cb, 0);
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, GL_TRUE);
if (!load_shader(&shader, vertex_filepath, fragment_filepath)) {
printf("Failed to compile shaders\n");
return -1;
@@ -243,9 +257,11 @@ DWORD _win_thread(LPVOID args) {
bool _glfw_setup() {
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
win = glfwCreateWindow(viewport.width, viewport.height, "LivePlotter", NULL, NULL);
if (win == NULL) {
printf("Failed to create GLFW window\n");
@@ -258,6 +274,7 @@ bool _glfw_setup() {
glfwSetMouseButtonCallback(win, _mouse_button_cb);
glfwSetScrollCallback(win, _scroll_cb);
_cursor_pos_cb(win, 0, 0);
return true;
}
@@ -267,6 +284,11 @@ void _refresh_win() {
set_uniform(shader, "camera_t", world_to_camera(camera));
set_uniform(shader, "projection_t", camera_to_projection(viewport));
/*glm::mat4 cam = world_to_camera(camera);
glm::mat4 view = camera_to_projection(viewport);
glUniformMatrix4fv(glGetUniformLocation(shader, "camera_t"), 1, GL_FALSE, glm::value_ptr(cam));
glUniformMatrix4fv(glGetUniformLocation(shader, "projection_t"), 1, GL_FALSE, glm::value_ptr(view));*/
if (trylock(m)) {
for (int i = 0; i < point_buf_len; i++) {
Point &p = point_buf[i];

View File

@@ -85,6 +85,7 @@ bool _compile_shader(uint *out_id, const char* filepath, int shader_type) {
glGetShaderInfoLog(id, MAX_ERR_MSG_LEN, NULL, err_msg);
printf("Error compiling shader %s\n", filepath);
printf("Error msg: %s\n", err_msg);
return false;
}
*out_id = id;
return status == GL_TRUE;

View File

@@ -12,6 +12,7 @@ bool read_file(string* s, const char* filepath) {
return false;
}
*s = { istreambuf_iterator<char>(file), istreambuf_iterator<char>() };
return true;
}
vector<string> split_str(string s, char delim) {
@@ -40,4 +41,4 @@ glm::mat4 quat_to_mat4(glm::quat q) {
return glm::mat4(col0, col1, col2, col3);
}
float randf() { return (float)rand() / (float)RAND_MAX; }
float randf() { return (float)rand() / (float)RAND_MAX; }