mirror of
https://github.com/Ed94/DuctTaped_GL.git
synced 2024-11-10 04:24:52 -08:00
Applied gorilla tape for models... Still need to add scotch for buffering it.
This commit is contained in:
parent
4baabf7acc
commit
d9100a3ff5
@ -1,6 +1,10 @@
|
||||
|
||||
|
||||
#version 330 core
|
||||
|
||||
|
||||
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
in vec2 TexCoord;
|
||||
@ -8,6 +12,9 @@ in vec2 TexCoord;
|
||||
uniform sampler2D texture1;
|
||||
uniform sampler2D texture2;
|
||||
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = mix(texture(texture1, TexCoord), texture(texture2, TexCoord), 0.2);
|
||||
|
@ -31,7 +31,7 @@ namespace Actions
|
||||
public:
|
||||
AAction(ActionType _actionToAssign, ActionParams... _params) :
|
||||
action(_actionToAssign),
|
||||
params(_params...)
|
||||
params(_params... )
|
||||
{};
|
||||
|
||||
private:
|
||||
|
14
BasicLamp.frag
Normal file
14
BasicLamp.frag
Normal file
@ -0,0 +1,14 @@
|
||||
#version 330 core
|
||||
|
||||
|
||||
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(1.0); // set all 4 vector values to 1.0
|
||||
}
|
15
BasicLighting.frag
Normal file
15
BasicLighting.frag
Normal file
@ -0,0 +1,15 @@
|
||||
#version 330 core
|
||||
|
||||
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
uniform vec3 ObjectColor;
|
||||
uniform vec3 LightColor ;
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColor = vec4(LightColor * ObjectColor, 1.0);
|
||||
}
|
@ -15,10 +15,12 @@ This merely removes the need to use operators I don't like and wraps them in eas
|
||||
#include <algorithm >
|
||||
#include <chrono >
|
||||
#include <cstdarg >
|
||||
#include <cstddef>
|
||||
#include <exception >
|
||||
#include <fstream >
|
||||
#include <functional>
|
||||
#include <iostream >
|
||||
#include <cmath >
|
||||
#include <memory >
|
||||
#include <queue >
|
||||
#include <sstream >
|
||||
@ -149,3 +151,4 @@ sfn ErrorRuntime(const Ref(std::runtime_error) _error)
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
17
DGL.hpp
17
DGL.hpp
@ -13,6 +13,7 @@
|
||||
#include "DGL_Shader.hpp"
|
||||
#include "DGL_Buffers.hpp"
|
||||
#include "DGL_Space.hpp"
|
||||
#include "DGL_Model.hpp"
|
||||
|
||||
// Non-Standard C++
|
||||
#include "Cpp_Alias.hpp"
|
||||
@ -119,15 +120,7 @@ namespace DGL
|
||||
return;
|
||||
}
|
||||
|
||||
sfn DrawArrays(EPrimitives _primitive, gInt _startingIndex, gInt _numToRender)
|
||||
{
|
||||
glDrawArrays(GLenum(_primitive), _startingIndex, _numToRender); // Starting from vertex 0; 3 vertices total -> 1 triangle.
|
||||
}
|
||||
|
||||
sfn DrawElements(EPrimitives _primitive, gSize _numElements, EDataType _dataType, DataPtr _offfsetAddressFromFirstIndex)
|
||||
{
|
||||
glDrawElements(GLenum(_primitive), _numElements, GLenum(_dataType), _offfsetAddressFromFirstIndex);
|
||||
}
|
||||
|
||||
|
||||
sfn GetCursorPosition(ptr<Window> _window, ptr<double> _xAxis, ptr<double> _yAxis)
|
||||
{
|
||||
@ -329,4 +322,10 @@ namespace DGL
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// RawTape
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
namespace DGL
|
||||
{
|
||||
sfn BindBuffer(const EBufferTarget _targetType, const ID<Buffer> _buffer)
|
||||
sfn BindBuffer(const EBufferTarget _targetType, const ID<VertexBuffer> _buffer)
|
||||
{
|
||||
glBindBuffer(GLenum(_targetType), _buffer);
|
||||
|
||||
@ -37,6 +37,11 @@ namespace DGL
|
||||
return;
|
||||
}
|
||||
|
||||
sfn BufferData(DataPtr _data, gSize _sizeOfData, const EBufferTarget _targetType, const EBufferUsage _usageType)
|
||||
{
|
||||
glBufferData(GLenum(_targetType), _sizeOfData, _data, GLenum(_usageType));
|
||||
}
|
||||
|
||||
template<typename... Type, typename = EFrameBuffer>
|
||||
sfn ClearBuffer(const Type... _buffersToClear)
|
||||
{
|
||||
@ -50,6 +55,16 @@ namespace DGL
|
||||
glDisableVertexAttribArray(_vertexAttributeArrayIndex);
|
||||
}
|
||||
|
||||
sfn DrawArrays(EPrimitives _primitive, gInt _startingIndex, gInt _numToRender)
|
||||
{
|
||||
glDrawArrays(GLenum(_primitive), _startingIndex, _numToRender); // Starting from vertex 0; 3 vertices total -> 1 triangle.
|
||||
}
|
||||
|
||||
sfn DrawElements(EPrimitives _primitive, gSize _numElements, EDataType _dataType, DataPtr _offfsetAddressFromFirstIndex)
|
||||
{
|
||||
glDrawElements(GLenum(_primitive), _numElements, GLenum(_dataType), _offfsetAddressFromFirstIndex);
|
||||
}
|
||||
|
||||
sfn EnableVertexAttributeArray(const gInt _vertexAttributeArrayIndex)
|
||||
{
|
||||
glEnableVertexAttribArray(_vertexAttributeArrayIndex);
|
||||
@ -89,4 +104,11 @@ namespace DGL
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sfn GetBufferParameterIV(EBufferTarget _target, EBufferParam _param, ptr<gInt> _data)
|
||||
{
|
||||
glGetBufferParameteriv(GLenum(_target), GLenum(_param), _data);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
14
DGL_Enum.hpp
14
DGL_Enum.hpp
@ -17,6 +17,14 @@ namespace DGL
|
||||
True = GL_TRUE ,
|
||||
False = GL_FALSE
|
||||
};
|
||||
|
||||
enum class EBufferParam
|
||||
{
|
||||
AccessPolicy = GL_BUFFER_ACCESS,
|
||||
IsMapped = GL_BUFFER_MAPPED,
|
||||
Size = GL_BUFFER_SIZE ,
|
||||
UsagePattern = GL_BUFFER_USAGE
|
||||
};
|
||||
|
||||
enum class EBufferTarget
|
||||
{
|
||||
@ -106,6 +114,8 @@ namespace DGL
|
||||
enum class EKeyCodes
|
||||
{
|
||||
F1 = GLFW_KEY_F1 ,
|
||||
F2 = GLFW_KEY_F2 ,
|
||||
F3 = GLFW_KEY_F3 ,
|
||||
A = GLFW_KEY_A ,
|
||||
D = GLFW_KEY_D ,
|
||||
E = GLFW_KEY_E ,
|
||||
@ -113,7 +123,9 @@ namespace DGL
|
||||
S = GLFW_KEY_S ,
|
||||
W = GLFW_KEY_W ,
|
||||
LeftShift = GLFW_KEY_LEFT_SHIFT,
|
||||
Escape = GLFW_KEY_ESCAPE
|
||||
Escape = GLFW_KEY_ESCAPE,
|
||||
UpArrow = GLFW_KEY_UP,
|
||||
DnArrow = GLFW_KEY_DOWN
|
||||
};
|
||||
|
||||
enum class EKeyState
|
||||
|
@ -26,6 +26,24 @@ namespace DGL
|
||||
template<typename ReferenceType>
|
||||
using ID = gUInt;
|
||||
|
||||
// ID Reference Types
|
||||
|
||||
class VertexBuffer ;
|
||||
class NormalBuffer;
|
||||
class Vec3 ;
|
||||
class Matrix ;
|
||||
class Shader ;
|
||||
class ShaderProgram;
|
||||
class VertexArray ;
|
||||
class ElementBuffer;
|
||||
|
||||
|
||||
|
||||
using Matrix4x4 = glm::mat4;
|
||||
|
||||
using Vector2 = glm::vec2;
|
||||
using Vector3 = glm::vec3;
|
||||
using Vector4 = glm::vec4;
|
||||
|
||||
struct LinearColor
|
||||
{
|
||||
@ -33,19 +51,10 @@ namespace DGL
|
||||
|
||||
LinearColor(gFloatClamped _red, gFloatClamped _green, gFloatClamped _blue, gFloatClamped _alpha) :
|
||||
Red(_red), Green(_green), Blue(_blue), Alpha(_alpha) {};
|
||||
|
||||
sfn Vector() -> Vector3
|
||||
{
|
||||
return Vector3(Red, Green, Blue);
|
||||
}
|
||||
};
|
||||
|
||||
// ID Reference Types
|
||||
|
||||
class Buffer ;
|
||||
class Matrix ;
|
||||
class Shader ;
|
||||
class ShaderProgram;
|
||||
class VertexBuffer ;
|
||||
class ElementBuffer;
|
||||
|
||||
using Matrix4x4 = glm::mat4;
|
||||
|
||||
using Vector3 = glm::vec3;
|
||||
using Vector4 = glm::vec4;
|
||||
}
|
||||
|
362
DGL_Model.hpp
Normal file
362
DGL_Model.hpp
Normal file
@ -0,0 +1,362 @@
|
||||
#pragma once
|
||||
|
||||
#include "DGL_Buffers.hpp"
|
||||
#include "DGL_Space.hpp"
|
||||
|
||||
#include "Cpp_Alias.hpp"
|
||||
|
||||
|
||||
|
||||
namespace DGL
|
||||
{
|
||||
sfn Offset(gInt _offsetAmount)
|
||||
{
|
||||
return ptr<void>(_offsetAmount);
|
||||
}
|
||||
|
||||
constexpr sfn ZeroOffset() -> ptr<void>
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
using std::string;
|
||||
|
||||
using VertexList = std ::vector < Vector3>;
|
||||
using UVList = std ::vector < Vector2>;
|
||||
using VecInt = Generic::Vector3< gInt >;
|
||||
|
||||
|
||||
|
||||
struct VertexGenerator
|
||||
{
|
||||
using ComponentList = std::vector< gFloat>;
|
||||
|
||||
ComponentList comp;
|
||||
|
||||
void Normalize()
|
||||
{
|
||||
using std::pow ;
|
||||
using std::sqrt;
|
||||
|
||||
using Element = ComponentList::iterator;
|
||||
|
||||
gFloat magnitude = 0.0f;
|
||||
|
||||
for (Element element = comp.begin(); element != comp.end(); element++)
|
||||
{
|
||||
magnitude += pow(*element, 2.0f);
|
||||
}
|
||||
|
||||
magnitude = sqrt(magnitude);
|
||||
|
||||
for (Element element = comp.begin(); element != comp.end(); element++)
|
||||
{
|
||||
*element /= magnitude;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: De-hard-code this generator to do any vector size.
|
||||
sfn GetVector() -> Vector3
|
||||
{
|
||||
return Vector3(comp.at(0), comp.at(1), comp.at(2));
|
||||
}
|
||||
};
|
||||
|
||||
/*struct Face
|
||||
{
|
||||
VecInt Vertexes, UVs, Normals;
|
||||
};*/
|
||||
|
||||
struct Face
|
||||
{
|
||||
VecInt Vertexes, Normals;
|
||||
};
|
||||
|
||||
struct FaceGenerator
|
||||
{
|
||||
using ComponentList = std::vector< gInt>;
|
||||
|
||||
ComponentList vertIndexes, uvIndexes, normals;
|
||||
|
||||
sfn AddVertexIndex(gInt _index)
|
||||
{
|
||||
vertIndexes.push_back(_index);
|
||||
}
|
||||
|
||||
sfn AddUVIndex(gInt _index)
|
||||
{
|
||||
uvIndexes.push_back(_index);
|
||||
}
|
||||
|
||||
sfn AddNormalIndex(gInt _index)
|
||||
{
|
||||
normals.push_back(_index);
|
||||
}
|
||||
|
||||
sfn GetFace() -> Face
|
||||
{
|
||||
Face generated;
|
||||
|
||||
if (vertIndexes.size() != 0)
|
||||
{
|
||||
for (int index = 0; index < vertIndexes.size(); index++)
|
||||
{
|
||||
generated.Vertexes[index] = vertIndexes.at(index);
|
||||
}
|
||||
}
|
||||
if (uvIndexes.size() != 0)
|
||||
{
|
||||
for (int index = 0; index < uvIndexes.size(); index++)
|
||||
{
|
||||
//generated.UVs[index] = uvIndexes.at(index);
|
||||
}
|
||||
}
|
||||
if (normals.size() != 0)
|
||||
{
|
||||
for (int index = 0; index < normals.size(); index++)
|
||||
{
|
||||
generated.Normals[index] = normals.at(index);
|
||||
}
|
||||
}
|
||||
|
||||
return generated;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
struct Model
|
||||
{
|
||||
using FaceList = std::vector< Face>;
|
||||
using VIndexList = std::vector< gInt>;
|
||||
|
||||
struct VN
|
||||
{
|
||||
Vector3 Vertex, Normal;
|
||||
|
||||
VN(Vector3 _v, Vector3 _n) : Vertex(_v), Normal(_n) {};
|
||||
};
|
||||
|
||||
using VNList = std::vector<VN>;
|
||||
|
||||
ID<VertexArray > VAO;
|
||||
ID<VertexBuffer > VBO;
|
||||
ID<NormalBuffer > NBO;
|
||||
ID<ElementBuffer> EBO;
|
||||
|
||||
const string FilePath;
|
||||
|
||||
VertexList Verticies ;
|
||||
VertexList VertNormals;
|
||||
UVList TextureMap ;
|
||||
FaceList Faces ;
|
||||
VIndexList Indicies ;
|
||||
|
||||
Model(const Ref(string) _filePath) :
|
||||
VAO(-1),
|
||||
VBO(-1),
|
||||
NBO(-1),
|
||||
EBO(-1),
|
||||
FilePath (_filePath ),
|
||||
Verticies (VertexList()),
|
||||
VertNormals(VertexList()),
|
||||
TextureMap (UVList ()),
|
||||
Faces (FaceList ())
|
||||
{}
|
||||
|
||||
// TODO: Add support for textures...
|
||||
sfn Load()
|
||||
{
|
||||
using std::cout ;
|
||||
using std::endl ;
|
||||
using std::ifstream ;
|
||||
using std::ios ;
|
||||
using std::stringstream;
|
||||
using std::getline;
|
||||
using std::ws;
|
||||
using std::get;
|
||||
|
||||
|
||||
ifstream fileBuffer;
|
||||
|
||||
fileBuffer.open(FilePath);
|
||||
|
||||
deduce processVertex = [&](Ref(stringstream) _vertexStream)
|
||||
{
|
||||
VertexGenerator vertex; gFloat componentValue;
|
||||
|
||||
while (not _vertexStream.eof())
|
||||
{
|
||||
_vertexStream >> componentValue >> ws;
|
||||
|
||||
vertex.comp.push_back(componentValue);
|
||||
}
|
||||
|
||||
Verticies.push_back(vertex.GetVector());
|
||||
};
|
||||
|
||||
deduce processNormals = [&](Ref(stringstream) _normalStream)
|
||||
{
|
||||
VertexGenerator normal; gFloat componentValue;
|
||||
|
||||
while (not _normalStream.eof())
|
||||
{
|
||||
_normalStream >> componentValue >> ws;
|
||||
|
||||
normal.comp.push_back(componentValue);
|
||||
}
|
||||
|
||||
normal.Normalize();
|
||||
|
||||
VertNormals.push_back(normal.GetVector());
|
||||
};
|
||||
|
||||
deduce processFace = [&](Ref(stringstream) _faceStream)
|
||||
{
|
||||
FaceGenerator faceMade; gInt vertexIndex, textureIndex, normalIndex;
|
||||
|
||||
while (not _faceStream.eof())
|
||||
{
|
||||
_faceStream >> vertexIndex >> ws;
|
||||
|
||||
faceMade.AddVertexIndex(vertexIndex - 1);
|
||||
|
||||
Indicies.push_back(vertexIndex - 1);
|
||||
|
||||
if (_faceStream.peek() == '/')
|
||||
{
|
||||
_faceStream.get();
|
||||
|
||||
if (_faceStream.peek() == '/')
|
||||
{
|
||||
_faceStream.get();
|
||||
|
||||
_faceStream >> normalIndex >> ws;
|
||||
|
||||
faceMade.AddNormalIndex(normalIndex - 1);
|
||||
|
||||
Indicies.push_back(normalIndex - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
_faceStream >> textureIndex >> ws;
|
||||
|
||||
faceMade.AddUVIndex(textureIndex - 1);
|
||||
|
||||
if (_faceStream.peek() == '/')
|
||||
{
|
||||
_faceStream.get();
|
||||
|
||||
_faceStream >> normalIndex >> ws;
|
||||
|
||||
faceMade.AddNormalIndex(normalIndex - 1);
|
||||
|
||||
Indicies.push_back(normalIndex - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Faces.push_back(faceMade.GetFace());
|
||||
};
|
||||
|
||||
if (fileBuffer.is_open())
|
||||
{
|
||||
stringstream stringBuffer;
|
||||
|
||||
stringBuffer << fileBuffer.rdbuf();
|
||||
|
||||
string line;
|
||||
|
||||
while (not stringBuffer.eof())
|
||||
{
|
||||
getline(stringBuffer, line);
|
||||
|
||||
stringstream lineStream(line);
|
||||
|
||||
string lineSig;
|
||||
|
||||
lineStream >> lineSig >> ws;
|
||||
|
||||
if (lineSig == "v")
|
||||
{
|
||||
processVertex(lineStream);
|
||||
}
|
||||
else if (lineSig == "vn")
|
||||
{
|
||||
processNormals(lineStream);
|
||||
}
|
||||
else if (lineSig == "f")
|
||||
{
|
||||
processFace(lineStream);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Could not open file to load model.");
|
||||
}
|
||||
|
||||
|
||||
fileBuffer.close();
|
||||
}
|
||||
|
||||
// Hardcoded to only do the verticies and normals for now...
|
||||
sfn Buffer()
|
||||
{
|
||||
GenerateVertexBuffers(Address(VAO), 1);
|
||||
GenerateBuffers (Address(VBO), 1);
|
||||
GenerateBuffers (Address(NBO), 1);
|
||||
GenerateBuffers (Address(EBO), 1);
|
||||
|
||||
BindVertexArray(VAO);
|
||||
|
||||
|
||||
|
||||
BindBuffer(EBufferTarget::VertexAttributes, VBO);
|
||||
|
||||
BufferData(Address(Verticies[0]), Verticies.size() * sizeof(Vector3), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
|
||||
|
||||
|
||||
BindBuffer(EBufferTarget::VertexAttributes, NBO);
|
||||
|
||||
BufferData(Address(VertNormals[0]), VertNormals.size() * sizeof(Vector3), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
|
||||
|
||||
|
||||
BindBuffer(EBufferTarget::VertexIndices, EBO);
|
||||
|
||||
BufferData(Address(Faces[0]), Faces.size() * sizeof(Face), EBufferTarget::VertexIndices, EBufferUsage::StaticDraw);
|
||||
|
||||
|
||||
//BufferData(Address(Indicies[0]), Indicies.size() * sizeof(gInt), EBufferTarget::VertexIndices, EBufferUsage::StaticDraw);
|
||||
|
||||
EnableVertexAttributeArray(0);
|
||||
FormatVertexAttributes<Vector3>(0, EDataType::Float, ZeroOffset(), 3, EBool::False);
|
||||
|
||||
//EnableVertexAttributeArray(1);
|
||||
//FormatVertexAttributes<Vector3>(1, EDataType::Float, ZeroOffset(), 3, EBool::False);
|
||||
|
||||
BindVertexArray(0);
|
||||
}
|
||||
|
||||
sfn Render()
|
||||
{
|
||||
BindVertexArray(VAO);
|
||||
|
||||
BindBuffer(EBufferTarget::VertexIndices, EBO);
|
||||
|
||||
gInt Size; GetBufferParameterIV(EBufferTarget::VertexIndices, DGL::EBufferParam::Size, Address(Size));
|
||||
|
||||
Size /= sizeof(Face);
|
||||
|
||||
DrawElements(DGL::EPrimitives::Triangles, Size, EDataType::UnsignedInt, ZeroOffset());
|
||||
|
||||
BindVertexArray(0);
|
||||
}
|
||||
};
|
||||
};
|
@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "DGL_Space.hpp"
|
||||
|
||||
|
||||
|
||||
namespace DGL
|
||||
{
|
||||
|
||||
struct Primitive
|
||||
{
|
||||
};
|
||||
}
|
111
DGL_Shader.hpp
111
DGL_Shader.hpp
@ -328,6 +328,13 @@ namespace DGL
|
||||
return;
|
||||
}
|
||||
|
||||
sfn SetUniformVariable_Vector3(const ID<Vec3> _ID, const gSize _numColor3, ptr<const gFloat> _dataPtr)
|
||||
{
|
||||
glUniform3fv(_ID, _numColor3, _dataPtr);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sfn UseProgramShader(ID<ShaderProgram> _shaderProgramToUse)
|
||||
{
|
||||
glUseProgram(_shaderProgramToUse);
|
||||
@ -359,12 +366,105 @@ namespace DGL
|
||||
}
|
||||
}
|
||||
|
||||
namespace Basic_LightingShader
|
||||
{
|
||||
ID<ShaderProgram> Shader;
|
||||
|
||||
ID<CoordSpace> ScreenSpaceVarID;
|
||||
|
||||
ID<Vec3> ObjectColorID, LightColorID;
|
||||
|
||||
sfn LoadShader()
|
||||
{
|
||||
Shader = LoadShaders("SimpleTransform.vert", "BasicLighting.frag");
|
||||
|
||||
ScreenSpaceVarID = GetUniformVariable(Shader, "ScreenSpaceTransform");
|
||||
|
||||
ObjectColorID = GetUniformVariable(Shader, "ObjectColor");
|
||||
LightColorID = GetUniformVariable(Shader, "LightColor" );
|
||||
}
|
||||
|
||||
sfn SetupRender(Ref(CoordSpace) _cubeTransform, Ref(Vector3) _objectColor, Ref(Vector3) _lightColor)
|
||||
{
|
||||
UseProgramShader(Shader);
|
||||
|
||||
SetUniformVariable_MVA(ScreenSpaceVarID, 1, EBool::False, Address(_cubeTransform[0][0]));
|
||||
|
||||
SetUniformVariable_Vector3(ObjectColorID, 1, Address(_objectColor[0]));
|
||||
SetUniformVariable_Vector3(LightColorID , 1, Address(_lightColor [0]));
|
||||
}
|
||||
}
|
||||
|
||||
namespace Basic_LampShader
|
||||
{
|
||||
ID<ShaderProgram> Shader;
|
||||
|
||||
ID<CoordSpace> ScreenSpaceVarID;
|
||||
|
||||
sfn LoadShader()
|
||||
{
|
||||
Shader = LoadShaders("SimpleTransform.vert", "BasicLamp.frag");
|
||||
|
||||
ScreenSpaceVarID = GetUniformVariable(Shader, "ScreenSpaceTransform");
|
||||
}
|
||||
|
||||
sfn SetupLampRender(Ref(CoordSpace) _lampTransform)
|
||||
{
|
||||
UseProgramShader(Shader);
|
||||
|
||||
SetUniformVariable_MVA(ScreenSpaceVarID, 1, EBool::False, Address(_lampTransform[0][0]));
|
||||
}
|
||||
}
|
||||
|
||||
namespace PhongShader
|
||||
{
|
||||
ID<ShaderProgram> ShaderID;
|
||||
|
||||
ID<CoordSpace> ModelScreenSpaceID, ModelSpaceID;
|
||||
|
||||
ID<Vec3> LightPositionID;
|
||||
|
||||
ID<Vec3> ObjectColorID, LightColorID;
|
||||
|
||||
sfn LoadShader()
|
||||
{
|
||||
ShaderID = LoadShaders("PhongShader.vert", "PhongShader.frag");
|
||||
|
||||
ModelScreenSpaceID = GetUniformVariable(ShaderID, "ModelScreenSpace");
|
||||
ModelSpaceID = GetUniformVariable(ShaderID, "ModelSpace" );
|
||||
|
||||
ObjectColorID = GetUniformVariable(ShaderID, "ObjectColor" );
|
||||
LightColorID = GetUniformVariable(ShaderID, "LightColor" );
|
||||
LightPositionID = GetUniformVariable(ShaderID, "LightPositionID");
|
||||
}
|
||||
|
||||
sfn SetupRender
|
||||
(
|
||||
Ref(CoordSpace) _screenSapceTransform,
|
||||
Ref(CoordSpace) _objectTransform ,
|
||||
Ref(Vector3 ) _objectColor ,
|
||||
Ref(Vector3 ) _lightPosition ,
|
||||
Ref(Vector3 ) _lightColor
|
||||
)
|
||||
{
|
||||
UseProgramShader(ShaderID);
|
||||
|
||||
SetUniformVariable_MVA(ModelScreenSpaceID, 1, EBool::False, Address(_screenSapceTransform[0][0]));
|
||||
SetUniformVariable_MVA(ModelSpaceID , 1, EBool::False, Address(_objectTransform [0][0]));
|
||||
|
||||
SetUniformVariable_Vector3(LightPositionID, 1, Address(_lightPosition[0]));
|
||||
|
||||
SetUniformVariable_Vector3(ObjectColorID, 1, Address(_objectColor[0]));
|
||||
SetUniformVariable_Vector3(LightColorID , 1, Address(_lightColor [0]));
|
||||
}
|
||||
}
|
||||
|
||||
sfn LoadRawShader()
|
||||
{
|
||||
ID<Shader> VertexShader;
|
||||
ID<Shader> FragmentShader;
|
||||
|
||||
MakeShader(VertexShader, EShaderType::Vertex, 1, Address(DGL::RawVertextShaderSource), NULL);
|
||||
MakeShader(VertexShader , EShaderType::Vertex , 1, Address(DGL::RawVertextShaderSource ), NULL);
|
||||
MakeShader(FragmentShader, EShaderType::Fragment, 1, Address(DGL::RawFragmentShaderSource), NULL);
|
||||
|
||||
MakeShaderProgram(RawShader, VertexShader, FragmentShader);
|
||||
@ -384,9 +484,12 @@ namespace DGL
|
||||
|
||||
sfn LoadDefaultShaders()
|
||||
{
|
||||
LoadRawShader ();
|
||||
LoadSimpleShader();
|
||||
SS_Transformed::LoadShader ();
|
||||
LoadRawShader ();
|
||||
LoadSimpleShader();
|
||||
SS_Transformed ::LoadShader ();
|
||||
Basic_LampShader ::LoadShader ();
|
||||
Basic_LightingShader::LoadShader ();
|
||||
PhongShader ::LoadShader ();
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -65,6 +65,11 @@ namespace DGL
|
||||
return glm::rotate(_matrix, _rotationAngleAmount, _axis);
|
||||
}
|
||||
|
||||
sfn Scale(const Matrix4x4 _matrix, Vector3 _scaleBy)
|
||||
{
|
||||
return glm::scale(_matrix, _scaleBy);
|
||||
}
|
||||
|
||||
template<typename Type>
|
||||
sfn ToRadians(const Ref(Type) _degrees) -> Type
|
||||
{
|
||||
@ -90,8 +95,8 @@ namespace DGL
|
||||
gFloat
|
||||
AspectRatio = 16.0f / 10.0f,
|
||||
FieldOfView = 90.0f ,
|
||||
NearClippingPlane = 0.1f ,
|
||||
FarClippingPlane = 100.0f ;
|
||||
NearClippingPlane = 0.01f ,
|
||||
FarClippingPlane = 1000.0f ;
|
||||
|
||||
Vector3 CameraPosition( 0, 0, 2),
|
||||
LookAtPosition( 0, 0, 0),
|
||||
@ -216,32 +221,21 @@ namespace DGL
|
||||
Pitch = -89.9f;
|
||||
}
|
||||
|
||||
break;
|
||||
return;
|
||||
}
|
||||
case ERotationAxis::Roll:
|
||||
{
|
||||
Roll += _rotationAmount * _deltaTime;
|
||||
|
||||
if (Roll > 89.9f)
|
||||
{
|
||||
Roll = 89.9f;
|
||||
}
|
||||
else if (Roll < -89.9f)
|
||||
{
|
||||
Roll = -89.9f;
|
||||
}
|
||||
|
||||
break;
|
||||
return;
|
||||
}
|
||||
case ERotationAxis::Yaw:
|
||||
{
|
||||
Yaw += _rotationAmount * _deltaTime;
|
||||
|
||||
break;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
@ -43,6 +43,7 @@ namespace Execution
|
||||
using DGL::GetTime ;
|
||||
using DGL::InitalizeGLEW ;
|
||||
using DGL::InitalizeGLFW ;
|
||||
using DGL::LoadDefaultShaders ;
|
||||
using DGL::KeyPressed ;
|
||||
using DGL::NotShared ;
|
||||
using DGL::PollEvents ;
|
||||
@ -119,6 +120,12 @@ namespace Execution
|
||||
// End of temp stuff...
|
||||
|
||||
|
||||
//sfn PrepareRenderObjects() -> void
|
||||
//{
|
||||
//
|
||||
|
||||
//}
|
||||
|
||||
|
||||
// Currently Does everything required before entering the cycler.
|
||||
sfn PrepWorkspace()
|
||||
@ -144,11 +151,26 @@ namespace Execution
|
||||
|
||||
// End of cursor stuff...
|
||||
|
||||
PrepareRenderObjects();
|
||||
LoadDefaultShaders();
|
||||
|
||||
//PrepareRenderObjects();
|
||||
|
||||
SetPolygonMode(DGL::EFace::Front_and_Back, DGL::ERenderMode::Fill);
|
||||
}
|
||||
|
||||
RAW_MakeCube();
|
||||
|
||||
RAW_MakeLightVAO();
|
||||
|
||||
ProperCube::Setup();
|
||||
|
||||
|
||||
// TODO: Clean THIS
|
||||
|
||||
// Enable depth test
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
// Accept fragment if it closer to the camera than the former one
|
||||
glDepthFunc(GL_LESS);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@ -219,7 +241,22 @@ namespace Execution
|
||||
return;
|
||||
}
|
||||
|
||||
sfn ModCamSpeed(bool _isPositive)
|
||||
{
|
||||
if (_isPositive)
|
||||
{
|
||||
CamMoveSpeed++;
|
||||
}
|
||||
else
|
||||
{
|
||||
CamMoveSpeed--;
|
||||
}
|
||||
}
|
||||
|
||||
deduce ModCamSpeedDelegate = Delegate<decltype(ModCamSpeed)>(ModCamSpeed);
|
||||
|
||||
|
||||
deduce SetPolyModeDelegate = Delegate<decltype(SetPolygonMode)>(SetPolygonMode);
|
||||
|
||||
sfn InputProcedure(ptr<Window> _currentWindowContext)
|
||||
{
|
||||
@ -239,6 +276,26 @@ namespace Execution
|
||||
}
|
||||
}
|
||||
|
||||
if (KeyPressed(_currentWindowContext, EKeyCodes::UpArrow))
|
||||
{
|
||||
ActionsToComplete.AddToQueue(ModCamSpeedDelegate, true);
|
||||
}
|
||||
|
||||
if (KeysPressed(_currentWindowContext, EKeyCodes::DnArrow))
|
||||
{
|
||||
ActionsToComplete.AddToQueue(ModCamSpeedDelegate, false);
|
||||
}
|
||||
|
||||
if (KeyPressed(_currentWindowContext, EKeyCodes::F2))
|
||||
{
|
||||
ActionsToComplete.AddToQueue(SetPolyModeDelegate, DGL::EFace::Front_and_Back, DGL::ERenderMode::Line);
|
||||
}
|
||||
|
||||
if (KeyPressed(_currentWindowContext, EKeyCodes::F3))
|
||||
{
|
||||
ActionsToComplete.AddToQueue(SetPolyModeDelegate, DGL::EFace::Front_and_Back, DGL::ERenderMode::Fill);
|
||||
}
|
||||
|
||||
if (CursorX != 0)
|
||||
{
|
||||
ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Yaw, CursorX * CamMoveSpeed, PhysicsDelta);
|
||||
@ -280,8 +337,6 @@ namespace Execution
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
sfn PhysicsProcedure()
|
||||
{
|
||||
WorldCamera.UpdateCamera();
|
||||
@ -289,21 +344,33 @@ namespace Execution
|
||||
UpdateScreenspace();
|
||||
|
||||
DGL::SS_Transformed::UpdateShader(Screenspace);
|
||||
}
|
||||
|
||||
|
||||
//RAW_RotateLitCube(PhysicsDelta);
|
||||
|
||||
ProperCube::Rotate();
|
||||
}
|
||||
|
||||
sfn RenderProcedure() -> void
|
||||
{
|
||||
EnableVertexAttributeArray(VertexAttributeIndex);
|
||||
|
||||
UseProgramShader(DGL::SS_Transformed::Shader);
|
||||
EnableVertexAttributeArray(1);
|
||||
//UseProgramShader(DGL::SS_Transformed::Shader);
|
||||
|
||||
BindVertexArray(VertexArrayObj);
|
||||
//BindVertexArray(VertexArrayObj);
|
||||
|
||||
DrawElements(EPrimitives::Triangles, 6, EDataType::UnsignedInt, ZeroOffset());
|
||||
//DrawElements(EPrimitives::Triangles, 6, EDataType::UnsignedInt, ZeroOffset());
|
||||
|
||||
RAW_RenderLight(WorldCamera.Perspective, WorldCamera.Viewport);
|
||||
|
||||
|
||||
//RAW_RenderLitCube(WorldCamera.Perspective, WorldCamera.Viewport);
|
||||
|
||||
ProperCube::Render(WorldCamera.Perspective, WorldCamera.Viewport);
|
||||
|
||||
DisableVertexAttributeArray(VertexAttributeIndex);
|
||||
|
||||
DisableVertexAttributeArray(1);
|
||||
}
|
||||
|
||||
|
||||
|
34
PhongShader.frag
Normal file
34
PhongShader.frag
Normal file
@ -0,0 +1,34 @@
|
||||
#version 330 core
|
||||
|
||||
out vec4 FragColor;
|
||||
|
||||
|
||||
//in vec3 FragPosition;
|
||||
//in vec3 Normal ;
|
||||
|
||||
|
||||
|
||||
uniform vec3 ObjectColor;
|
||||
|
||||
|
||||
//uniform vec3 LightPosition;
|
||||
uniform vec3 LightColor ;
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
float AmbientStrength = 0.1;
|
||||
|
||||
vec3 ambient = AmbientStrength * LightColor ;
|
||||
|
||||
// vec3 Direction = normalize(Normal );
|
||||
// vec3 LightDirection = normalize(LightPosition - FragPosition);
|
||||
//
|
||||
// float DiffuseStrength = max(dot(Normal, LightDirection), 0.0);
|
||||
// vec3 diffuse = DiffuseStrength * LightColor ;
|
||||
|
||||
vec3 result = (ambient ) * ObjectColor;
|
||||
|
||||
FragColor = vec4(result, 1.0);
|
||||
}
|
26
PhongShader.vert
Normal file
26
PhongShader.vert
Normal file
@ -0,0 +1,26 @@
|
||||
#version 330 core
|
||||
|
||||
layout (location = 0) in vec3 VertPosition;
|
||||
//layout (location = 1) in vec3 VertNormal ;
|
||||
|
||||
|
||||
|
||||
//out vec3 FragPosition;
|
||||
//out vec3 Normal ;
|
||||
|
||||
|
||||
|
||||
uniform mat4 ModelScreenSpace ;
|
||||
uniform mat4 ModelSpace ;
|
||||
uniform mat4 InverseModelSpace;
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = ModelScreenSpace * vec4(VertPosition, 1.0);
|
||||
|
||||
// FragPosition = vec3(ModelSpace * vec4(VertPosition, 1.0));
|
||||
|
||||
// Normal = mat3(transpose(InverseModelSpace));
|
||||
}
|
@ -1,15 +1,13 @@
|
||||
#version 330 core
|
||||
layout (location = 0) in vec3 aPos;
|
||||
|
||||
// uniform mat4 model;
|
||||
// uniform mat4 view;
|
||||
// uniform mat4 projection;
|
||||
|
||||
|
||||
uniform mat4 ScreenSpaceTransform;
|
||||
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
//gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||
|
||||
gl_Position = ScreenSpaceTransform * vec4(aPos, 1.0);
|
||||
}
|
324
Testing.hpp
324
Testing.hpp
@ -7,20 +7,71 @@
|
||||
|
||||
|
||||
using DGL::gFloat;
|
||||
using DGL::VertexBuffer;
|
||||
using DGL::VertexArray;
|
||||
using DGL::EBufferTarget;
|
||||
using DGL::EBufferUsage;
|
||||
using DGL::Buffer;
|
||||
using DGL::VertexBuffer;
|
||||
using DGL::ID;
|
||||
using DGL::gInt;
|
||||
using DGL::gSize;
|
||||
using DGL::LinearColor;
|
||||
using DGL::Vector3;
|
||||
using DGL::ZeroOffset;
|
||||
|
||||
|
||||
float vertices[] = {
|
||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
|
||||
|
||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
|
||||
|
||||
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
|
||||
-0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
|
||||
-0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
|
||||
-0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
|
||||
-0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
|
||||
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
|
||||
|
||||
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
|
||||
0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
|
||||
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
|
||||
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
|
||||
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
|
||||
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
|
||||
|
||||
-0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
|
||||
0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
|
||||
0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
|
||||
0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
|
||||
-0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
|
||||
-0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
|
||||
|
||||
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
|
||||
0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
|
||||
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
|
||||
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
|
||||
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
|
||||
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
//DGL::DefaultSpace::WorldSpace = DGL::Rotate(DGL::DefaultSpace::WorldSpace, 0.015f, Vector3(0.0f, 1.0f, 0.0f));
|
||||
|
||||
// This will identify our vertex buffer
|
||||
ID<Buffer> VertexBufferObj;
|
||||
ID<VertexBuffer> VertexBufferObj;
|
||||
|
||||
|
||||
|
||||
struct Vertex3
|
||||
{
|
||||
@ -67,7 +118,7 @@ RectangleRaw SquareVerticies =
|
||||
}
|
||||
};
|
||||
|
||||
ID<VertexBuffer> VertexArrayObj;
|
||||
ID<VertexArray> VertexArrayObj;
|
||||
|
||||
struct RectangleCompressed
|
||||
{
|
||||
@ -156,10 +207,7 @@ DGL::gInt VertexAttributeIndex = 0; // See shader source: (layout = 0).
|
||||
using DGL::EBool;
|
||||
using DGL::EDataType;
|
||||
|
||||
constexpr sfn ZeroOffset() -> ptr<void>
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// Testing
|
||||
|
||||
@ -189,24 +237,268 @@ sfn CreateWindow_TimedRender()
|
||||
|
||||
DGL::InitalizeGLEW();
|
||||
|
||||
PrepareRenderObjects();
|
||||
//PrepareRenderObjects();
|
||||
|
||||
//DGL::RunBasicWindowLoop_Timed(windowObj, 1.0 / 60.0, Address(RenderProcedure));
|
||||
}
|
||||
|
||||
sfn PrepareRenderObjects() -> void
|
||||
|
||||
|
||||
struct Edge3
|
||||
{
|
||||
RAW_SetupBuffers();
|
||||
TriIndex a, b;
|
||||
};
|
||||
|
||||
RAW_BindAndBufferDataToIDs();
|
||||
struct VertPhong
|
||||
{
|
||||
Vertex3 locationPad,
|
||||
normalPad ;
|
||||
};
|
||||
|
||||
DGL::LoadDefaultShaders();
|
||||
struct CubeVerts
|
||||
{
|
||||
Vertex3
|
||||
f1, f2, f3, f4, // Front
|
||||
b1, b2, b3, b4; // Back
|
||||
};
|
||||
|
||||
DGL::FormatVertexAttributes<Vertex3>(VertexAttributeIndex, EDataType::Float, ZeroOffset(), Vertex3::ValueCount(), EBool::False);
|
||||
struct CubeElements
|
||||
{
|
||||
Edge3 front, right, back, left, bottom, top;
|
||||
};
|
||||
|
||||
DGL::BindBuffer(EBufferTarget::VertexAttributes, 0); // Dunno. Prob unbinding...
|
||||
CubeVerts DefaultCube =
|
||||
{
|
||||
// Front
|
||||
{-1.0f, -1.0f, 1.0f},
|
||||
{ 1.0f, -1.0f, 1.0f},
|
||||
{ 1.0f, 1.0f, 1.0f},
|
||||
{-1.0f, 1.0f, 1.0f},
|
||||
|
||||
DGL::BindVertexArray(0);
|
||||
// Back
|
||||
{-1.0f, -1.0f, -1.0f},
|
||||
{ 1.0f, -1.0f, -1.0f},
|
||||
{ 1.0f, 1.0f, -1.0f},
|
||||
{-1.0f, 1.0f, -1.0f}
|
||||
};
|
||||
|
||||
CubeElements DefaultCubeElements =
|
||||
{
|
||||
// Front
|
||||
{ { 0, 1, 2 }, { 2, 3, 0 } },
|
||||
|
||||
// Right
|
||||
{ { 1, 5, 6 }, { 6, 2, 1 } },
|
||||
|
||||
// Back
|
||||
{ { 7, 6, 5 }, { 5, 4, 7 } },
|
||||
|
||||
// Left
|
||||
{ { 4, 0, 3 }, { 3, 7, 4 } },
|
||||
|
||||
// Bottom
|
||||
{ { 4, 5, 1 }, { 1, 0, 4 } },
|
||||
|
||||
// Top
|
||||
{ { 3, 2, 6 }, { 6, 7, 3 } }
|
||||
};
|
||||
|
||||
|
||||
using DGL::CoordSpace;
|
||||
using DGL::Matrix4x4;
|
||||
using DGL::Model;
|
||||
|
||||
ID<VertexArray> CubeVAO;
|
||||
ID<VertexBuffer > CubeModelBuffer ;
|
||||
ID<ElementBuffer> CubeModelElements;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
sfn RAW_MakeCube()
|
||||
{
|
||||
DGL::GenerateVertexBuffers(Address(CubeVAO ), 1);
|
||||
DGL::GenerateBuffers (Address(CubeModelBuffer ), 1);
|
||||
DGL::GenerateBuffers (Address(CubeModelElements), 1);
|
||||
|
||||
DGL::BindVertexArray(CubeVAO);
|
||||
|
||||
|
||||
DGL::BindBuffer(EBufferTarget::VertexAttributes, CubeModelBuffer);
|
||||
|
||||
DGL::BufferData<CubeVerts>(Address(DefaultCube), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
|
||||
|
||||
|
||||
DGL::BindBuffer(EBufferTarget::VertexIndices, CubeModelElements);
|
||||
|
||||
DGL::BufferData<CubeElements>(Address(DefaultCubeElements), EBufferTarget::VertexIndices, EBufferUsage::StaticDraw);
|
||||
|
||||
|
||||
|
||||
DGL::FormatVertexAttributes<Vertex3>(0, EDataType::Float, ZeroOffset(), Vertex3::ValueCount(), EBool::False);
|
||||
|
||||
DGL::EnableVertexAttributeArray(0);
|
||||
|
||||
//DGL::FormatVertexAttributes<VertPhong>(1, EDataType::Float, Offset(Vertex3::ValueCount()), Vertex3::ValueCount(), EBool::False);
|
||||
|
||||
//DGL::EnableVertexAttributeArray(1);
|
||||
|
||||
/*glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
|
||||
glEnableVertexAttribArray(0);*/
|
||||
|
||||
/*glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)(3 * sizeof(float)));
|
||||
glEnableVertexAttribArray(1);*/
|
||||
|
||||
|
||||
//DGL::BindBuffer(EBufferTarget::VertexAttributes, 0); // Dunno. Prob unbinding...
|
||||
}
|
||||
|
||||
sfn RAW_RenderCube()
|
||||
{
|
||||
DGL::BindBuffer(EBufferTarget::VertexIndices, CubeModelElements);
|
||||
|
||||
gInt Size; GetBufferParameterIV(EBufferTarget::VertexIndices, DGL::EBufferParam::Size, Address(Size));
|
||||
|
||||
Size /= sizeof(unsigned int);
|
||||
|
||||
DGL::DrawElements(DGL::EPrimitives::Triangles, Size, EDataType::UnsignedInt, ZeroOffset());
|
||||
}
|
||||
|
||||
|
||||
LinearColor CoralColor(1.0f, 0.5f, 0.31f, 1.0f);
|
||||
LinearColor LightColor(1.0f, 1.0f, 1.0f , 1.0f);
|
||||
|
||||
Vector3 LightPosition(1.2f, 1.0f, 2.0f);
|
||||
|
||||
Vector3 LightScale = Vector3(0.2f);
|
||||
|
||||
Vector3 result = LightColor.Vector() * CoralColor.Vector();
|
||||
|
||||
CoordSpace LightTransform = Matrix4x4(1.0f);
|
||||
|
||||
ID<VertexArray> LightVAO;
|
||||
|
||||
sfn RAW_MakeLightVAO()
|
||||
{
|
||||
DGL::GenerateVertexBuffers(Address(LightVAO), 1);
|
||||
|
||||
DGL::BindVertexArray(LightVAO);
|
||||
|
||||
DGL::BindBuffer(EBufferTarget::VertexAttributes, CubeModelBuffer );
|
||||
DGL::BindBuffer(EBufferTarget::VertexIndices , CubeModelElements);
|
||||
|
||||
DGL::FormatVertexAttributes<Vertex3>(0, EDataType::Float, ZeroOffset(), Vertex3::ValueCount(), EBool::False);
|
||||
|
||||
DGL::EnableVertexAttributeArray(0);
|
||||
|
||||
LightTransform = DGL::Translate(LightTransform, LightPosition);
|
||||
LightTransform = DGL::Scale (LightTransform, LightScale );
|
||||
}
|
||||
|
||||
|
||||
using DGL::GetBufferParameterIV;
|
||||
|
||||
sfn RAW_RenderLight(CoordSpace _projection, CoordSpace _viewport)
|
||||
{
|
||||
deduce screenspaceTransform = _projection * _viewport * LightTransform;
|
||||
|
||||
DGL::Basic_LampShader::SetupLampRender(screenspaceTransform);
|
||||
|
||||
DGL::BindVertexArray(LightVAO);
|
||||
|
||||
RAW_RenderCube();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Vector3 LitCubePosition = Vector3(0.0f);
|
||||
|
||||
Vector3 CubeColor = CoralColor.Vector();
|
||||
|
||||
CoordSpace LitCubeTransform = Matrix4x4(1.0f);
|
||||
|
||||
gFloat RotationRate = 0.015f;
|
||||
|
||||
ID<VertexArray> LitCubeVAO;
|
||||
|
||||
sfn RAW_MakeLitCube()
|
||||
{
|
||||
DGL::GenerateVertexBuffers(Address(LitCubeVAO), 1);
|
||||
|
||||
DGL::BindVertexArray(LitCubeVAO);
|
||||
|
||||
DGL::BindBuffer(EBufferTarget::VertexAttributes, CubeModelBuffer );
|
||||
DGL::BindBuffer(EBufferTarget::VertexIndices , CubeModelElements);
|
||||
|
||||
DGL::FormatVertexAttributes<Vertex3>(0, EDataType::Float, ZeroOffset(), Vertex3::ValueCount(), EBool::False);
|
||||
|
||||
DGL::EnableVertexAttributeArray(0);
|
||||
}
|
||||
|
||||
sfn RAW_RotateLitCube(gFloat _delta)
|
||||
{
|
||||
LitCubeTransform = DGL::Rotate(LitCubeTransform, RotationRate * _delta, Vector3(0.0f, 1.0f, 0.0f));
|
||||
}
|
||||
|
||||
sfn RAW_RenderLitCube(CoordSpace _projection, CoordSpace _viewport)
|
||||
{
|
||||
CoordSpace screenspaceTransform = _projection * _viewport * LitCubeTransform;
|
||||
|
||||
Vector3 lightColor = LightColor.Vector();
|
||||
|
||||
DGL::PhongShader::SetupRender(screenspaceTransform, LitCubeTransform, CubeColor, LightPosition, lightColor);
|
||||
|
||||
DGL::BindVertexArray(LitCubeVAO);
|
||||
|
||||
RAW_RenderCube();
|
||||
}
|
||||
|
||||
|
||||
|
||||
namespace ProperCube
|
||||
{
|
||||
Model model("cube.obj");
|
||||
|
||||
Vector3 position = Vector3(0.0f);
|
||||
|
||||
Vector3 color = CoralColor.Vector();
|
||||
|
||||
CoordSpace transform = Matrix4x4(1.0f);
|
||||
|
||||
sfn Rotate()
|
||||
{
|
||||
transform = DGL::Rotate(transform, 0.035f, Vector3(0, 1, 0));
|
||||
}
|
||||
|
||||
sfn Render(Ref(CoordSpace) _projection, Ref(CoordSpace) _viewport)
|
||||
{
|
||||
CoordSpace screenspaceTransform = _projection * _viewport * transform;
|
||||
|
||||
Vector3 lightColor = LightColor.Vector();
|
||||
|
||||
//DGL::PhongShader::SetupRender(screenspaceTransform, transform, color, LightPosition, lightColor);
|
||||
|
||||
DGL::Basic_LightingShader::SetupRender(screenspaceTransform, color, lightColor);
|
||||
|
||||
model.Render();
|
||||
}
|
||||
|
||||
sfn Setup()
|
||||
{
|
||||
model.Load();
|
||||
|
||||
//model.GenVN();
|
||||
|
||||
model.Buffer();
|
||||
|
||||
//transform = DGL::Scale(transform, Vector3(0.01));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
38
cube.obj
Normal file
38
cube.obj
Normal file
@ -0,0 +1,38 @@
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
mtllib cube.mtl
|
||||
|
||||
|
||||
#
|
||||
# cube Mesh
|
||||
#
|
||||
g cube Mesh
|
||||
|
||||
v 0.022541 0.000000 0.000000
|
||||
v 1.022541 1.000000 0.000000
|
||||
v 1.022541 0.000000 0.000000
|
||||
v 0.022541 1.000000 0.000000
|
||||
v 0.022541 1.000000 1.000000
|
||||
v 0.022541 0.000000 1.000000
|
||||
v 1.022541 1.000000 1.000000
|
||||
v 1.022541 0.000000 1.000000
|
||||
vn 0.000000 0.000000 -1.000000
|
||||
vn -1.000000 0.000000 0.000000
|
||||
vn 0.000000 1.000000 0.000000
|
||||
vn 1.000000 0.000000 0.000000
|
||||
vn 0.000000 -1.000000 0.000000
|
||||
vn 0.000000 0.000000 1.000000
|
||||
f 1//1 2//1 3//1
|
||||
f 1//1 4//1 2//1
|
||||
f 1//2 5//2 4//2
|
||||
f 1//2 6//2 5//2
|
||||
f 4//3 7//3 2//3
|
||||
f 4//3 5//3 7//3
|
||||
f 3//4 2//4 7//4
|
||||
f 3//4 7//4 8//4
|
||||
f 1//5 3//5 8//5
|
||||
f 1//5 8//5 6//5
|
||||
f 6//6 8//6 7//6
|
||||
f 6//6 7//6 5//6
|
76166
sculpture.obj
Normal file
76166
sculpture.obj
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user