Added missing files
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,9 +1,4 @@
|
||||
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
|
||||
Rernderer.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
|
||||
Generating Code...
|
||||
Renderer.cpp
|
||||
LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
|
||||
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
|
||||
glew32s.lib(glew.obj) : warning LNK4099: PDB 'vc120.pdb' was not found with 'glew32s.lib(glew.obj)' or at 'C:\dev\Glfw_Practice\c++\Window_practice\Debug\vc120.pdb'; linking object as if no debug info
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -147,7 +147,7 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\IndexBuffer.cpp" />
|
||||
<ClCompile Include="src\Main.cpp" />
|
||||
<ClCompile Include="src\Rernderer.cpp" />
|
||||
<ClCompile Include="src\Renderer.cpp" />
|
||||
<ClCompile Include="src\VertexArray.cpp" />
|
||||
<ClCompile Include="src\VertexBuffer.cpp" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
<ClCompile Include="src\Main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\Rernderer.cpp">
|
||||
<ClCompile Include="src\Renderer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\VertexBuffer.cpp">
|
||||
|
||||
20
Window_practice/res/shaders/Basic.shader
Normal file
20
Window_practice/res/shaders/Basic.shader
Normal file
@@ -0,0 +1,20 @@
|
||||
#shader vertex
|
||||
#version 330 core
|
||||
|
||||
layout(location = 0) in vec4 position;
|
||||
|
||||
void main() {
|
||||
gl_Position = position;
|
||||
};
|
||||
|
||||
|
||||
#shader fragment
|
||||
#version 330 core
|
||||
|
||||
layout(location = 0) out vec4 color;
|
||||
|
||||
uniform vec4 u_Color;
|
||||
|
||||
void main() {
|
||||
color = u_Color;
|
||||
};
|
||||
4
Window_practice/shader to console.txt
Normal file
4
Window_practice/shader to console.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
/*std::cout << "VERTEX" << std::endl;
|
||||
std::cout << source.VertexSource << std::endl; //to write shader to console
|
||||
std::cout << "FRAGMENT" << std::endl;
|
||||
std::cout << source.FragmentSource << std::endl;*/
|
||||
27
Window_practice/src/IndexBuffer.cpp
Normal file
27
Window_practice/src/IndexBuffer.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "IndexBuffer.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
IndexBuffer::IndexBuffer(const unsigned int* data, unsigned int count)
|
||||
:m_Count(count)
|
||||
{
|
||||
GLCall(glGenBuffers(1, &m_RendererID)); //number of buffer to generate
|
||||
GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_RendererID)); //binding the buffer
|
||||
GLCall(glBufferData(GL_ELEMENT_ARRAY_BUFFER, count * sizeof(unsigned int), data, GL_STATIC_DRAW));
|
||||
}
|
||||
|
||||
IndexBuffer::~IndexBuffer()
|
||||
{
|
||||
GLCall(glDeleteBuffers(1, &m_RendererID));
|
||||
}
|
||||
|
||||
|
||||
void IndexBuffer::Bind() const
|
||||
{
|
||||
GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_RendererID));
|
||||
}
|
||||
|
||||
void IndexBuffer::Unbind() const
|
||||
{
|
||||
GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
|
||||
}
|
||||
|
||||
15
Window_practice/src/IndexBuffer.h
Normal file
15
Window_practice/src/IndexBuffer.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
class IndexBuffer {
|
||||
private:
|
||||
unsigned int m_RendererID;
|
||||
unsigned int m_Count;
|
||||
public:
|
||||
IndexBuffer(const unsigned int* data, unsigned int count);
|
||||
~IndexBuffer();
|
||||
|
||||
void Bind() const;
|
||||
void Unbind() const;
|
||||
|
||||
inline unsigned int GetCount() const { return m_Count; }
|
||||
};
|
||||
17
Window_practice/src/Renderer.cpp
Normal file
17
Window_practice/src/Renderer.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "Renderer.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
void GLClearError() {
|
||||
while (glGetError() != GL_NO_ERROR);
|
||||
}
|
||||
|
||||
//OpenGl logging
|
||||
bool GLLogCall(const char* function, const char* file, int line) {
|
||||
while (GLenum error = glGetError()) {
|
||||
std::cout << "[OpenGL Error] (" << error << "): "
|
||||
<< function << " " << file << ":" << line << std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
14
Window_practice/src/Renderer.h
Normal file
14
Window_practice/src/Renderer.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <GL\glew.h>
|
||||
|
||||
//Macros
|
||||
#define ASSERT(x) if(!(x)) __debugbreak();
|
||||
#define GLCall(x) GLClearError();\
|
||||
x;\
|
||||
ASSERT(GLLogCall(#x, __FILE__, __LINE__))
|
||||
|
||||
//Clearing OpenGl error list
|
||||
void GLClearError();
|
||||
//OpenGl logging
|
||||
bool GLLogCall(const char* function, const char* file, int line);
|
||||
38
Window_practice/src/VertexArray.cpp
Normal file
38
Window_practice/src/VertexArray.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
#include "VertexArray.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
VertexArray::VertexArray()
|
||||
{
|
||||
GLCall(glGenVertexArrays(1, &m_RendererID));
|
||||
}
|
||||
|
||||
VertexArray::~VertexArray()
|
||||
{
|
||||
GLCall(glDeleteVertexArrays(1, &m_RendererID));
|
||||
}
|
||||
|
||||
void VertexArray::AddBuffer(const VertexBuffer& vb, const VertexBufferLayout& layout)
|
||||
{
|
||||
Bind();
|
||||
vb.Bind();
|
||||
const auto& elements = layout.GetElements();
|
||||
unsigned int offset = 0;
|
||||
|
||||
for (unsigned int i = 0; i < elements.size(); i++) {
|
||||
const auto& element = elements[i];
|
||||
GLCall(glEnableVertexAttribArray(i));
|
||||
GLCall(glVertexAttribPointer(i, element.count, element.type, element.normalized,
|
||||
layout.GetStride(), (const void*)offset));
|
||||
offset += element.count * VertexBufferElement::GetSizeOfType(element.type);
|
||||
}
|
||||
}
|
||||
|
||||
void VertexArray::Bind() const
|
||||
{
|
||||
GLCall(glBindVertexArray(m_RendererID));
|
||||
}
|
||||
|
||||
void VertexArray::Unbind() const
|
||||
{
|
||||
GLCall(glBindVertexArray(0));
|
||||
}
|
||||
16
Window_practice/src/VertexArray.h
Normal file
16
Window_practice/src/VertexArray.h
Normal file
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "VertexBuffer.h"
|
||||
#include "VertexBufferLayout.h"
|
||||
|
||||
class VertexArray {
|
||||
private:
|
||||
unsigned int m_RendererID;
|
||||
public:
|
||||
VertexArray();
|
||||
~VertexArray();
|
||||
|
||||
void AddBuffer(const VertexBuffer& vb, const VertexBufferLayout& layout);
|
||||
void Bind() const;
|
||||
void Unbind() const;
|
||||
};
|
||||
24
Window_practice/src/VertexBuffer.cpp
Normal file
24
Window_practice/src/VertexBuffer.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
#include "VertexBuffer.h"
|
||||
#include "Renderer.h"
|
||||
|
||||
VertexBuffer::VertexBuffer(const void* data, unsigned int size)
|
||||
{
|
||||
GLCall(glGenBuffers(1, &m_RendererID)); //number of buffer to generate
|
||||
GLCall(glBindBuffer(GL_ARRAY_BUFFER, m_RendererID)); //binding the buffer
|
||||
GLCall(glBufferData(GL_ARRAY_BUFFER, size, data, GL_STATIC_DRAW));
|
||||
}
|
||||
|
||||
VertexBuffer::~VertexBuffer()
|
||||
{
|
||||
GLCall(glDeleteBuffers(1, &m_RendererID));
|
||||
}
|
||||
|
||||
void VertexBuffer::Bind() const
|
||||
{
|
||||
GLCall(glBindBuffer(GL_ARRAY_BUFFER, m_RendererID));
|
||||
}
|
||||
|
||||
void VertexBuffer::Unbind() const
|
||||
{
|
||||
GLCall(glBindBuffer(GL_ARRAY_BUFFER, 0));
|
||||
}
|
||||
12
Window_practice/src/VertexBuffer.h
Normal file
12
Window_practice/src/VertexBuffer.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
class VertexBuffer {
|
||||
private:
|
||||
unsigned int m_RendererID;
|
||||
public:
|
||||
VertexBuffer(const void* data, unsigned int size);
|
||||
~VertexBuffer();
|
||||
|
||||
void Bind() const;
|
||||
void Unbind() const;
|
||||
};
|
||||
57
Window_practice/src/VertexBufferLayout.h
Normal file
57
Window_practice/src/VertexBufferLayout.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include "GL\glew.h"
|
||||
#include "Renderer.h";
|
||||
|
||||
struct VertexBufferElement {
|
||||
unsigned int type;
|
||||
unsigned int count;
|
||||
unsigned char normalized;
|
||||
|
||||
static unsigned int GetSizeOfType(unsigned int type) {
|
||||
switch (type)
|
||||
{
|
||||
case GL_FLOAT: return 4;
|
||||
case GL_UNSIGNED_INT: return 4;
|
||||
case GL_UNSIGNED_BYTE: return 1;
|
||||
}
|
||||
ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
class VertexBufferLayout {
|
||||
private:
|
||||
std::vector<VertexBufferElement> m_Elements;
|
||||
unsigned int m_Stride;
|
||||
public:
|
||||
VertexBufferLayout()
|
||||
: m_Stride(0){}
|
||||
|
||||
template<typename T>
|
||||
void Push(unsigned int count) {
|
||||
static_assert(false);
|
||||
}
|
||||
|
||||
template<>
|
||||
void Push<float>(unsigned int count) {
|
||||
m_Elements.push_back({ GL_FLOAT, count, GL_FALSE });
|
||||
m_Stride += VertexBufferElement::GetSizeOfType(GL_FLOAT) * count;
|
||||
}
|
||||
|
||||
template<>
|
||||
void Push<unsigned int>(unsigned int count) {
|
||||
m_Elements.push_back({ GL_UNSIGNED_INT ,count, GL_FALSE });
|
||||
m_Stride += VertexBufferElement::GetSizeOfType(GL_UNSIGNED_INT) * count;
|
||||
}
|
||||
|
||||
template<>
|
||||
void Push<unsigned char>(unsigned int count) {
|
||||
m_Elements.push_back({ GL_UNSIGNED_BYTE ,count, GL_TRUE });
|
||||
m_Stride += VertexBufferElement::GetSizeOfType(GL_UNSIGNED_BYTE) * count;
|
||||
}
|
||||
|
||||
inline const std::vector<VertexBufferElement> GetElements() const{ return m_Elements; }
|
||||
inline unsigned int GetStride() const { return m_Stride; }
|
||||
};
|
||||
Reference in New Issue
Block a user