cleaned up a bit and got rid of some errors, still seg fualt

This commit is contained in:
MichaelFisher1997 2025-01-11 20:56:58 +00:00
parent 3e799fd434
commit fd13d0ba63
5 changed files with 12 additions and 12 deletions

View File

@ -6,13 +6,15 @@ IndexBuffer::IndexBuffer(const unsigned int* data, unsigned int count)
{
ASSERT(sizeof(unsigned int) == sizeof(GLuint));
//
std::cout << "m_RendererID: " << &m_RendererID << " " << m_RendererID << std::endl;
GLCall(glGenBuffers(1, &m_RendererID));
GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_RendererID)); //select buffer called 'buffer'
GLCall(glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(GLuint), data, GL_STATIC_DRAW)); // assigne buffer size, static as we use many times, but does not change
GLCall(glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(unsigned int), data, GL_STATIC_DRAW)); // assigne buffer size, static as we use many times, but does not change
}
IndexBuffer::~IndexBuffer()
{
std::cout << "m_RendererID: " << &m_RendererID << " " << m_RendererID << std::endl;
GLCall(glDeleteBuffers(1, &m_RendererID));
}

View File

@ -1,9 +1,10 @@
#include "Renderer.h"
#include <iostream>
void GLClearError() {
while (glGetError() != GL_NO_ERROR);
//while (glGetError() != GL_NO_ERROR);
}

View File

@ -34,4 +34,4 @@
#define INT2VOIDP(i) (void*)(uintptr_t)(i)
void GLClearError();
bool GLLogCall();
bool GLLogCall();

View File

@ -63,7 +63,7 @@ SdlWindow::SdlWindow(const char* title, int width, int height)
r(0.5f),
location(),
increment(0.05f),
ib(nullptr,6)
m_ib(nullptr, 0)
{
// 1. Set attributes
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
@ -120,13 +120,10 @@ SdlWindow::SdlWindow(const char* title, int width, int height)
2, 3, 0
};
//unsigned int vao; //vertext array object
//GLCall(glGenVertexArrays(1, &vao));
//GLCall(glBindVertexArray(vao));
VertexArray va;
VertexBuffer vb(positions, 4 * 2 * sizeof(float));
ib = IndexBuffer(indices, 6);
IndexBuffer ib(indices, 6);
m_ib = ib;
VertexBufferLayout layout;
layout.Push<float>(2);
@ -255,7 +252,7 @@ void SdlWindow::render() {
GLCall(glUniform4f(location, r, 0.3f, 0.8f, 1.0f));
va.Bind();
ib.Bind();
m_ib.Bind();
// TODO: Draw with OpenGL here (shaders, triangles, etc.)
//glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr);
GLCall(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr)); //macro assert for debugging
@ -363,7 +360,7 @@ SdlWindow::ShaderProgramSource SdlWindow::parseShader(const std::string& filepat
}
void SdlWindow::GLClearError() {
while (glGetError() != GL_NO_ERROR);
//while (glGetError() != GL_NO_ERROR);
}

View File

@ -62,11 +62,11 @@ private:
unsigned int buffer;
unsigned int ibo;
unsigned int vao;
IndexBuffer ib; // pointer, no default constructor needed
unsigned int shader;
unsigned int location;
VertexBufferLayout layout;
VertexArray va;
IndexBuffer m_ib;
// Private methods
void processEvents();