Buffer Layout abstraction
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,2 +1,10 @@
|
||||
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...
|
||||
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.
@@ -148,13 +148,16 @@
|
||||
<ClCompile Include="src\IndexBuffer.cpp" />
|
||||
<ClCompile Include="src\Main.cpp" />
|
||||
<ClCompile Include="src\Rernderer.cpp" />
|
||||
<ClCompile Include="src\VertexArray.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\VertexArray.h" />
|
||||
<ClInclude Include="src\VertexBuffer.h" />
|
||||
<ClInclude Include="src\VertexBufferLayout.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="res\shaders\Basic.shader" />
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
<ClCompile Include="src\IndexBuffer.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\VertexArray.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="src\Main.h">
|
||||
@@ -41,6 +44,12 @@
|
||||
<ClInclude Include="src\IndexBuffer.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\VertexArray.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="src\VertexBufferLayout.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="res\shaders\Basic.shader" />
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "Renderer.h"
|
||||
#include "VertexBuffer.h"
|
||||
#include "IndexBuffer.h"
|
||||
#include "VertexArray.h"
|
||||
|
||||
struct ShaderProgramSource {
|
||||
std::string VertexSource;
|
||||
@@ -71,7 +72,6 @@ static unsigned int CompileShader(unsigned int type, const std::string& source)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ int main(void){
|
||||
//OpenGL version and profile
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //core does not have deafult vao
|
||||
|
||||
//Main window creation
|
||||
GLFWwindow* window = glfwCreateWindow(640, 480, "OpenGl practice", NULL, NULL);
|
||||
@@ -129,7 +129,7 @@ int main(void){
|
||||
-0.5f, 0.5f
|
||||
};
|
||||
|
||||
//index buffer
|
||||
//index buffer indecies
|
||||
unsigned int indecies[]{
|
||||
0, 1, 2,
|
||||
2, 3, 0
|
||||
@@ -140,21 +140,14 @@ int main(void){
|
||||
GLCall(glGenVertexArrays(1, &vao));
|
||||
GLCall(glBindVertexArray(vao));
|
||||
|
||||
//Vertex buffer(s)
|
||||
VertexArray va;
|
||||
VertexBuffer vb(positions, 4 * 2 * sizeof(float));
|
||||
|
||||
GLCall(glEnableVertexAttribArray(0));
|
||||
GLCall(glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, 0));
|
||||
|
||||
//index buffer
|
||||
VertexBufferLayout layout;
|
||||
layout.Push<float>(2);
|
||||
va.AddBuffer(vb, layout);
|
||||
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; //to write shader to console
|
||||
std::cout << "FRAGMENT" << std::endl;
|
||||
std::cout << source.FragmentSource << std::endl;*/
|
||||
|
||||
//Creating the shader
|
||||
unsigned int shader = CreateShader(source.VertexSource, source.FragmentSource);
|
||||
@@ -184,7 +177,7 @@ int main(void){
|
||||
GLCall(glUseProgram(shader));
|
||||
GLCall(glUniform4f(location, r, 0.3f, 0.8f, 1.0f));
|
||||
|
||||
GLCall(glBindVertexArray(vao));
|
||||
va.Bind();
|
||||
ib.Bind();
|
||||
|
||||
GLCall(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr));
|
||||
|
||||
Reference in New Issue
Block a user