Started work on the Renderer and added directory-creating functionality to writeFile

This commit is contained in:
grayson committed 2021-08-20 14:06:03 -05:00
1 parent 11dc2deb2f
commit f6ffb9f87e
14 files changed
+253 -61

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
#include "IndexBuffer.h"
namespace nf {
IndexBuffer::IndexBuffer(const void* data, size_t count) {
m_count = count;
glGenBuffers(1, &m_id);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_id);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(unsigned int), data, GL_STATIC_DRAW);//TODO: See if I need to change this to dynamic
}
void IndexBuffer::bind() const {
glBindBuffer(GL_ARRAY_BUFFER, m_id);
}
unsigned int IndexBuffer::getCount() {
return m_count;
}
IndexBuffer::~IndexBuffer() {
glDeleteBuffers(1, &m_id);
}
}
+71
View File
@@ -0,0 +1,71 @@
#include "Renderer.h"
#include "Application.h"
namespace nf {
Renderer::Renderer(Application* app) {
m_app = app;
m_hdc = GetDC(m_app->getWindow());
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, //Flags
PFD_TYPE_RGBA, // The kind of framebuffer. RGBA or palette.
32, // Colordepth of the framebuffer.
0, 0, 0, 0, 0, 0,
0,
0,
0,
0, 0, 0, 0,
24, // Number of bits for the depthbuffer
8, // Number of bits for the stencilbuffer
0, // Number of Aux buffers in the framebuffer.
PFD_MAIN_PLANE,
0,
0, 0, 0
};
int pf = ChoosePixelFormat(m_hdc, &pfd);
SetPixelFormat(m_hdc, pf, &pfd);
m_hglrc = wglCreateContext(m_hdc);
wglMakeCurrent(m_hdc, m_hglrc);
glewExperimental = GL_TRUE;
if (glewInit() != GLEW_OK) {
Error("Could not initialize GLEW");
}
const int attrib[] = {
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 3,
WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
0, 0
};
wglDeleteContext(m_hglrc);
m_hglrc = wglCreateContextAttribsARB(m_hdc, NULL, attrib);
wglMakeCurrent(m_hdc, m_hglrc);
wglSwapIntervalEXT(0);
Log("OpenGL version: " + std::string((char*)glGetString(GL_VERSION)));
GLuint vao;
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
void Renderer::doFrame() {
glViewport(0, 0, m_app->getConfig().width, m_app->getConfig().height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
SwapBuffers(m_hdc);
#ifdef _DEBUG
GLenum err = glGetError();
if (err != GL_NO_ERROR) {
Error(("OpenGL error " + std::to_string(err)).c_str());
}
#endif
}
Renderer::~Renderer() {
ReleaseDC(m_app->getWindow(), m_hdc);
wglMakeCurrent(NULL, NULL);
wglDeleteContext(m_hglrc);
}
}
+12
View File
@@ -0,0 +1,12 @@
#include "VertexArray.h"
namespace nf{
VertexArray::VertexArray(VertexBuffer& buffer) {
glGenVertexArrays(1, &m_id);
//TODO: Bind buffer and set the layout
}
VertexArray::~VertexArray() {
glDeleteVertexArrays(1, &m_id);
}
}
+17
View File
@@ -0,0 +1,17 @@
#include "VertexBuffer.h"
namespace nf {
VertexBuffer::VertexBuffer(const void* data, size_t size) {
glGenBuffers(1, &m_id);
glBindBuffer(GL_ARRAY_BUFFER, m_id);
glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW);//TODO: See if I need to change this to dynamic
}
void VertexBuffer::bind() const {
glBindBuffer(GL_ARRAY_BUFFER, m_id);
}
VertexBuffer::~VertexBuffer() {
glDeleteBuffers(1, &m_id);
}
}