This commit is contained in:
Tobias Dahl
2014-03-03 20:22:47 +01:00
parent c60b490d01
commit 40d0db4dc2
6 changed files with 146 additions and 2 deletions
+2
View File
@@ -89,6 +89,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="Model.cpp" />
<ClCompile Include="Renderer\Renderer.cpp" />
<ClCompile Include="Systems\CollisionSystem.cpp" />
<ClCompile Include="Systems\InputSystem.cpp" />
@@ -105,6 +106,7 @@
<ClInclude Include="Entity.h" />
<ClInclude Include="logging.h" />
<ClInclude Include="glerror.h" />
<ClInclude Include="Model.h" />
<ClInclude Include="Renderer\Renderer.h" />
<ClInclude Include="Systems\CollisionSystem.h" />
<ClInclude Include="Systems\InputSystem.h" />
@@ -60,6 +60,9 @@
<ClCompile Include="Renderer\Renderer.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
<ClCompile Include="Model.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="glerror.h">
@@ -107,6 +110,9 @@
<ClInclude Include="Renderer\Renderer.h">
<Filter>Header Files\Renderer</Filter>
</ClInclude>
<ClInclude Include="Model.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="Shaders\Fragment.glsl">
+67
View File
@@ -0,0 +1,67 @@
#include "Model.h"
Model::Model()
{
temp_CreateModelShit();
CreateBuffers();
}
void Model::temp_CreateModelShit()
{
Vertices.push_back(0.0f);
Vertices.push_back(0.0f);
Vertices.push_back(2.0f);
Vertices.push_back(0.0f);
Vertices.push_back(1.0f);
Vertices.push_back(2.0f);
Vertices.push_back(1.0f);
Vertices.push_back(0.0f);
Vertices.push_back(2.0f);
Normals.push_back();
Normals.push_back();
Normals.push_back();
}
void Model::CreateBuffers( std::vector<float> _Vertices, std::vector<float> _Normals, std::vector<float> _TextureCoords )
{
glGenBuffers(1, &VertBuffer);
glBindBuffer(GL_ARRAY_BUFFER, VertBuffer);
glBufferData(GL_ARRAY_BUFFER, Vertices.size()*sizeof(float), Vertices.data, GL_STATIC_DRAW);
GLERROR("GLEW: BufferFail1");
glGenBuffers(1, &NormalBuffer);
glBindBuffer(GL_ARRAY_BUFFER, NormalBuffer);
glBufferData(GL_ARRAY_BUFFER, Normals.size()*sizeof(float), Normals.data, GL_STATIC_DRAW);
GLERROR("GLEW: BufferFail2");
glGenBuffers(1, &TextureCoordBuffer);
glBindBuffer(GL_ARRAY_BUFFER, TextureCoordBuffer);
glBufferData(GL_ARRAY_BUFFER, TextureCoords.size()*sizeof(float), TextureCoords.data, GL_STATIC_DRAW);
GLERROR("GLEW: BufferFail3");
glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO);
GLERROR("GLEW: BufferFail4");
glBindBuffer(GL_ARRAY_BUFFER, VertBuffer);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
GLERROR("GLEW: BufferFail5");
glBindBuffer(GL_ARRAY_BUFFER, NormalBuffer);
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, TextureCoordBuffer);
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
GLERROR("GLEW: BufferFail5");
}
+41
View File
@@ -0,0 +1,41 @@
#include <string>
#include <fstream>
#include <iostream>
#include <sstream>
#include <vector>
#define _CRT_SECURE_NO_WARNINGS
#include <GL/glew.h>
#define GLFW_INCLUDE_GLU
#include <GLFW/glfw3.h>
#include <glext.h>
#define GLM_FORCE_RADIANS
#include <glm/glm.hpp>
#include <glm/gtc/constants.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include "glerror.h"
#include <cstdlib>
class Model
{
public:
glm::vec3 Position;
std::vector<float> Vertices;
std::vector<float> Normals;
std::vector<float> TextureCoords;
GLuint VertBuffer;
GLuint NormalBuffer;
GLuint TextureCoordBuffer;
GLuint VAO;
Model();
void temp_CreateModelShit();
void CreateBuffers(std::vector<float>, std::vector<float>, std::vector<float>);
};
+25 -1
View File
@@ -5,6 +5,29 @@ Renderer::Renderer()
}
void Renderer::Draw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
glUseProgram(shaderProgram);
}
void Renderer::DrawText()
{
//DrawShitInTextForm
}
void Renderer::AddTextToDraw()
{
//Add to draw shit vector
}
void Renderer::AddObjectToDraw()
{
}
//Fixa med shaders, lägga in alla verts osv.
@@ -52,4 +75,5 @@ GLuint Renderer::CompileShader(GLenum shaderType, std::string fileName)
return shader;
}
}
+5 -1
View File
@@ -24,12 +24,16 @@ public:
GLuint shaderProgram;
GLuint VAO;
std::vector<std::vector<float>> Vertices;
std::vector<std::vector<float>> Normals;
std::vector<std::vector<float>> TextureCoords;
Renderer();
void Draw();
void DrawText();
void AddObjectToDraw();
void AddObjectToDraw(std::vector<float>, std::vector<float>, std::vector<float>);
void AddTextToDraw();
GLuint CompileShader(GLenum, std::string);