From 3a2d18f7310c4429dd2072707611a587722a82bb Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Wed, 25 Oct 2023 18:26:11 -0500 Subject: [PATCH] Create basic vertex and fragment shader. Error handling. --- OpenGLTemplate/OpenGLTemplate.vcxproj | 3 + OpenGLTemplate/OpenGLTemplate.vcxproj.filters | 5 + OpenGLTemplate/ShaderError.h | 39 +++++++ OpenGLTemplate/main.cpp | 100 +++++++++++++++++- 4 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 OpenGLTemplate/ShaderError.h diff --git a/OpenGLTemplate/OpenGLTemplate.vcxproj b/OpenGLTemplate/OpenGLTemplate.vcxproj index dae2e99..f06f70c 100644 --- a/OpenGLTemplate/OpenGLTemplate.vcxproj +++ b/OpenGLTemplate/OpenGLTemplate.vcxproj @@ -141,6 +141,9 @@ + + + diff --git a/OpenGLTemplate/OpenGLTemplate.vcxproj.filters b/OpenGLTemplate/OpenGLTemplate.vcxproj.filters index ce0c35c..62b6244 100644 --- a/OpenGLTemplate/OpenGLTemplate.vcxproj.filters +++ b/OpenGLTemplate/OpenGLTemplate.vcxproj.filters @@ -19,4 +19,9 @@ Source Files + + + Header Files + + \ No newline at end of file diff --git a/OpenGLTemplate/ShaderError.h b/OpenGLTemplate/ShaderError.h new file mode 100644 index 0000000..8ae7d47 --- /dev/null +++ b/OpenGLTemplate/ShaderError.h @@ -0,0 +1,39 @@ +#pragma once +#include +#include +#include + +namespace ErrorCheck{ + inline void printShaderLog(GLuint shader) { + int len = 0; + int chWrittn = 0; + char *log; + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &len); + if (len > 0) { + log = (char *)malloc(len); + glGetShaderInfoLog(shader, len, &chWrittn, log); + std::cout << "Shader Info Log: " << log << std::endl; + free(log); + } } + inline void printProgramLog(int prog) { + int len = 0; + int chWrittn = 0; + char *log; + glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &len); + if (len > 0) { + log = (char *)malloc(len); + glGetProgramInfoLog(prog, len, &chWrittn, log); + std::cout << "Program Info Log: " << log << std::endl; + free(log); + } } + inline bool checkOpenGLError() { + bool foundError = false; + int glErr = glGetError(); + while (glErr != GL_NO_ERROR) { + std::cout << "glError: " << glErr << std::endl; + foundError = true; + glErr = glGetError(); + } + return foundError; + } +} \ No newline at end of file diff --git a/OpenGLTemplate/main.cpp b/OpenGLTemplate/main.cpp index eac2b6e..3db875b 100644 --- a/OpenGLTemplate/main.cpp +++ b/OpenGLTemplate/main.cpp @@ -1,5 +1,101 @@ +#include +#include #include +#include "ShaderError.h" -int main(){ - std::cout<<"It works!"<