Basic Renderer
This commit is contained in:
Binary file not shown.
Binary file not shown.
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
|
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.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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;
|
||||||
|
|||||||
@@ -15,3 +15,15 @@ bool GLLogCall(const char* function, const char* file, int line) {
|
|||||||
}
|
}
|
||||||
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));
|
||||||
|
}
|
||||||
@@ -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();\
|
||||||
@@ -12,3 +16,9 @@
|
|||||||
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;
|
||||||
|
};
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
#include "VertexArray.h"
|
#include "VertexArray.h"
|
||||||
|
#include "VertexBufferLayout.h"
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
|
|
||||||
VertexArray::VertexArray()
|
VertexArray::VertexArray()
|
||||||
|
|||||||
@@ -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:
|
||||||
|
|||||||
Reference in New Issue
Block a user