Basic Renderer
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -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
|
||||
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
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "Renderer.h"
|
||||
#include "VertexBuffer.h"
|
||||
#include "VertexBufferLayout.h"
|
||||
#include "IndexBuffer.h"
|
||||
#include "VertexArray.h"
|
||||
#include "Shader.h"
|
||||
@@ -70,6 +71,8 @@ int main(void){
|
||||
shader.Bind();
|
||||
shader.SetUniform4f("u_Color", 0.8f, 0.3f, 0.8f, 1.0f);
|
||||
|
||||
Renderer renderer;
|
||||
|
||||
//unbinding the buffers
|
||||
va.Unbind();
|
||||
vb.Unbind();
|
||||
@@ -83,15 +86,12 @@ int main(void){
|
||||
//Main loop
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
/* Render here */
|
||||
GLCall(glClear(GL_COLOR_BUFFER_BIT));
|
||||
renderer.Clear();
|
||||
|
||||
shader.Bind();
|
||||
shader.SetUniform4f("u_Color", r, 0.3f, 0.8f, 1.0f);
|
||||
|
||||
va.Bind();
|
||||
ib.Bind();
|
||||
|
||||
GLCall(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr));
|
||||
renderer.Draw(va, ib, shader);
|
||||
|
||||
if (r > 1.0f)
|
||||
increment = -0.05f;
|
||||
|
||||
@@ -14,4 +14,16 @@ bool GLLogCall(const char* function, const char* file, int line) {
|
||||
return false;
|
||||
}
|
||||
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));
|
||||
}
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
#include <GL\glew.h>
|
||||
|
||||
#include "VertexArray.h"
|
||||
#include "IndexBuffer.h"
|
||||
#include "Shader.h"
|
||||
|
||||
//Macros
|
||||
#define ASSERT(x) if(!(x)) __debugbreak();
|
||||
#define GLCall(x) GLClearError();\
|
||||
@@ -11,4 +15,10 @@
|
||||
//Clearing OpenGl error list
|
||||
void GLClearError();
|
||||
//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;
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "VertexArray.h"
|
||||
#include "VertexBufferLayout.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
VertexArray::VertexArray()
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "VertexBuffer.h"
|
||||
#include "VertexBufferLayout.h"
|
||||
|
||||
class VertexBufferLayout;
|
||||
|
||||
class VertexArray {
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user