Moved Index and Vertex buffer to a class

This commit is contained in:
Tom
2021-06-09 13:55:45 +02:00
parent 86f61bed6b
commit 90812b2031
16 changed files with 103 additions and 106 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,5 +1,2 @@
Main.cpp Main.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
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

@@ -145,10 +145,16 @@
</Link> </Link>
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="src\IndexBuffer.cpp" />
<ClCompile Include="src\Main.cpp" /> <ClCompile Include="src\Main.cpp" />
<ClCompile Include="src\Rernderer.cpp" />
<ClCompile Include="src\VertexBuffer.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="src\IndexBuffer.h" />
<ClInclude Include="src\Main.h" /> <ClInclude Include="src\Main.h" />
<ClInclude Include="src\Renderer.h" />
<ClInclude Include="src\VertexBuffer.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="res\shaders\Basic.shader" /> <None Include="res\shaders\Basic.shader" />

View File

@@ -18,11 +18,29 @@
<ClCompile Include="src\Main.cpp"> <ClCompile Include="src\Main.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\Rernderer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\VertexBuffer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\IndexBuffer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="src\Main.h"> <ClInclude Include="src\Main.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\Renderer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\VertexBuffer.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\IndexBuffer.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="res\shaders\Basic.shader" /> <None Include="res\shaders\Basic.shader" />

View File

@@ -6,27 +6,9 @@
#include <string> #include <string>
#include <sstream> #include <sstream>
//Macros #include "Renderer.h"
#define ASSERT(x) if(!(x)) __debugbreak(); #include "VertexBuffer.h"
#define GLCall(x) GLClearError();\ #include "IndexBuffer.h"
x;\
ASSERT(GLLogCall(#x, __FILE__, __LINE__))
//Clearing OpenGl error list
static void GLClearError() {
while (glGetError() != GL_NO_ERROR);
}
//OpenGl logging
static 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;
}
struct ShaderProgramSource { struct ShaderProgramSource {
std::string VertexSource; std::string VertexSource;
@@ -138,7 +120,7 @@ int main(void){
} }
std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl; std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;
{
//vertex positions //vertex positions
float positions[] = { float positions[] = {
-0.5f, -0.5f, -0.5f, -0.5f,
@@ -159,26 +141,20 @@ int main(void){
GLCall(glBindVertexArray(vao)); GLCall(glBindVertexArray(vao));
//Vertex buffer(s) //Vertex buffer(s)
unsigned int buffer; VertexBuffer vb(positions, 4 * 2 * sizeof(float));
GLCall(glGenBuffers(1, &buffer)); //number of buffer to generate
GLCall(glBindBuffer(GL_ARRAY_BUFFER, buffer)); //binding the buffer
GLCall(glBufferData(GL_ARRAY_BUFFER, 4 * 2 * sizeof(float), positions, GL_STATIC_DRAW));
GLCall(glEnableVertexAttribArray(0)); GLCall(glEnableVertexAttribArray(0));
GLCall(glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0)); GLCall(glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0));
//index buffer setup //index buffer
unsigned int ibo; //index buffer object IndexBuffer ib(indecies, 6);
GLCall(glGenBuffers(1, &ibo));
GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo)); //binding the buffer
GLCall(glBufferData(GL_ELEMENT_ARRAY_BUFFER, 6 * sizeof(unsigned int), indecies, GL_STATIC_DRAW));
//Shader to console //Shader to console
ShaderProgramSource source = ParseShader("res/shaders/Basic.shader"); ShaderProgramSource source = ParseShader("res/shaders/Basic.shader");
std::cout << "VERTEX" << std::endl; /*std::cout << "VERTEX" << std::endl;
std::cout << source.VertexSource << std::endl; std::cout << source.VertexSource << std::endl; //to write shader to console
std::cout << "FRAGMENT" << std::endl; std::cout << "FRAGMENT" << std::endl;
std::cout << source.FragmentSource << std::endl; std::cout << source.FragmentSource << std::endl;*/
//Creating the shader //Creating the shader
unsigned int shader = CreateShader(source.VertexSource, source.FragmentSource); unsigned int shader = CreateShader(source.VertexSource, source.FragmentSource);
@@ -209,7 +185,7 @@ int main(void){
GLCall(glUniform4f(location, r, 0.3f, 0.8f, 1.0f)); GLCall(glUniform4f(location, r, 0.3f, 0.8f, 1.0f));
GLCall(glBindVertexArray(vao)); GLCall(glBindVertexArray(vao));
GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo)); ib.Bind();
GLCall(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr)); GLCall(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr));
@@ -228,7 +204,7 @@ int main(void){
} }
GLCall(glDeleteProgram(shader)); GLCall(glDeleteProgram(shader));
}
glfwTerminate(); glfwTerminate();
return 0; return 0;
} }