Moved Index and Vertex buffer to a class
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,2 @@
|
||||
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
|
||||
|
||||
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.
@@ -145,10 +145,16 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\IndexBuffer.cpp" />
|
||||
<ClCompile Include="src\Main.cpp" />
|
||||
<ClCompile Include="src\Rernderer.cpp" />
|
||||
<ClCompile Include="src\VertexBuffer.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\IndexBuffer.h" />
|
||||
<ClInclude Include="src\Main.h" />
|
||||
<ClInclude Include="src\Renderer.h" />
|
||||
<ClInclude Include="src\VertexBuffer.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="res\shaders\Basic.shader" />
|
||||
|
||||
@@ -18,11 +18,29 @@
|
||||
<ClCompile Include="src\Main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</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>
|
||||
<ClInclude Include="src\Main.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</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>
|
||||
<None Include="res\shaders\Basic.shader" />
|
||||
|
||||
@@ -6,27 +6,9 @@
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
//Macros
|
||||
#define ASSERT(x) if(!(x)) __debugbreak();
|
||||
#define GLCall(x) GLClearError();\
|
||||
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;
|
||||
}
|
||||
#include "Renderer.h"
|
||||
#include "VertexBuffer.h"
|
||||
#include "IndexBuffer.h"
|
||||
|
||||
struct ShaderProgramSource {
|
||||
std::string VertexSource;
|
||||
@@ -138,7 +120,7 @@ int main(void){
|
||||
}
|
||||
|
||||
std::cout << "OpenGL version: " << glGetString(GL_VERSION) << std::endl;
|
||||
|
||||
{
|
||||
//vertex positions
|
||||
float positions[] = {
|
||||
-0.5f, -0.5f,
|
||||
@@ -159,26 +141,20 @@ int main(void){
|
||||
GLCall(glBindVertexArray(vao));
|
||||
|
||||
//Vertex buffer(s)
|
||||
unsigned int buffer;
|
||||
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));
|
||||
VertexBuffer vb(positions, 4 * 2 * sizeof(float));
|
||||
|
||||
GLCall(glEnableVertexAttribArray(0));
|
||||
GLCall(glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0));
|
||||
|
||||
//index buffer setup
|
||||
unsigned int ibo; //index buffer object
|
||||
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));
|
||||
//index buffer
|
||||
IndexBuffer ib(indecies, 6);
|
||||
|
||||
//Shader to console
|
||||
ShaderProgramSource source = ParseShader("res/shaders/Basic.shader");
|
||||
std::cout << "VERTEX" << std::endl;
|
||||
std::cout << source.VertexSource << std::endl;
|
||||
/*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;
|
||||
std::cout << source.FragmentSource << std::endl;*/
|
||||
|
||||
//Creating the shader
|
||||
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(glBindVertexArray(vao));
|
||||
GLCall(glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo));
|
||||
ib.Bind();
|
||||
|
||||
GLCall(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr));
|
||||
|
||||
@@ -228,7 +204,7 @@ int main(void){
|
||||
}
|
||||
|
||||
GLCall(glDeleteProgram(shader));
|
||||
|
||||
}
|
||||
glfwTerminate();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user