mirror of
https://github.com/MichaelFisher1997/opengl-cpp.git
synced 2025-04-27 22:23:10 +00:00
cleaned up a bit and got rid of some errors, still seg fualt
This commit is contained in:
parent
3e799fd434
commit
fd13d0ba63
@ -6,13 +6,15 @@ IndexBuffer::IndexBuffer(const unsigned int* data, unsigned int count)
|
|||||||
{
|
{
|
||||||
ASSERT(sizeof(unsigned int) == sizeof(GLuint));
|
ASSERT(sizeof(unsigned int) == sizeof(GLuint));
|
||||||
//
|
//
|
||||||
|
std::cout << "m_RendererID: " << &m_RendererID << " " << m_RendererID << std::endl;
|
||||||
GLCall(glGenBuffers(1, &m_RendererID));
|
GLCall(glGenBuffers(1, &m_RendererID));
|
||||||
GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_RendererID)); //select buffer called 'buffer'
|
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()
|
IndexBuffer::~IndexBuffer()
|
||||||
{
|
{
|
||||||
|
std::cout << "m_RendererID: " << &m_RendererID << " " << m_RendererID << std::endl;
|
||||||
GLCall(glDeleteBuffers(1, &m_RendererID));
|
GLCall(glDeleteBuffers(1, &m_RendererID));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void GLClearError() {
|
void GLClearError() {
|
||||||
while (glGetError() != GL_NO_ERROR);
|
//while (glGetError() != GL_NO_ERROR);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
src/sdl.cpp
13
src/sdl.cpp
@ -63,7 +63,7 @@ SdlWindow::SdlWindow(const char* title, int width, int height)
|
|||||||
r(0.5f),
|
r(0.5f),
|
||||||
location(),
|
location(),
|
||||||
increment(0.05f),
|
increment(0.05f),
|
||||||
ib(nullptr,6)
|
m_ib(nullptr, 0)
|
||||||
{
|
{
|
||||||
// 1. Set attributes
|
// 1. Set attributes
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
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
|
2, 3, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
//unsigned int vao; //vertext array object
|
|
||||||
//GLCall(glGenVertexArrays(1, &vao));
|
|
||||||
//GLCall(glBindVertexArray(vao));
|
|
||||||
|
|
||||||
VertexArray va;
|
VertexArray va;
|
||||||
VertexBuffer vb(positions, 4 * 2 * sizeof(float));
|
VertexBuffer vb(positions, 4 * 2 * sizeof(float));
|
||||||
ib = IndexBuffer(indices, 6);
|
IndexBuffer ib(indices, 6);
|
||||||
|
m_ib = ib;
|
||||||
|
|
||||||
VertexBufferLayout layout;
|
VertexBufferLayout layout;
|
||||||
layout.Push<float>(2);
|
layout.Push<float>(2);
|
||||||
@ -255,7 +252,7 @@ void SdlWindow::render() {
|
|||||||
GLCall(glUniform4f(location, r, 0.3f, 0.8f, 1.0f));
|
GLCall(glUniform4f(location, r, 0.3f, 0.8f, 1.0f));
|
||||||
|
|
||||||
va.Bind();
|
va.Bind();
|
||||||
ib.Bind();
|
m_ib.Bind();
|
||||||
// TODO: Draw with OpenGL here (shaders, triangles, etc.)
|
// TODO: Draw with OpenGL here (shaders, triangles, etc.)
|
||||||
//glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr);
|
//glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr);
|
||||||
GLCall(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr)); //macro assert for debugging
|
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() {
|
void SdlWindow::GLClearError() {
|
||||||
while (glGetError() != GL_NO_ERROR);
|
//while (glGetError() != GL_NO_ERROR);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,11 +62,11 @@ private:
|
|||||||
unsigned int buffer;
|
unsigned int buffer;
|
||||||
unsigned int ibo;
|
unsigned int ibo;
|
||||||
unsigned int vao;
|
unsigned int vao;
|
||||||
IndexBuffer ib; // pointer, no default constructor needed
|
|
||||||
unsigned int shader;
|
unsigned int shader;
|
||||||
unsigned int location;
|
unsigned int location;
|
||||||
VertexBufferLayout layout;
|
VertexBufferLayout layout;
|
||||||
VertexArray va;
|
VertexArray va;
|
||||||
|
IndexBuffer m_ib;
|
||||||
|
|
||||||
// Private methods
|
// Private methods
|
||||||
void processEvents();
|
void processEvents();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user