Basic Renderer

This commit is contained in:
Tom
2021-06-12 17:41:57 +02:00
parent 890c36bfc1
commit 6a9ac4661c
16 changed files with 39 additions and 8 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,3 +1,10 @@
Main.cpp IndexBuffer.cpp
Main.cpp
C:\dev\Glfw_Practice\c++\Window_practice\Window_practice\src\VertexBufferLayout.h(5,10): warning C4067: unexpected tokens following preprocessor directive - expected a newline C:\dev\Glfw_Practice\c++\Window_practice\Window_practice\src\VertexBufferLayout.h(5,10): warning C4067: unexpected tokens following preprocessor directive - expected a newline
Renderer.cpp
Shader.cpp
VertexArray.cpp
C:\dev\Glfw_Practice\c++\Window_practice\Window_practice\src\VertexBufferLayout.h(5,10): warning C4067: unexpected tokens following preprocessor directive - expected a newline
VertexBuffer.cpp
Generating Code...
Window_practice.vcxproj -> C:\dev\Glfw_Practice\c++\Window_practice\Debug\Window_practice.exe Window_practice.vcxproj -> C:\dev\Glfw_Practice\c++\Window_practice\Debug\Window_practice.exe

Binary file not shown.

Binary file not shown.

View File

@@ -5,6 +5,7 @@
#include "Renderer.h" #include "Renderer.h"
#include "VertexBuffer.h" #include "VertexBuffer.h"
#include "VertexBufferLayout.h"
#include "IndexBuffer.h" #include "IndexBuffer.h"
#include "VertexArray.h" #include "VertexArray.h"
#include "Shader.h" #include "Shader.h"
@@ -70,6 +71,8 @@ int main(void){
shader.Bind(); shader.Bind();
shader.SetUniform4f("u_Color", 0.8f, 0.3f, 0.8f, 1.0f); shader.SetUniform4f("u_Color", 0.8f, 0.3f, 0.8f, 1.0f);
Renderer renderer;
//unbinding the buffers //unbinding the buffers
va.Unbind(); va.Unbind();
vb.Unbind(); vb.Unbind();
@@ -83,15 +86,12 @@ int main(void){
//Main loop //Main loop
while (!glfwWindowShouldClose(window)) { while (!glfwWindowShouldClose(window)) {
/* Render here */ /* Render here */
GLCall(glClear(GL_COLOR_BUFFER_BIT)); renderer.Clear();
shader.Bind(); shader.Bind();
shader.SetUniform4f("u_Color", r, 0.3f, 0.8f, 1.0f); shader.SetUniform4f("u_Color", r, 0.3f, 0.8f, 1.0f);
va.Bind(); renderer.Draw(va, ib, shader);
ib.Bind();
GLCall(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr));
if (r > 1.0f) if (r > 1.0f)
increment = -0.05f; increment = -0.05f;

View File

@@ -14,4 +14,16 @@ bool GLLogCall(const char* function, const char* file, int line) {
return false; return false;
} }
return true; return true;
}
void Renderer::Draw(const VertexArray& va, const IndexBuffer& ib, const Shader& shader) const {
shader.Bind();
va.Bind();
ib.Bind();
GLCall(glDrawElements(GL_TRIANGLES, ib.GetCount(), GL_UNSIGNED_INT, nullptr));
}
void Renderer::Clear() const{
GLCall(glClear(GL_COLOR_BUFFER_BIT));
} }

View File

@@ -2,6 +2,10 @@
#include <GL\glew.h> #include <GL\glew.h>
#include "VertexArray.h"
#include "IndexBuffer.h"
#include "Shader.h"
//Macros //Macros
#define ASSERT(x) if(!(x)) __debugbreak(); #define ASSERT(x) if(!(x)) __debugbreak();
#define GLCall(x) GLClearError();\ #define GLCall(x) GLClearError();\
@@ -11,4 +15,10 @@
//Clearing OpenGl error list //Clearing OpenGl error list
void GLClearError(); void GLClearError();
//OpenGl logging //OpenGl logging
bool GLLogCall(const char* function, const char* file, int line); bool GLLogCall(const char* function, const char* file, int line);
class Renderer {
public:
void Clear() const;
void Draw(const VertexArray& va, const IndexBuffer& ib, const Shader& shader) const;
};

View File

@@ -1,4 +1,5 @@
#include "VertexArray.h" #include "VertexArray.h"
#include "VertexBufferLayout.h"
#include "Renderer.h" #include "Renderer.h"
VertexArray::VertexArray() VertexArray::VertexArray()

View File

@@ -1,7 +1,8 @@
#pragma once #pragma once
#include "VertexBuffer.h" #include "VertexBuffer.h"
#include "VertexBufferLayout.h"
class VertexBufferLayout;
class VertexArray { class VertexArray {
private: private: