Started removing the excess adhesive... still a bit more to go...

This commit is contained in:
Edward R. Gonzalez 2020-02-21 01:18:07 -05:00
parent d4bfec3944
commit 6d7750ebfb
15 changed files with 1436 additions and 902 deletions

View File

@ -38,7 +38,7 @@ namespace Actions
using ActionType = Delegate< FunctionType >;
public:
AAction(ActionType _actionToAssign, ActionParams... _params) :
AAction(ro Ref(ActionType) _actionToAssign, ro Ref(ActionParams)... _params) :
action(_actionToAssign),
params(_params... ),
done (false )
@ -49,7 +49,7 @@ namespace Actions
return done;
}
sfn IsSame(ActionParams... _paramsForAction) -> bool
sfn IsSame(ro Ref(ActionParams)... _paramsForAction) -> bool
{
Tuple<ActionParams...> paramsToCheck(_paramsForAction...);
@ -63,7 +63,7 @@ namespace Actions
}
}
sfn ReInitalize(ActionParams... _params)
sfn ReInitalize(ro Ref(ActionParams)... _params)
{
params = Tuple<ActionParams...> (_params...);
@ -71,10 +71,10 @@ namespace Actions
}
private:
sfn DoAction_Implementation(ActionParams... _params) { action(_params...); }
sfn DoAction_Implementation(ro Ref(ActionParams)... _params) { action(_params...); }
template<IndexType... TuplePackIndex> // TuplePackSequence<TuplePackIndex...>
sfn ExpandTuple_CallDoActionImplementaiton(const Ref(Tuple<ActionParams...>) _paramsToExpand, std::index_sequence <TuplePackIndex...>)
template<IndexType... TuplePackIndex> // TuplePackSequence<TuplePackIndex...>
sfn ExpandTuple_CallDoActionImplementaiton(ro Ref(Tuple<ActionParams...>) _paramsToExpand, std::index_sequence <TuplePackIndex...>)
{
// ExpandTuplePack<TuplePackIndex>
DoAction_Implementation(std::get<TuplePackIndex>(_paramsToExpand)...);
@ -112,11 +112,6 @@ namespace Actions
using AActions_Registry = std::map <TypeIndex , Managed_AActions>;
public:
template<typename Entry>
sfn Available(Ref(Entry) _entry) -> bool
{
return _entry != aActions_Available.end() ? true : false;
}
template<typename Entry>
sfn Contains(Ref(Entry) _entry) -> bool
@ -132,7 +127,7 @@ namespace Actions
}
template<typename FunctionType, typename... ActionParams>
sfn Request_AAction(Delegate< FunctionType> _actionToQueue, ActionParams... _paramsForAction) -> ptr<IAction>
sfn Request_AAction(ro Ref(Delegate< FunctionType>) _actionToQueue, ro Ref(ActionParams)... _paramsForAction) -> ptr<IAction>
{
using ActionType = AAction < FunctionType, ActionParams...>;
@ -196,7 +191,7 @@ namespace Actions
public:
template<typename FunctionType, typename... ActionParams>
sfn AddToQueue(Delegate< FunctionType> _actionToQueue, ActionParams... _paramsForAction)
sfn AddToQueue(ro Ref(Delegate< FunctionType>) _actionToQueue, ro Ref(ActionParams)... _paramsForAction)
{
using GeneratedActionType = AAction<FunctionType, ActionParams...>;

View File

@ -44,8 +44,11 @@ auto
#define deduce \
auto
#define Ref(_type) \
_type&
#define ro \
const
#define Ref(...) \
__VA_ARGS__&
#define rRef(_type) \
_type&&
@ -68,18 +71,21 @@ using ptr = Type*;
template<typename ReturnType, typename... ParamTypes>
using FnPtr = ReturnType(*)(ParamTypes...);
template<typename Type>
using SPtr = std::shared_ptr<Type>;
template<typename Type>
using UPtr = std::unique_ptr<Type>;
// Delegating
template<typename FnType>
using Delegate = std::function<FnType>;
template<typename ReturnType, typename... ParamTypes>
using Func = ReturnType(ParamTypes...);
template<typename Type>
using UPtr = std::unique_ptr<Type>;
template<typename Type>
using SPtr = std::shared_ptr<Type>;
// Strings
@ -90,9 +96,14 @@ using RawString = ptr<CharType>;
using std::cout;
using std::endl;
using DataSize = std::size_t;
using Thread = std::thread;
using std::ifstream ;
using std::ios ;
using std::string ;
using std::stringstream;
using DataSize = std::size_t;
using Thread = std::thread;
template<typename... ObjectTypes>
using Tuple = std::tuple<ObjectTypes...>;
@ -120,7 +131,7 @@ sfn Address(Ref(Type) _instance) -> ptr<Type>
}
template<typename Type>
sfn Dref(ptr<Type> _type) -> Ref(Type)
sfn Dref(ro ptr<Type> _type) -> Ref(Type)
{
return *_type;
}
@ -141,14 +152,14 @@ sfn MakeSPtr(rRef(ParamTypes)... _params) -> SPtr<Type>
// Exit
sfn Exit(ExitCode _code)
sfn Exit(ro ExitCode _code)
{
exit(int(_code));
}
// Error Stuff
sfn ErrorRuntime(const Ref(std::runtime_error) _error)
sfn ErrorRuntime(ro Ref(std::runtime_error) _error)
{
std::cout << "Runtime error occurred: " << _error.what() << std::endl;

325
DGL.hpp
View File

@ -1,331 +1,10 @@
#pragma once
// GLFW, GLEW, GLM
#include <glew.h >
#include <glfw3.h >
#include <glm/glm.hpp >
#include <glm/gtc/matrix_transform.hpp>
// DGL
#include "DGL_FundamentalTypes.hpp"
#include "DGL_MiscTypes.hpp"
#include "DGL_Types.hpp"
#include "DGL_Enum.hpp"
#include "DGL_Shader.hpp"
#include "DGL_Buffers.hpp"
#include "DGL_Space.hpp"
#include "DGL_Model.hpp"
// Non-Standard C++
#include "Cpp_Alias.hpp"
namespace DGL
{
// Aliases
// C++ STL
using std::cout;
using std::endl;
// GLFW
using Monitor = GLFWmonitor;
using TimeValInt = uint64_t;
using TimeValDec = double;
using Window = GLFWwindow;
using WindowRefList = std::vector< ptr<Window> >;
// Object Instances
WindowRefList Windows;
// Constants
sfn constexpr NotShared () -> ptr<Window > { return NULL; }
sfn constexpr WindowedMode() -> ptr<Monitor> { return NULL; }
// Forward Declares
sfn SwapBuffers(const ptr<Window> _window) -> void;
// Functionality
sfn CanClose(const ptr<Window> _theWindow)
{
return glfwWindowShouldClose(_theWindow);
}
sfn CanUseRawMouse()
{
return glfwRawMouseMotionSupported();
}
sfn CreateWindow
(
int _width,
int _height,
RawString<const char> _title,
ptr <Monitor > _monitorToFullscreen,
ptr <Window > _windowToShareResourcesWith
)
-> ptr<Window>
{
Windows.push_back(glfwCreateWindow(_width, _height, _title, _monitorToFullscreen, _windowToShareResourcesWith));
try
{
if (Windows.back() == NULL)
{
throw std::runtime_error("Failed to create a window");
}
}
catch (std::runtime_error _error)
{
ErrorRuntime(_error);
Exit(ExitCode::Failed);
}
return Windows.back();
}
sfn CursorPositionUpdateBind(ptr<Window> _window, FnPtr<void, double, double> _functionToCall)
{
glfwSetCursorPosCallback(_window, GLFWcursorposfun(_functionToCall));
}
sfn DestoryWindow(const ptr<Window> _window)
{
using ElementType = decltype(Windows.begin());
for (ElementType element = Windows.begin(); element != Windows.end(); element++)
{
if (*element == _window)
{
glfwDestroyWindow(_window);
Windows.erase(element);
}
}
return;
}
sfn GetCursorPosition(ptr<Window> _window, ptr<double> _xAxis, ptr<double> _yAxis)
{
glfwGetCursorPos(_window, _xAxis, _yAxis);
}
sfn GetMouseInputMode(ptr<Window> _contextWindowRef, EMouseMode _mode)
{
return glfwGetInputMode(_contextWindowRef, GLenum(_mode));
}
sfn GetRawTime() -> TimeValInt
{
return glfwGetTimerValue();
}
sfn GetTime() -> TimeValDec
{
return glfwGetTime();
}
sfn InitalizeGLFW()
{
try
{
std::cout << "Initializing GLFW Version: " << glfwGetVersionString() << std::endl;
/* Initialize the library */
if (!glfwInit())
{
throw std::runtime_error("Failed to initialize GLFW");
}
}
catch (const std::runtime_error _error)
{
ErrorRuntime(_error);
Exit(ExitCode::Failed);
}
return;
}
sfn InitalizeGLEW()
{
try
{
// If using GLEW version 1.13 or earlier
//glewExperimental = true;
std::cout << "Initializing Glew Version: " << glewGetString(GLEW_VERSION) << std::endl;
GLenum err = glewInit();
if (err != GLEW_OK)
{
// Problem: glewInit failed, something is seriously wrong.
std::cout << "glewInit failed: " << glewGetErrorString(err) << std::endl;
throw std::runtime_error("Failed to initialize GLFW");
}
cout << "OpenGL Version: " << glGetString(GL_VERSION) << endl;
}
catch (const std::runtime_error _error)
{
ErrorRuntime(_error);
Exit(ExitCode::Failed);
}
}
sfn KeyPressed(ptr<Window> _contextWindowRef, EKeyCodes _keyToCheck) -> bool
{
return glfwGetKey(_contextWindowRef, int(_keyToCheck));
}
template<typename... CodeType, typename = EKeyCodes>
sfn KeysPressed(ptr<Window> _contextWindowRef, CodeType... _otherKeys) -> bool
{
return (KeyPressed(_contextWindowRef, _otherKeys) && ...) == true;
}
sfn PollEvents()
{
glfwPollEvents();
return;
}
sfn ResetCursor(ptr<Window> _window, gFloat _screenCenterWidth, gFloat _screenCenterHeight)
{
glfwSetCursorPos(_window, _screenCenterWidth, _screenCenterHeight);
glfwSetCursorPos(_window, 0, 0);
}
sfn RunBasicWindowLoop(const ptr<Window> _window)
{
/* Loop until the user closes the window */
while (not CanClose(_window))
{
ClearBuffer(EFrameBuffer::Color);
SwapBuffers(_window);
PollEvents();
}
return;
}
sfn RunBasicWindowLoop_Timed(const ptr<Window> _window, TimeValDec _interval, Delegate< Func<void>> _renderProcedure)
{
TimeValDec start, end, deltaSinceClear = 0.0;
while (not CanClose(_window))
{
start = GetTime();
if (deltaSinceClear > _interval)
{
ClearBuffer(EFrameBuffer::Color, EFrameBuffer::Depth);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.25f, 0.25f, 0.25f, 1.0f);
//glMatrixMode(GL_MODELVIEW);
//glLoadIdentity();
_renderProcedure();
SwapBuffers(_window);
PollEvents();
}
end = GetTime();
deltaSinceClear = deltaSinceClear + end - start;
}
return;
}
sfn SetClearColor(LinearColor _colorToSet)
{
glClearColor(_colorToSet.Red, _colorToSet.Green, _colorToSet.Blue, _colorToSet.Alpha);
}
sfn SetCurrentContext(const ptr<Window> _window)
{
try
{
glfwMakeContextCurrent(_window);
ptr< RawString<const char> > ErrorMsg = NULL;
int code = glfwGetError(ErrorMsg);
if (code == GLFW_NO_WINDOW_CONTEXT)
{
throw std::runtime_error( Dref(ErrorMsg) );
}
}
catch (const std::runtime_error _error)
{
ErrorRuntime(_error);
Exit(ExitCode::Failed);
}
return;
}
template<typename ModeParam>
sfn SetInputMode(ptr<Window> _window, EMouseMode _mouseMode, ModeParam _modeParam)
{
glfwSetInputMode(_window, GLenum(_mouseMode), GLenum(_modeParam));
}
sfn SetPolygonMode(EFace _desiredFaces, ERenderMode _desiredMode)
{
glPolygonMode(GLenum(_desiredFaces), GLenum(_desiredMode));
}
sfn SwapBuffers(const ptr<Window> _window) -> void
{
glfwSwapBuffers(_window);
return;
}
sfn TerminateGLFW()
{
glfwTerminate();
return;
}
// RawTape
}
#include "DGL_Entity.hpp"

View File

@ -4,9 +4,8 @@
#include <glew.h>
// DGL
#include "DGL_FundamentalTypes.hpp"
#include "DGL_MiscTypes.hpp"
#include "DGL_Enum.hpp"
#include "DGL_Types.hpp"
// Non-Standard C++
#include "Cpp_Alias.hpp"
@ -15,14 +14,14 @@
namespace DGL
{
sfn BindBuffer(const EBufferTarget _targetType, const ID<VertexBuffer> _buffer)
sfn BindBuffer(EBufferTarget _targetType, ID<VertexBuffer> _buffer)
{
glBindBuffer(GLenum(_targetType), _buffer);
return;
}
sfn BindVertexArray(const gUInt _referenceToTrackArray)
sfn BindVertexArray(gUInt _referenceToTrackArray)
{
glBindVertexArray(_referenceToTrackArray);
@ -30,27 +29,28 @@ namespace DGL
}
template<typename TypeOfData>
sfn BufferData(ptr<TypeOfData> _data, const EBufferTarget _targetType, const EBufferUsage _usageType)
sfn BufferData(ro Ref(TypeOfData) _data, EBufferTarget _targetType, EBufferUsage _usageType)
{
glBufferData(GLenum(_targetType), sizeof(TypeOfData), _data, GLenum(_usageType));
glBufferData(GLenum(_targetType), sizeof(TypeOfData), Address(_data), GLenum(_usageType));
return;
}
sfn BufferData(DataPtr _data, gSize _sizeOfData, const EBufferTarget _targetType, const EBufferUsage _usageType)
template<typename Type>
sfn BufferData(ro Ref(Type) _data, gSize _sizeOfData, EBufferTarget _targetType, EBufferUsage _usageType)
{
glBufferData(GLenum(_targetType), _sizeOfData, _data, GLenum(_usageType));
glBufferData(GLenum(_targetType), _sizeOfData, Address(_data), GLenum(_usageType));
}
template<typename... Type, typename = EFrameBuffer>
sfn ClearBuffer(const Type... _buffersToClear)
sfn ClearBuffer(Type... _buffersToClear)
{
glClear((gBitfield(_buffersToClear) | ...));
glClear( (gBitfield(_buffersToClear) | ...) );
return;
}
sfn DisableVertexAttributeArray(const gInt _vertexAttributeArrayIndex)
sfn DisableVertexAttributeArray(gInt _vertexAttributeArrayIndex)
{
glDisableVertexAttribArray(_vertexAttributeArrayIndex);
}
@ -60,12 +60,12 @@ namespace DGL
glDrawArrays(GLenum(_primitive), _startingIndex, _numToRender); // Starting from vertex 0; 3 vertices total -> 1 triangle.
}
sfn DrawElements(EPrimitives _primitive, gSize _numElements, EDataType _dataType, DataPtr _offfsetAddressFromFirstIndex)
sfn DrawElements(EPrimitives _primitive, gSize _numElements, EDataType _dataType, ro DataPtr _offfsetAddressFromFirstIndex)
{
glDrawElements(GLenum(_primitive), _numElements, GLenum(_dataType), _offfsetAddressFromFirstIndex);
}
sfn EnableVertexAttributeArray(const gInt _vertexAttributeArrayIndex)
sfn EnableVertexAttributeArray(gInt _vertexAttributeArrayIndex)
{
glEnableVertexAttribArray(_vertexAttributeArrayIndex);
}
@ -73,11 +73,11 @@ namespace DGL
template<typename VertType>
sfn FormatVertexAttributes
(
gUInt _attributeIndex ,
EDataType _vertexComponenetType ,
ptr<void> _firstVertexComponentLocation,
gInt _numberOfVertexComponents ,
EBool _shouldNormalize
gUInt _attributeIndex ,
EDataType _vertexComponenetType ,
ro ptr<void> _firstVertexComponentLocation,
gInt _numberOfVertexComponents ,
gBoolean _shouldNormalize
)
{
glVertexAttribPointer
@ -85,30 +85,47 @@ namespace DGL
_attributeIndex ,
_numberOfVertexComponents ,
GLenum(_vertexComponenetType),
GLenum(_shouldNormalize ),
_shouldNormalize ,
sizeof(VertType ),
_firstVertexComponentLocation
);
}
sfn GenerateBuffers(ptr<gUInt> _bufferReferencer, uInt64 _numberOfBuffersToReserve)
sfn GenerateBuffers(Ref(gUInt) _bufferReferencer, gSize _numberOfBuffersToReserve)
{
glGenBuffers(_numberOfBuffersToReserve, _bufferReferencer);
glGenBuffers(_numberOfBuffersToReserve, Address(_bufferReferencer));
return;
}
sfn GenerateVertexBuffers(ptr<gUInt> __referenceRetainerToBuffer, uInt64 _numOfObjectsToReserveFor)
sfn GenerateVertexBuffers(Ref(gUInt) __referenceRetainerToBuffer, gSize _numOfObjectsToReserveFor)
{
glGenVertexArrays(_numOfObjectsToReserveFor, __referenceRetainerToBuffer);
glGenVertexArrays(_numOfObjectsToReserveFor, Address(__referenceRetainerToBuffer));
return;
}
sfn GetBufferParameterIV(EBufferTarget _target, EBufferParam _param, ptr<gInt> _data)
sfn GetBufferParameterIV(EBufferTarget _target, EBufferParam _param, Ref(gInt) _dataStore)
{
glGetBufferParameteriv(GLenum(_target), GLenum(_param), _data);
glGetBufferParameteriv(GLenum(_target), GLenum(_param), Address(_dataStore));
return;
}
// Used to get an offset from a specified location.
sfn Offset(uInt64 _offsetAmount)
{
return DataPtr(_offsetAmount);
}
sfn UnbindVertexArray()
{
BindVertexArray(0);
}
// Provides an zero offset pointer specifier.
constexpr sfn ZeroOffset() -> ptr<void>
{
return 0;
}
}

233
DGL_Entity.hpp Normal file
View File

@ -0,0 +1,233 @@
#pragma once
// DGL
#include "DGL_Types.hpp"
#include "DGL_Model.hpp"
#include "DGL_Shader.hpp"
#include "DGL_Utilities.hpp"
// Non-Standard C++
#include "Cpp_Alias.hpp"
namespace DGL
{
namespace Colors
{
LinearColor CoralColor(1.0f , 0.5f , 0.31f, 1.0f);
LinearColor GreyColor (0.60f, 0.60f, 0.60f, 1.0f);
LinearColor LightColor(1.0f , 1.0f , 1.0f , 1.0f);
}
class Light_Basic
{
public:
Light_Basic() :
color (Colors::LightColor.Vector()),
position (Vector3 (0.0f) ),
scale (Vector3 (0.2f) ),
transform (CoordSpace(1.0f) ),
translationRadius(4.0f )
{}
sfn GetColor() -> VecColor
{
return color;
}
sfn GetPosition() -> Vector3
{
return position;
}
sfn Load()
{
GenerateVertexBuffers(modelVAO, 1);
GenerateBuffers (modelVBO, 1);
GenerateBuffers (modelEBO, 1);
BindVertexArray(modelVAO);
BindBuffer(EBufferTarget::VertexAttributes, modelVBO);
BufferData<CubeVerts>(DefaultCube, EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
BindBuffer(EBufferTarget::VertexIndices, modelEBO);
BufferData<CubeElements>(DefaultCubeElements, EBufferTarget::VertexIndices, EBufferUsage::StaticDraw);
FormatVertexAttributes<CubeVerts::Vertex3>(0, EDataType::Float, ZeroOffset(), CubeVerts::Vertex3::ValueCount(), false);
UnbindVertexArray();
}
sfn Update()
{
transform = CoordSpace(1.0f);
position.x = translationRadius * sin(GetTime());
position.z = translationRadius * cos(GetTime());
transform = Translate(transform, position);
transform = Scale (transform, scale );
}
sfn Render(ro Ref(CoordSpace) _projection, ro Ref(CoordSpace) _viewport)
{
deduce screenspaceTransform = _projection * _viewport * transform;
Basic_LampShader::Use(screenspaceTransform);
BindVertexArray(modelVAO);
BindBuffer(EBufferTarget::VertexIndices, modelEBO);
gInt SizeRef; GetBufferParameterIV(EBufferTarget::VertexIndices, DGL::EBufferParam::Size, SizeRef); SizeRef /= sizeof(unsigned int);
DrawElements(EPrimitives::Triangles, SizeRef, EDataType::UnsignedInt, ZeroOffset());
Basic_LampShader::Stop();
}
private:
VecColor color ;
Vector3 position ;
Vector3 scale ;
CoordSpace transform ;
gFloat translationRadius;
// Hardcoded Model
struct CubeVerts
{
struct Vertex3
{
gFloat x, y, z;
static constexpr sfn ValueCount() -> gSize { return 3; }
};
Vertex3
f1, f2, f3, f4, // Front
b1, b2, b3, b4; // Back
}
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},
// 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}
};
struct CubeElements
{
struct Edge3
{
struct TriIndex
{
gInt a, b, c;
};
TriIndex a, b;
};
Edge3 front, right, back, left, bottom, top;
}
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 } }
};
ID<VertexArray > modelVAO;
ID<VertexBuffer > modelVBO;
ID<ElementBuffer> modelEBO;
};
class Entity_Basic
{
public:
Entity_Basic() :
position (Vector3(0.0f) ),
model ("" ),
transform(CoordSpace(1.0f))
{};
Entity_Basic(Ref(Model) _model, Ref(Material_Phong) _material) :
position (Vector3(0.0f) ),
model (_model ),
transform(CoordSpace(1.0f)),
material (_material )
//type (_type )
{};
sfn Update()
{
}
sfn Render(ro Ref(CoordSpace) _projection, ro Ref(CoordSpace) _viewport, ro Ref(Vector3) _lightPosition, ro Ref(VecColor) _lightColor)
{
PhongShader::Use(_projection, _viewport, transform, _lightPosition,_lightColor, material);
model.Render();
PhongShader::Stop();
return;
}
sfn operator= (ro Ref(Entity_Basic) _entity)->Ref(Entity_Basic)
{
position = _entity.position ;
model = _entity.model ;
transform = _entity.transform;
material = _entity.material ;
return Dref(this);
}
private:
//EEntityType type;
Vector3 position ;
Model model ;
CoordSpace transform ;
Material_Phong material ;
};
}

View File

@ -3,57 +3,37 @@
// DGL
#include "DGL_Buffers.hpp"
#include "DGL_Space.hpp"
#include "DGL_Types.hpp"
// C++
// Non-Standard C++
#include "Cpp_Alias.hpp"
namespace DGL
{
using std::string;
using UVList = std ::vector < Vector2>;
using Vec3Int = Generic::Vector3< gUInt >;
using Vec2Int = Generic::Vector2< gUInt >;
using VertexList = std ::vector < Vector3>;
using VIndexList = std ::vector < gInt >;
sfn Offset(gInt _offsetAmount)
{
return ptr<void>(_offsetAmount);
}
constexpr sfn ZeroOffset() -> ptr<void>
{
return 0;
}
struct VertexGenerator
{
using ComponentList = std::vector< gFloat>;
public:
ComponentList comp;
// TODO: De-hard-code this generator to do any vector size.
sfn GetVector() -> Vector3
sfn AddComponent(gFloat _float)
{
return Vector3(comp.at(0), comp.at(1), comp.at(2));
comp.push_back(_float);
}
// TODO: De-hard-code this generator to do any vector size.
sfn GetVector2() -> Vector2
{
return Vector2(comp.at(0), comp.at(1));
}
sfn GetVector3() -> Vector3
{
return Vector3(comp.at(0), comp.at(1), comp.at(2));
}
void Normalize()
{
using std::pow ;
@ -75,6 +55,10 @@ namespace DGL
*element /= magnitude;
}
}
private:
ComponentList comp;
};
@ -141,46 +125,122 @@ namespace DGL
};
struct Model
// TODO: Add support for textures...
class Model
{
ID<VertexArray > VAO;
ID<VertexBuffer > VBO;
ID<NormalBuffer > NBO;
ID<TextureBuffer> TBO;
ID<ElementBuffer> EBO;
private:
// Not the most efficient method to do normals, but works.
sfn generateNormals() -> void
{
normals.resize(verticies.size(), Vector3(0.0f));
const string FilePath;
for (int faceIndex = 0; faceIndex < faces.size(); faceIndex++)
{
int vertexIndex1 = faces[faceIndex].Vertexes[0],
vertexIndex2 = faces[faceIndex].Vertexes[1],
vertexIndex3 = faces[faceIndex].Vertexes[2];
VertexList Verticies ;
VertexList VertNormals;
Vector3 edge1 = verticies[vertexIndex2] - verticies[vertexIndex1],
edge2 = verticies[vertexIndex3] - verticies[vertexIndex1],
VertexList RAWVertex ;
VertexList VertNormalsRAW;
normal = GetDirection(GetCrossNormal(edge1, edge2));
UVList TextureMap ;
FaceList Faces ;
VIndexList Indicies ;
faces[faceIndex].Normals[0] = vertexIndex1;
faces[faceIndex].Normals[1] = vertexIndex2;
faces[faceIndex].Normals[2] = vertexIndex3;
normals[vertexIndex1] = normal;
normals[vertexIndex2] = normal;
normals[vertexIndex3] = normal;
}
}
public:
Model(const Ref(string) _filePath) :
VAO(-1),
VBO(-1),
NBO(-1),
EBO(-1),
FilePath (_filePath ),
Verticies (VertexList()),
VertNormals(VertexList()),
TextureMap (UVList ()),
Faces (FaceList ())
Model(ro Ref(string) _filePath) :
vertexArrayID (0 ),
vertexBufferID (0 ),
normalBuffferID(0 ),
textureBufferID(0 ),
elementBufferID(0 ),
filePath (_filePath ),
verticies (VertexList()),
normals (VertexList()),
textureUVs (UVList ()),
faces (FaceList ())
{}
// TODO: Add support for textures...
// Hardcoded to only do the verticies and normals for now...
sfn Buffer()
{
GenerateVertexBuffers(vertexArrayID , 1);
GenerateBuffers (vertexBufferID , 1);
GenerateBuffers (normalBuffferID, 1);
GenerateBuffers (elementBufferID, 1);
if (normals.size() == 0)
{
generateNormals();
}
BindVertexArray(vertexArrayID);
// Vertex Position Buffering
BindBuffer(EBufferTarget::VertexAttributes, vertexBufferID);
BufferData(verticies[0], gSize(verticies.size() * sizeof(Vector3)), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
FormatVertexAttributes<Vector3>(0, EDataType::Float, ZeroOffset(), 3, false);
EnableVertexAttributeArray(0);
// Normal Buffering
if (normals.size() != 0)
{
BindBuffer(EBufferTarget::VertexAttributes, normalBuffferID);
BufferData(normals[0], gSize(normals.size() * sizeof(Vector3)), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
FormatVertexAttributes<Vector3>(1, EDataType::Float, ZeroOffset(), 3, false);
EnableVertexAttributeArray(1);
}
// Texture buffering
// TODO: Fix this.
if (textureUVs.size() != 0)
{
//glBindTexture(TBO, GL_TEXTURE_2D);
//BufferData(Address(TextureMap[0]), TextureMap.size() * sizeof(Vector2), EBufferTarget::TextureData, EBufferUsage::StaticDraw);
//FormatVertexAttributes<Vector2>(2, EDataType::Float, ZeroOffset(), 2, EBool::False);
//EnableVertexAttributeArray(2);
}
BindBuffer(EBufferTarget::VertexIndices, elementBufferID);
BufferData(faces[0], gSize(faces.size() * sizeof(Face)), EBufferTarget::VertexIndices, EBufferUsage::StaticDraw);
UnbindVertexArray(); // Unbind vertex array.
}
sfn Load()
{
using std::cout ;
using std::endl ;
using std::get ;
using std::getline ;
using std::ifstream ;
@ -190,7 +250,7 @@ namespace DGL
ifstream fileBuffer; fileBuffer.open(FilePath);
ifstream fileBuffer; fileBuffer.open(filePath);
@ -202,10 +262,10 @@ namespace DGL
{
_vertexStream >> componentValue >> ws;
vertex.comp.push_back(componentValue);
vertex.AddComponent(componentValue);
}
Verticies.push_back(vertex.GetVector());
verticies.push_back(vertex.GetVector3());
};
deduce processNormals = [&](Ref(stringstream) _normalStream)
@ -216,12 +276,12 @@ namespace DGL
{
_normalStream >> componentValue >> ws;
normal.comp.push_back(componentValue);
normal.AddComponent(componentValue);
}
normal.Normalize();
VertNormals.push_back(normal.GetVector());
normals.push_back(normal.GetVector3());
};
deduce processTexture = [&](Ref(stringstream) _normalStream)
@ -232,10 +292,10 @@ namespace DGL
{
_normalStream >> componentValue >> ws;
texture.comp.push_back(componentValue);
texture.AddComponent(componentValue);
}
TextureMap.push_back(texture.GetVector2());
textureUVs.push_back(texture.GetVector2());
};
deduce processFace = [&](Ref(stringstream) _faceStream)
@ -248,7 +308,7 @@ namespace DGL
faceMade.AddVertexIndex(vertexIndex - 1);
Indicies.push_back(vertexIndex - 1);
indicies.push_back(vertexIndex - 1);
if (_faceStream.peek() == '/')
{
@ -262,7 +322,7 @@ namespace DGL
faceMade.AddNormalIndex(normalIndex -1);
Indicies.push_back(normalIndex - 1);
indicies.push_back(normalIndex - 1);
}
else
{
@ -278,17 +338,15 @@ namespace DGL
faceMade.AddNormalIndex(normalIndex - 1);
Indicies.push_back(normalIndex - 1);
indicies.push_back(normalIndex - 1);
}
}
}
}
Faces.push_back(faceMade.GetFace());
faces.push_back(faceMade.GetFace());
};
if (fileBuffer.is_open())
{
stringstream stringBuffer;
@ -325,130 +383,65 @@ namespace DGL
}
}
fileBuffer.close();
return;
}
else
{
throw std::runtime_error("Could not open file to load model.");
}
fileBuffer.close();
}
sfn GenerateNormals()
{
VertNormals.resize(Verticies.size());
for (int index = 0; index < Faces.size(); index++)
{
int vertexIndex1 = Faces[index].Vertexes[0],
vertexIndex2 = Faces[index].Vertexes[1],
vertexIndex3 = Faces[index].Vertexes[2];
Vector3 edge1 = Verticies[vertexIndex2] - Verticies[vertexIndex1],
edge2 = Verticies[vertexIndex3] - Verticies[vertexIndex1],
normal = GetDirection(GetCrossNormal(edge1, edge2));
Faces[index].Normals[0] = vertexIndex1;
Faces[index].Normals[1] = vertexIndex2;
Faces[index].Normals[2] = vertexIndex3;
VertNormals[vertexIndex1] = normal;
VertNormals[vertexIndex2] = normal;
VertNormals[vertexIndex3] = normal;
}
}
template<typename Type>
sfn RoundOff(Type _value, gInt _numDigitsToKeep) -> Type
{
uInt64 Rounder = pow(10, _numDigitsToKeep);
return round(_value * Rounder) / Rounder;
}
// Hardcoded to only do the verticies and normals for now...
sfn Buffer()
{
GenerateVertexBuffers(Address(VAO), 1);
GenerateBuffers (Address(VBO), 1);
GenerateBuffers (Address(NBO), 1);
//glGenTextures (1, Address(TBO));
GenerateBuffers (Address(EBO), 1);
if (VertNormals.size() == 0)
{
GenerateNormals();
}
BindVertexArray(VAO);
BindBuffer(EBufferTarget::VertexAttributes, VBO);
BufferData(Address(Verticies[0]), Verticies.size() * sizeof(Vector3), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
FormatVertexAttributes<Vector3>(0, EDataType::Float, ZeroOffset(), 3, EBool::False);
EnableVertexAttributeArray(0);
if (VertNormals.size() != 0)
{
BindBuffer(EBufferTarget::VertexAttributes, NBO);
BufferData(Address(VertNormals[0]), VertNormals.size() * sizeof(Vector3), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
FormatVertexAttributes<Vector3>(1, EDataType::Float, ZeroOffset(), 3, EBool::False);
EnableVertexAttributeArray(1);
}
/*if (TextureMap.size() != 0)
{
glBindTexture(TBO, GL_TEXTURE_2D);
BufferData(Address(TextureMap[0]), TextureMap.size() * sizeof(Vector2), EBufferTarget::TextureData, EBufferUsage::StaticDraw);
FormatVertexAttributes<Vector2>(2, EDataType::Float, ZeroOffset(), 2, EBool::False);
EnableVertexAttributeArray(2);
}*/
BindBuffer(EBufferTarget::VertexIndices, EBO);
BufferData(Address(Faces[0]), Faces.size() * sizeof(Face), EBufferTarget::VertexIndices, EBufferUsage::StaticDraw);
BindVertexArray(0);
}
sfn Render()
{
BindVertexArray(VAO);
BindVertexArray(vertexArrayID);
gInt Size; GetBufferParameterIV(EBufferTarget::VertexIndices, EBufferParam::Size, Address(Size));
Size /= sizeof(gUInt);
gInt SizeRef; GetBufferParameterIV(EBufferTarget::VertexIndices, EBufferParam::Size, SizeRef); SizeRef /= sizeof(gUInt);
DrawElements(EPrimitives::Triangles, Size, EDataType::UnsignedInt, ZeroOffset());
DrawElements(EPrimitives::Triangles, SizeRef, EDataType::UnsignedInt, ZeroOffset());
BindVertexArray(0);
UnbindVertexArray();
}
sfn operator= (ro Ref(Model) _model) -> Ref(Model)
{
vertexArrayID = _model.vertexArrayID ;
vertexBufferID = _model.vertexBufferID ;
normalBuffferID = _model.normalBuffferID;
textureBufferID = _model.textureBufferID;
elementBufferID = _model.elementBufferID;
filePath = _model.filePath;
verticies = _model.verticies ;
normals = _model.normals ;
textureUVs = _model.textureUVs;
faces = _model.faces ;
indicies = _model.indicies ;
return Dref(this);
}
private:
// Components
ID<VertexArray > vertexArrayID ;
ID<VertexBuffer > vertexBufferID ;
ID<NormalBuffer > normalBuffferID;
ID<TextureBuffer> textureBufferID;
ID<ElementBuffer> elementBufferID;
string filePath;
VertexList verticies ;
VertexList normals ;
UVList textureUVs;
FaceList faces ;
VIndexList indicies ;
};
};

View File

@ -2,52 +2,23 @@
//DGL
#include "DGL_Enum.hpp"
#include "DGL_FundamentalTypes.hpp"
#include "DGL_MiscTypes.hpp"
#include "DGL_Types.hpp"
#include "DGL_Buffers.hpp"
#include "DGL_Space.hpp"
// Non-Standard C++
#include "Cpp_Alias.hpp"
namespace DGL
{
// Some Raw Source Defaults:
RawString<const char> RawVertextShaderSource =
"#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
"}\0";
RawString<const char> RawFragmentShaderSource =
"#version 400\n"
"out vec4 frag_colour;"
"void main() {"
" frag_colour = vec4(0.5, 0.0, 0.5, 1.0);"
"}";
// Default Shaders
ID<ShaderProgram> RawShader ,
SimpleShader ;
// Forward Declarations
sfn GetShaderInfo ( ID<Shader > _shader , gSize _logLength , ptr<gSize> _infoLengthRef , RawString<gChar> _infoLogRef ) -> void;
sfn QueryShader ( ID<Shader > _shaderToQuery , EShaderInfo _shaderInfoDesired, ptr<gInt > _requestedInfoObject ) -> void;
sfn MakeShader (Ref(ID<Shader >) _shaderIDHolder , EShaderType _typeOfShader , uInt64 _numberOfStringElements , ptr<RawString<const gChar>> _sourceCode, ptr<const gInt> _lengthsOfStrings) -> void;
sfn MakeShaderProgram(Ref(ID<ShaderProgram>) _shaderProgramIDHolder, const ID<Shader> _vertexShader , const ID<Shader> _fragShader ) -> void;
sfn GetShaderInfo ( ID<Shader > _shader , gSize _logLength , ptr<gSize> _infoLengthRef , RawString<gChar> _infoLogRef ) -> void;
sfn QueryShader ( ID<Shader > _shaderToQuery , EShaderInfo _shaderInfoDesired, ptr<gInt > _requestedInfoObject ) -> void;
sfn MakeShader (Ref(ID<Shader >) _shaderIDHolder , EShaderType _typeOfShader , uInt64 _numberOfStringElements , ro ptr<RawString<ro gChar>> _sourceCode, ro ptr<gInt> _lengthsOfStrings) -> void;
sfn MakeShaderProgram(Ref(ID<ShaderProgram>) _shaderProgramIDHolder,ro ID<Shader> _vertexShader , ro ID<Shader> _fragShader ) -> void;
@ -57,7 +28,7 @@ namespace DGL
{
GLint uniforms;
glGetProgramiv(_shaderToQueryForUniforms, GL_ACTIVE_UNIFORMS, &uniforms);
glGetProgramiv(_shaderToQueryForUniforms, GL_ACTIVE_UNIFORMS, Address(uniforms));
for (int uniformIndex = 0; uniformIndex < uniforms; uniformIndex++)
{
@ -67,7 +38,7 @@ namespace DGL
char name[100];
glGetActiveUniform(_shaderToQueryForUniforms, GLuint(uniformIndex), sizeof(name) - 1, &name_len, &num, &type, name);
glGetActiveUniform(_shaderToQueryForUniforms, GLuint(uniformIndex), sizeof(name) - 1, Address(name_len), Address(num), Address(type), name);
name[name_len] = 0;
}
@ -82,14 +53,14 @@ namespace DGL
return;
}
sfn BindShaderSource(ID<Shader> _shader, uInt64 _numberOfStringElements, ptr< RawString<const gChar>> _sourceCode, ptr<const gInt> _lengthsOfStrings)
sfn BindShaderSource(ID<Shader> _shader, gSize _numberOfStringElements, ro ptr<RawString<ro gChar>> _sourceCode, ro ptr<gInt> _lengthsOfStrings)
{
glShaderSource(_shader, _numberOfStringElements, _sourceCode, _lengthsOfStrings);
glShaderSource(_shader, _numberOfStringElements, _sourceCode, _lengthsOfStrings); //Address(_sourceCode), Address(_lengthsOfStrings));
return;
}
sfn CompileShader(const ID<Shader> _shaderToCompile)
sfn CompileShader(ID<Shader> _shaderToCompile)
{
glCompileShader(_shaderToCompile);
@ -144,21 +115,21 @@ namespace DGL
return;
}
sfn GetShaderInfo(ID<Shader> _shader, gSize _logLength, ptr<gSize> _infoLengthRef, RawString<gChar> _infoLogRef) -> void
sfn GetShaderInfo(ID<Shader> _shader, gSize _logLength, ro ptr<gSize> _infoLengthRef, RawString<gChar> _infoLogRef) -> void
{
glGetShaderInfoLog(_shader, _logLength, _infoLengthRef, _infoLogRef);
return;
}
sfn GetShaderProgramInfo(ID<ShaderProgram> _shaderProgram, gSize _logLength, ptr<gSize> _infoLengthRef, RawString<gChar> _infoLogRef) -> void
sfn GetShaderProgramInfo(ID<ShaderProgram> _shaderProgram, gSize _logLength, ro ptr<gSize> _infoLengthRef, RawString<gChar> _infoLogRef) -> void
{
glGetProgramInfoLog(_shaderProgram, _logLength, _infoLengthRef, _infoLogRef);
return;
}
sfn GetUniformVariable(const ID<ShaderProgram> _programID, RawString<const char> _nameOfVariable) -> ID<Matrix>
sfn GetUniformVariable(const ID<ShaderProgram> _programID, ro RawString<const char> _nameOfVariable) -> ID<Matrix>
{
return glGetUniformLocation(_programID, _nameOfVariable);
}
@ -184,15 +155,9 @@ namespace DGL
return;
}
sfn LoadShaders(RawString<const char> _vertexShaderFilePath, RawString<const char> _fragmentShaderFilePath) -> ID<ShaderProgram>
sfn LoadShaders(RawString<ro char> _vertexShaderFilePath, RawString<ro char> _fragmentShaderFilePath) -> ID<ShaderProgram>
{
using std::cout ;
using std::endl ;
using std::ifstream ;
using std::ios ;
using std::string ;
using std::stringstream;
using std::vector ;
using std::vector;
string vertexShaderCode ;
@ -204,72 +169,63 @@ namespace DGL
vertexShaderFileStream .open(_vertexShaderFilePath);
fragmentShaderFileStream.open(_fragmentShaderFilePath);
try
if (vertexShaderFileStream.is_open() and fragmentShaderFileStream.is_open())
{
if (vertexShaderFileStream.is_open() and fragmentShaderFileStream.is_open())
{
stringstream vertSourceStrStream;
stringstream fragSourceStrStream;
stringstream vertSourceStrStream;
stringstream fragSourceStrStream;
vertSourceStrStream << vertexShaderFileStream .rdbuf();
fragSourceStrStream << fragmentShaderFileStream.rdbuf();
vertSourceStrStream << vertexShaderFileStream .rdbuf();
fragSourceStrStream << fragmentShaderFileStream.rdbuf();
vertexShaderFileStream .close();
fragmentShaderFileStream.close();
vertexShaderFileStream .close();
fragmentShaderFileStream.close();
vertexShaderCode = vertSourceStrStream.str();
fragmentShaderCode = fragSourceStrStream.str();
}
else
{
throw std::runtime_error("Impossible to open% s.Are you in the right directory ? Don't forget to read the FAQ !");
}
RawString<const char> vertexSourcePtr = vertexShaderCode .c_str();
RawString<const char> fragmentSourcePtr = fragmentShaderCode.c_str();
cout << "Compiling shader: " << _vertexShaderFilePath << endl;
ID<Shader> vertexShader = CreateShader(EShaderType::Vertex);
BindShaderSource(vertexShader, 1, Address(vertexSourcePtr), NULL);
CompileShader (vertexShader );
cout << "Compiling shader: " << _fragmentShaderFilePath << endl;
ID<Shader> fragmentShader = CreateShader(EShaderType::Fragment);
BindShaderSource(fragmentShader, 1, Address(fragmentSourcePtr), NULL);
CompileShader (fragmentShader );
cout << "Making Shader Program and Linking..." << endl;
ID<ShaderProgram> generatedProgram;
MakeShaderProgram(generatedProgram, vertexShader, fragmentShader);
DeleteShader(vertexShader );
DeleteShader(fragmentShader);
return generatedProgram;
vertexShaderCode = vertSourceStrStream.str();
fragmentShaderCode = fragSourceStrStream.str();
}
catch (const std::runtime_error _error)
else
{
ErrorRuntime(_error);
Exit(ExitCode::Failed);
throw std::runtime_error("Impossible to open% s.Are you in the right directory ? Don't forget to read the FAQ !");
}
RawString<const char> vertexSourcePtr = vertexShaderCode .c_str();
RawString<const char> fragmentSourcePtr = fragmentShaderCode.c_str();
cout << "Compiling shader: " << _vertexShaderFilePath << endl;
ID<Shader> vertexShader = CreateShader(EShaderType::Vertex);
BindShaderSource(vertexShader, 1, Address(vertexSourcePtr), NULL);
CompileShader (vertexShader );
cout << "Compiling shader: " << _fragmentShaderFilePath << endl;
ID<Shader> fragmentShader = CreateShader(EShaderType::Fragment);
BindShaderSource(fragmentShader, 1, Address(fragmentSourcePtr), NULL);
CompileShader (fragmentShader );
cout << "Making Shader Program and Linking..." << endl;
ID<ShaderProgram> generatedProgram;
MakeShaderProgram(generatedProgram, vertexShader, fragmentShader);
DeleteShader(vertexShader );
DeleteShader(fragmentShader);
return generatedProgram;
}
sfn MakeShader
(
Ref(ID<Shader>) _shaderIDHolder ,
EShaderType _typeOfShader ,
uInt64 _numberOfStringElements,
ptr<RawString<const gChar>> _sourceCode ,
ptr< const gInt > _lengthsOfStrings
Ref(ID<Shader> ) _shaderIDHolder ,
EShaderType _typeOfShader ,
gSize _numberOfStringElements,
ro ptr<RawString<ro gChar>> _sourceCode ,
ro ptr< gInt > _lengthsOfStrings
)
-> void
{
@ -282,7 +238,7 @@ namespace DGL
return;
}
sfn MakeShaderProgram(Ref(ID<ShaderProgram>) _shaderProgramIDHolder, const ID<Shader> _vertexShader, const ID<Shader> _fragShader) -> void
sfn MakeShaderProgram(Ref(ID<ShaderProgram>) _shaderProgramIDHolder, ID<Shader> _vertexShader, ID<Shader> _fragShader) -> void
{
_shaderProgramIDHolder = CreateShaderProgram();
@ -307,6 +263,8 @@ namespace DGL
GetShaderProgramInfo(_shaderProgramIDHolder, infoLogLength, NULL, Address(ErrorMessage.at(0)));
cout << (char*)&ErrorMessage[0] << endl;
throw std::runtime_error(Address(ErrorMessage.at(0)));
}
else
@ -322,16 +280,23 @@ namespace DGL
}
// MVA: MatrixVariableArray
sfn SetUniformVariable_MVA(const ID<Matrix> _matrixID, const gSize _numMatricies, const EBool _shouldTransposeValues, ptr<const float> _dataPtr)
sfn SetUniformVariable_MVA(ID<Matrix> _matrixID, gSize _numMatricies, gBoolean _shouldTransposeValues, ro Ref(gFloat) _dataPtr)
{
glUniformMatrix4fv(_matrixID, _numMatricies, GLenum(_shouldTransposeValues), _dataPtr);
glUniformMatrix4fv(_matrixID, _numMatricies, _shouldTransposeValues, Address(_dataPtr));
return;
}
sfn SetUniformVariable_Vector3(const ID<Vec3> _ID, const gSize _numColor3, ptr<const gFloat> _dataPtr)
sfn SetUniformVariable_Vector3(ID<Vec3> _ID, gSize _num, ro Ref(gFloat) _dataPtr)
{
glUniform3fv(_ID, _numColor3, _dataPtr);
glUniform3fv(_ID, _num, Address(_dataPtr));
return;
}
sfn SetUniformVariable_Float(ID<gFloat> _ID, gFloat _data)
{
glUniform1f(_ID, _data);
return;
}
@ -344,15 +309,137 @@ namespace DGL
}
// Shader Class
//class Shader_PhongBasic
//{
//public:
// Shader_PhongBasic()
// {
// LoadShader();
// };
// sfn LoadShader()
// {
// shaderID = LoadShaders("PhongShader_Deprecated.vert", "PhongShader_Deprecated.frag");
// inverseModelSpaceID = GetUniformVariable(shaderID, "InverseModelSpace");
// modelSpaceID = GetUniformVariable(shaderID, "ModelSpace" );
// projectionID = GetUniformVariable(shaderID, "Projection" );
// viewportID = GetUniformVariable(shaderID, "Viewport" );
// objectColorID = GetUniformVariable(shaderID, "ObjectColor" );
// lightColorID = GetUniformVariable(shaderID, "LightColor" );
// lightPositionID = GetUniformVariable(shaderID, "LightPosition");
// viewPositionID = GetUniformVariable(shaderID, "ViewPosition" );
// return;
// }
// sfn Use
// (
// ro Ref(CoordSpace) _projection ,
// ro Ref(CoordSpace) _viewport ,
// ro Ref(CoordSpace) _objectTransform ,
// ro Ref(Vector3 ) _objectColor ,
// ro Ref(Vector3 ) _lightPosition ,
// ro Ref(Vector3 ) _lightColor ,
// ro Ref(Vector3 ) _viewPosition
// )
// {
// CoordSpace inverseTransform = Inverse(_viewport * _objectTransform);
// UseProgramShader(shaderID);
// SetUniformVariable_MVA(inverseModelSpaceID, 1, false, inverseTransform[0][0]);
// SetUniformVariable_MVA(modelSpaceID , 1, false, _objectTransform[0][0]);
// SetUniformVariable_MVA(projectionID , 1, false, _projection [0][0]);
// SetUniformVariable_MVA(viewportID , 1, false, _viewport [0][0]);
// SetUniformVariable_Vector3(lightPositionID, 1, _lightPosition[0]);
// SetUniformVariable_Vector3(objectColorID , 1, _objectColor [0]);
// SetUniformVariable_Vector3(lightColorID , 1, _lightColor [0]);
// SetUniformVariable_Vector3(viewPositionID, 1, _viewPosition[0]);
// EnableVertexAttributeArray(0);
// EnableVertexAttributeArray(1);
// //EnableVertexAttributeArray(2);
// return;
// }
// sfn Stop()
// {
// //DisableVertexAttributeArray(2);
// DisableVertexAttributeArray(1);
// DisableVertexAttributeArray(0);
// return;
// }
// Declarations
//private:
// ID<ShaderProgram> shaderID;
// ID<CoordSpace> modelSpaceID, inverseModelSpaceID, viewportID, projectionID;
// ID<Vec3> lightPositionID, viewPositionID, objectColorID, lightColorID;
// gInt vertexIndexID, normalIndexID;
//};
// Old
// Some Raw Source Defaults:
RawString<const char> RawVertextShaderSource =
"#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n"
"void main()\n"
"{\n"
" gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
"}\0";
RawString<const char> RawFragmentShaderSource =
"#version 400\n"
"out vec4 frag_colour;"
"void main() {"
" frag_colour = vec4(0.5, 0.0, 0.5, 1.0);"
"}";
// Default Shaders
ID<ShaderProgram> RawShader ,
SimpleShader ;
namespace SS_Transformed
{
ID<ShaderProgram> Shader;
ID<CoordSpace> ScreenSpaceVarID;
sfn UpdateShader(Ref(CoordSpace) _screenSpace)
sfn UpdateShader(ro Ref(CoordSpace) _screenSpace)
{
SetUniformVariable_MVA(ScreenSpaceVarID, 1, DGL::EBool::False, Address(_screenSpace[0][0]));
SetUniformVariable_MVA(ScreenSpaceVarID, 1, false, _screenSpace[0][0]);
return;
}
@ -385,23 +472,27 @@ namespace DGL
LightColorID = GetUniformVariable(Shader, "LightColor" );
}
sfn Use(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]));
EnableVertexAttributeArray(0);
EnableVertexAttributeArray(1);
}
sfn Stop()
{
DisableVertexAttributeArray(0);
DisableVertexAttributeArray(1);
return;
}
sfn Use(Ref(CoordSpace) _cubeTransform, Ref(Vector3) _objectColor, Ref(Vector3) _lightColor)
{
UseProgramShader(Shader);
SetUniformVariable_MVA(ScreenSpaceVarID, 1, false, _cubeTransform[0][0]);
SetUniformVariable_Vector3(ObjectColorID, 1, _objectColor[0]);
SetUniformVariable_Vector3(LightColorID , 1, _lightColor [0]);
EnableVertexAttributeArray(0);
EnableVertexAttributeArray(1);
return;
}
}
@ -416,34 +507,50 @@ namespace DGL
Shader = LoadShaders("SimpleTransform.vert", "BasicLamp.frag");
ScreenSpaceVarID = GetUniformVariable(Shader, "ScreenSpaceTransform");
return;
}
sfn SetupLampRender(Ref(CoordSpace) _lampTransform)
sfn Use(ro Ref(CoordSpace) _lampTransform)
{
UseProgramShader(Shader);
SetUniformVariable_MVA(ScreenSpaceVarID, 1, EBool::False, Address(_lampTransform[0][0]));
SetUniformVariable_MVA(ScreenSpaceVarID, 1, false, _lampTransform[0][0]);
EnableVertexAttributeArray(0);
EnableVertexAttributeArray(1);
return;
}
sfn Stop()
{
DisableVertexAttributeArray(0);
DisableVertexAttributeArray(1);
return;
}
}
struct Material_Phong
{
VecColor Color ;
gFloat Ambience;
gFloat Diffuse ;
gFloat Specular;
};
namespace PhongShader
{
ID<ShaderProgram> ShaderID;
ID<CoordSpace> ModelSpaceID, InverseModelSpaceID, ViewportID, ProjectionID;
ID<Vec3> LightPositionID, ViewPositionID;
ID<Vec3> LightPositionID, ObjectColorID, LightColorID;
ID<Vec3> ObjectColorID, LightColorID;
ID<gFloat> AmbientStrengthID, DiffuseStrengthID, SpecularStrengthID;
gInt VertexIndexID, NormalIndexID;
sfn LoadShader()
{
@ -457,59 +564,99 @@ namespace DGL
ObjectColorID = GetUniformVariable(ShaderID, "ObjectColor" );
LightColorID = GetUniformVariable(ShaderID, "LightColor" );
LightPositionID = GetUniformVariable(ShaderID, "LightPosition");
ViewPositionID = GetUniformVariable(ShaderID, "ViewPosition" );
AmbientStrengthID = GetUniformVariable(ShaderID, "AmbientStrength" );
DiffuseStrengthID = GetUniformVariable(ShaderID, "DiffuseStrength" );
SpecularStrengthID = GetUniformVariable(ShaderID, "SpecularStrength");
return;
}
sfn Use
sfn Use_Old
(
Ref(CoordSpace) _projection ,
Ref(CoordSpace) _viewport ,
Ref(CoordSpace) _objectTransform ,
Ref(Vector3 ) _objectColor ,
Ref(Vector3 ) _lightPosition ,
Ref(Vector3 ) _lightColor ,
Ref(Vector3 ) _viewPosition
ro Ref(CoordSpace) _projection ,
ro Ref(CoordSpace) _viewport ,
ro Ref(CoordSpace) _objectTransform ,
ro Ref(Vector3 ) _objectColor ,
ro Ref(Vector3 ) _lightPosition ,
ro Ref(Vector3 ) _lightColor ,
ro Ref(Vector3 ) _viewPosition
)
{
CoordSpace inverseTransform = Inverse(_viewport * _objectTransform);
UseProgramShader(ShaderID);
SetUniformVariable_MVA(InverseModelSpaceID, 1, EBool::False, Address(inverseTransform[0][0]));
SetUniformVariable_MVA(ModelSpaceID , 1, EBool::False, Address(_objectTransform[0][0]));
SetUniformVariable_MVA(ProjectionID , 1, EBool::False, Address(_projection [0][0]));
SetUniformVariable_MVA(ViewportID , 1, EBool::False, Address(_viewport [0][0]));
SetUniformVariable_MVA(InverseModelSpaceID, 1, false, inverseTransform[0][0]);
SetUniformVariable_MVA(ModelSpaceID , 1, false, _objectTransform[0][0]);
SetUniformVariable_MVA(ProjectionID , 1, false, _projection [0][0]);
SetUniformVariable_MVA(ViewportID , 1, false, _viewport [0][0]);
SetUniformVariable_Vector3(LightPositionID, 1, Address(_lightPosition[0]));
SetUniformVariable_Vector3(LightPositionID, 1, _lightPosition[0]);
SetUniformVariable_Vector3(ObjectColorID , 1, Address(_objectColor [0]));
SetUniformVariable_Vector3(LightColorID , 1, Address(_lightColor [0]));
SetUniformVariable_Vector3(ViewPositionID, 1, Address(_viewPosition[0]));
SetUniformVariable_Vector3(ObjectColorID , 1, _objectColor [0]);
SetUniformVariable_Vector3(LightColorID , 1, _lightColor [0]);
EnableVertexAttributeArray(0);
EnableVertexAttributeArray(1);
//EnableVertexAttributeArray(2);
return;
}
sfn Use
(
ro Ref(CoordSpace ) _projection ,
ro Ref(CoordSpace ) _viewport ,
ro Ref(CoordSpace ) _objectTransform ,
ro Ref(Vector3 ) _lightPosition ,
ro Ref(Vector3 ) _lightColor ,
ro Ref(Material_Phong) _material
)
{
CoordSpace inverseTransform = Inverse(_viewport * _objectTransform);
UseProgramShader(ShaderID);
SetUniformVariable_MVA(InverseModelSpaceID, 1, false, inverseTransform[0][0]);
SetUniformVariable_MVA(ModelSpaceID , 1, false, _objectTransform[0][0]);
SetUniformVariable_MVA(ProjectionID , 1, false, _projection [0][0]);
SetUniformVariable_MVA(ViewportID , 1, false, _viewport [0][0]);
SetUniformVariable_Vector3(LightPositionID, 1, _lightPosition[0]);
SetUniformVariable_Vector3(ObjectColorID , 1, _material.Color[0]);
SetUniformVariable_Vector3(LightColorID , 1, _lightColor [0]);
SetUniformVariable_Float(AmbientStrengthID , _material.Ambience);
SetUniformVariable_Float(DiffuseStrengthID , _material.Diffuse );
SetUniformVariable_Float(SpecularStrengthID, _material.Specular);
EnableVertexAttributeArray(0);
EnableVertexAttributeArray(1);
return;
}
sfn Stop()
{
//DisableVertexAttributeArray(2);
DisableVertexAttributeArray(1);
DisableVertexAttributeArray(0);
return;
}
}
sfn LoadRawShader()
{
ID<Shader> VertexShader;
ID<Shader> FragmentShader;
ID<Shader> VertexShader = 0;
ID<Shader> FragmentShader = 0;
MakeShader(VertexShader , EShaderType::Vertex , 1, Address(DGL::RawVertextShaderSource ), NULL);
MakeShader(FragmentShader, EShaderType::Fragment, 1, Address(DGL::RawFragmentShaderSource), NULL);
MakeShader(VertexShader , EShaderType::Vertex , 1, Address(RawVertextShaderSource ), NULL);
MakeShader(FragmentShader, EShaderType::Fragment, 1, Address(RawFragmentShaderSource), NULL);
MakeShaderProgram(RawShader, VertexShader, FragmentShader);
DeleteShader(VertexShader);
DeleteShader(VertexShader );
DeleteShader(FragmentShader);
return;

View File

@ -6,19 +6,16 @@
#include <glm/ext/matrix_transform.hpp >
// DGL
#include "DGL_FundamentalTypes.hpp"
#include "DGL_MiscTypes.hpp"
#include "DGL_Types.hpp"
// Non-Standard C++
#include "Cpp_Alias.hpp"
namespace DGL
{
using CoordSpace = Matrix4x4;
using Projection = Matrix4x4;
// Function
@ -34,7 +31,7 @@ namespace DGL
}
template<typename Type>
sfn CreateLookAtView(const Generic::Vector3<Type> _viewPosition, const Generic::Vector3<Type> _lookAtPosition, const Generic::Vector3<Type> _upDirection) -> Matrix4x4
sfn CreateLookAtView(ro Ref(Generic::Vector3<Type>) _viewPosition, ro Ref(Generic::Vector3<Type>) _lookAtPosition, ro Ref(Generic::Vector3<Type>) _upDirection) -> Matrix4x4
{
return glm::lookAt(_viewPosition, _lookAtPosition, _upDirection);
}
@ -45,43 +42,43 @@ namespace DGL
}
template<typename FloatType>
sfn CreatePerspective(const FloatType _fieldOfView, const FloatType _aspectRatio, const FloatType _nearPlane, const FloatType _farPlane)
sfn CreatePerspective(FloatType _fieldOfView, FloatType _aspectRatio, FloatType _nearPlane, FloatType _farPlane)
{
return glm::perspective(_fieldOfView, _aspectRatio, _nearPlane, _farPlane);
}
sfn GetCrossNormal(Vector3 _subj, Vector3 _ref) -> Vector3
sfn GetCrossNormal(ro Ref(Vector3) _subj, ro Ref(Vector3) _ref) -> Vector3
{
return glm::cross(_subj, _ref);
}
sfn GetDirection(Vector3 _vectorSpecified)
sfn GetDirection(ro Ref(Vector3) _vectorSpecified)
{
return glm::normalize(_vectorSpecified);
}
sfn Inverse(const Matrix4x4 _matrix)
sfn Inverse(ro Ref(Matrix4x4) _matrix)
{
return glm::inverse(_matrix);
}
sfn Rotate(const Matrix4x4 _matrix, gFloat _rotationAngleAmount, Vector3 _axis) -> Matrix4x4
sfn Rotate(ro Ref(Matrix4x4) _matrix, gFloat _rotationAngleAmount, ro Ref(Vector3) _axis) -> Matrix4x4
{
return glm::rotate(_matrix, _rotationAngleAmount, _axis);
}
sfn Scale(const Matrix4x4 _matrix, Vector3 _scaleBy)
sfn Scale(ro Ref(Matrix4x4) _matrix, ro Ref(Vector3) _scaleBy)
{
return glm::scale(_matrix, _scaleBy);
}
template<typename Type>
sfn ToRadians(const Ref(Type) _degrees) -> Type
sfn ToRadians(Type _degrees) -> Type
{
return glm::radians(_degrees);
}
sfn Translate(const Matrix4x4 _matrix, Vector3 _translationAmount)
sfn Translate(ro Ref(Matrix4x4) _matrix, ro Ref(Vector3) _translationAmount)
{
return glm::translate(_matrix, _translationAmount);
}
@ -109,7 +106,7 @@ namespace DGL
UpDirection ( 0, 1, 0),
FrontDirection( 0, 0, 1) ;
gFloat ScreenWidth = 720.0f, ScreenHeight = 540.0f, ScreenCenterWidth = ScreenWidth / 2, ScreenCenterHeight = ScreenHeight / 2;
gInt ScreenWidth = 720, ScreenHeight = 540, ScreenCenterWidth = ScreenWidth / 2, ScreenCenterHeight = ScreenHeight / 2;
}
struct Camera
@ -127,13 +124,13 @@ namespace DGL
Camera
(
gFloat _aspectRatio ,
gFloat _fieldOfView ,
ClippingPlanes _clippingPlanes,
Vector3 _position ,
Vector3 _lookAtPosition,
Vector3 _upDirection ,
Vector3 _frontDirection
gFloat _aspectRatio ,
gFloat _fieldOfView ,
ro Ref(ClippingPlanes) _clippingPlanes,
ro Ref(Vector3 ) _position ,
ro Ref(Vector3 ) _lookAtPosition,
ro Ref(Vector3 ) _upDirection ,
ro Ref(Vector3 ) _frontDirection
) :
AspectRatio (_aspectRatio ),
FieldOfView (_fieldOfView ),
@ -143,11 +140,11 @@ namespace DGL
UpDirection (_upDirection ),
FrontDirection(_frontDirection)
{
Yaw = -90.0f; Pitch = 0; Roll = 0;
Yaw = -90.0f; Pitch = 0.0f; Roll = 0.0f;
UpdateCamera();
Orthographic = CreateOrthographic(0.0f, DefaultSpace::ScreenWidth, 0.0f, DefaultSpace::ScreenHeight, ClipSpace.Near, ClipSpace.Far);
Orthographic = CreateOrthographic(0.0f, gFloat(DefaultSpace::ScreenWidth), 0.0f, gFloat(DefaultSpace::ScreenHeight), ClipSpace.Near, ClipSpace.Far);
Perspective = CreatePerspective<gFloat>(ToRadians(FieldOfView), AspectRatio, ClipSpace.Near, ClipSpace.Far);
}
@ -202,7 +199,7 @@ namespace DGL
return;
}
sfn Move(Vector3 _translationAmount, Ref(gFloat) _deltaTime)
sfn Move(ro Ref(Vector3) _translationAmount, gFloat _deltaTime)
{
Position += _translationAmount * _deltaTime;
@ -266,12 +263,12 @@ namespace DGL
{
Camera WorldCamera
(
AspectRatio,
FieldOfView,
AspectRatio ,
FieldOfView ,
ClippingPlanes(NearClippingPlane, FarClippingPlane),
CameraPosition,
LookAtPosition,
UpDirection,
CameraPosition ,
LookAtPosition ,
UpDirection ,
FrontDirection
);

117
DGL_Types.hpp Normal file
View File

@ -0,0 +1,117 @@
/*
Title : Ducktaped GL: Types
Author: Edward R. Gonzalez
Description:
Provides type definitions and aliases for the various types used in DGL library.
*/
#pragma once
// GLEW
#include <glew.h>
// GLFW
#include <glfw3.h>
// GLM
#include <glm/glm.hpp>
// C++
#include "Cpp_Alias.hpp"
namespace DGL
{
// OpenGL
// Fundamental Types
using gBitfield = GLbitfield;
using gBoolean = GLboolean ;
using gChar = GLchar ;
using gFloat = GLfloat ;
using gFloatClamped = GLclampf ;
using gInt = GLint ;
using gUInt = GLuint ;
using gSize = GLsizei ;
using gVoid = GLvoid ;
using DataPtr = ptr<gVoid>;
// Type used to indicate the context of an integer used as an ID for an object managed by OpenGL.
template<typename ReferenceType>
using ID = gUInt;
// ID Reference Types
class ElementBuffer;
class Matrix ;
class NormalBuffer ;
class Shader ;
class ShaderProgram;
class TextureBuffer;
class Vec3 ;
class VertexArray ;
class VertexBuffer ;
// GLM
namespace Generic
{
template<typename Type>
using Vector3 = glm::tvec3<Type>;
template<typename Type>
using Vector2 = glm::tvec2<Type>;
}
using Matrix4x4 = glm::mat4;
using CoordSpace = Matrix4x4;
using Projection = Matrix4x4;
using Vector2 = glm::vec2;
using Vector3 = glm::vec3;
using Vector4 = glm::vec4;
using UVList = std::vector < Vector2>;
using Vec2Int = Generic::Vector2< gUInt >;
using Vec3Int = Generic::Vector3< gUInt >;
using VertexList = std ::vector < Vector3>;
// GLFW
using Monitor = GLFWmonitor ;
using TimeValInt = uint64_t ;
using TimeValDec = double ;
using Window = GLFWwindow ;
using WindowRefList = std::vector< ptr<Window> >;
// DGL
using VecColor = Vector3;
struct LinearColor
{
gFloatClamped Red, Green, Blue, Alpha;
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);
}
};
using VIndexList = std ::vector < gInt >;
}

301
DGL_Utilities.hpp Normal file
View File

@ -0,0 +1,301 @@
#pragma once
// GLFW, GLEW, GLM
#include <glew.h >
#include <glfw3.h >
#include <glm/glm.hpp >
#include <glm/gtc/matrix_transform.hpp>
// DGL
#include "DGL_Types.hpp"
#include "DGL_Enum.hpp"
#include "DGL_Shader.hpp"
#include "DGL_Buffers.hpp"
#include "DGL_Space.hpp"
#include "DGL_Model.hpp"
// Non-Standard C+
#include "Cpp_Alias.hpp"
namespace DGL
{
// Object Instances
WindowRefList Windows;
// Constants
sfn constexpr NotShared () -> ptr<Window > { return NULL; }
sfn constexpr WindowedMode() -> ptr<Monitor> { return NULL; }
// Forward Declarations
sfn SwapBuffers(ro ptr<Window> _window) -> void;
// Functionality
sfn CanClose(ro ptr<Window> _theWindow)
{
return glfwWindowShouldClose(_theWindow);
}
sfn CanUseRawMouse()
{
return glfwRawMouseMotionSupported();
}
sfn CreateWindow
(
int _width ,
int _height ,
ro RawString<ro char> _title ,
ro ptr <Monitor> _monitorToFullscreen ,
ro ptr <Window > _windowToShareResourcesWith
)
-> ptr<Window>
{
Windows.push_back(glfwCreateWindow(_width, _height, _title, _monitorToFullscreen, _windowToShareResourcesWith));
if (Windows.back() == NULL)
{
throw std::runtime_error("Failed to create a window");
}
return Windows.back();
}
sfn CursorPositionUpdateBind(ro ptr<Window> _window, ro FnPtr<void, double, double> _functionToCall)
{
glfwSetCursorPosCallback(_window, GLFWcursorposfun(_functionToCall));
}
sfn DestoryWindow(ro ptr<Window> _window)
{
using ElementType = decltype(Windows.begin());
for (ElementType element = Windows.begin(); element != Windows.end(); element++)
{
if (Dref(element._Ptr) == _window)
{
glfwDestroyWindow(_window);
Windows.erase(element);
return;
}
}
return;
}
sfn EnableDepth()
{
// TODO: Clean.
// Enable depth test
glEnable(GL_DEPTH_TEST);
// Accept fragment if it closer to the camera than the former one
glDepthFunc(GL_LESS);
}
sfn GetCursorPosition(ro ptr<Window> _window, ro ptr<double> _xAxis, ro ptr<double> _yAxis)
{
glfwGetCursorPos(_window, _xAxis, _yAxis);
}
sfn GetMouseInputMode(ro ptr<Window> _contextWindowRef, EMouseMode _mode)
{
return glfwGetInputMode(_contextWindowRef, GLenum(_mode));
}
sfn GetRawTime() -> TimeValInt
{
return glfwGetTimerValue();
}
sfn GetTime() -> TimeValDec
{
return glfwGetTime();
}
sfn InitalizeGLFW()
{
std::cout << "Initializing GLFW Version: " << glfwGetVersionString() << std::endl;
/* Initialize the library */
if (!glfwInit())
{
throw std::runtime_error("Failed to initialize GLFW");
}
return;
}
sfn InitalizeGLEW()
{
// If using GLEW version 1.13 or earlier
//glewExperimental = true;
std::cout << "Initializing Glew Version: " << glewGetString(GLEW_VERSION) << std::endl;
GLenum err = glewInit();
if (err != GLEW_OK)
{
// Problem: glewInit failed, something is seriously wrong.
std::cout << "glewInit failed: " << glewGetErrorString(err) << std::endl;
throw std::runtime_error("Failed to initialize GLFW");
}
cout << "OpenGL Version: " << glGetString(GL_VERSION) << endl;
}
sfn KeyPressed(ro ptr<Window> _contextWindowRef, EKeyCodes _keyToCheck) -> bool
{
return glfwGetKey(_contextWindowRef, int(_keyToCheck));
}
template<typename... CodeType, typename = EKeyCodes>
sfn KeysPressed(ro ptr<Window> _contextWindowRef, CodeType... _otherKeys) -> bool
{
return (KeyPressed(_contextWindowRef, _otherKeys) && ...) == true;
}
sfn PollEvents()
{
glfwPollEvents();
return;
}
sfn ResetCursor(ro ptr<Window> _window, gUInt _screenCenterWidth, gUInt _screenCenterHeight)
{
//glfwSetCursorPos(_window, _screenCenterWidth, _screenCenterHeight);
ECursorMode cursorMode = ECursorMode(GetMouseInputMode(_window, EMouseMode::Cursor));
if (cursorMode == ECursorMode::Normal || cursorMode == ECursorMode::Hidden) // Normal Cursor Mode
{
glfwSetCursorPos(_window, double(_screenCenterWidth), double(_screenCenterHeight));
}
else // Raw Cursor mode
{
glfwSetCursorPos(_window, 0, 0);
}
return;
}
sfn SetClearColor(ro Ref(LinearColor) _colorToSet)
{
glClearColor(_colorToSet.Red, _colorToSet.Green, _colorToSet.Blue, _colorToSet.Alpha);
return;
}
sfn SetCurrentContext(ro ptr<Window> _window)
{
glfwMakeContextCurrent(_window);
ptr< RawString<const char> > ErrorMsg = NULL;
int code = glfwGetError(ErrorMsg);
if (code == GLFW_NO_WINDOW_CONTEXT)
{
throw std::runtime_error(Dref(ErrorMsg));
}
return;
}
template<typename ModeParam>
sfn SetInputMode(ro ptr<Window> _window, EMouseMode _mouseMode, ModeParam _modeParam)
{
glfwSetInputMode(_window, GLenum(_mouseMode), GLenum(_modeParam));
return;
}
sfn SetPolygonMode(EFace _desiredFaces, ERenderMode _desiredMode)
{
glPolygonMode(GLenum(_desiredFaces), GLenum(_desiredMode));
return;
}
sfn SwapBuffers(ro ptr<Window> _window) -> void
{
glfwSwapBuffers(_window);
return;
}
sfn TerminateGLFW()
{
glfwTerminate();
return;
}
// Old Tape
[[deprecated]]
sfn RunBasicWindowLoop(ro ptr<Window> _window)
{
/* Loop until the user closes the window */
while (not CanClose(_window))
{
ClearBuffer(EFrameBuffer::Color);
SwapBuffers(_window);
PollEvents();
}
return;
}
[[deprecated]]
sfn RunBasicWindowLoop_Timed(ro ptr<Window> _window, TimeValDec _interval, ro Delegate< Func<void>> _renderProcedure)
{
TimeValDec start, end, deltaSinceClear = 0.0;
while (not CanClose(_window))
{
start = GetTime();
if (deltaSinceClear > _interval)
{
ClearBuffer(EFrameBuffer::Color, EFrameBuffer::Depth);
//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.25f, 0.25f, 0.25f, 1.0f);
//glMatrixMode(GL_MODELVIEW);
//glLoadIdentity();
_renderProcedure();
SwapBuffers(_window);
PollEvents();
}
end = GetTime();
deltaSinceClear = deltaSinceClear + end - start;
}
return;
}
}

View File

@ -1,43 +1,57 @@
// Cpp STL
/*
// Project
*/
// DGL
#include "DGL.hpp"
#include "Actions.hpp"
#include "Testing.hpp"
// Utility
#include "Actions.hpp"
// Non-Standard C++
#include "Cpp_Alias.hpp"
namespace Execution
{
inline namespace Alias
inline namespace LibraryReferences
{
// DGL
using DGL::Camera ;
using DGL::ECursorMode ;
using DGL::EBool ;
using DGL::ECursorMode ;
using DGL::EDirection ;
using DGL::EFrameBuffer ;
using DGL::EKeyCodes ;
using DGL::EMouseMode ;
using DGL::EMouseMode ;
using DGL::EPrimitives ;
using DGL::ERotationAxis;
using DGL::gFloat ;
using DGL::LinearColor ;
using DGL::Matrix ;
using DGL::Matrix4x4 ;
using DGL::TimeValDec ;
using DGL::Vector3 ;
using DGL::Window ;
using DGL::SimpleShader;
using DGL::Camera ;
using DGL::Entity_Basic ;
using DGL::gFloat ;
using DGL::Light_Basic ;
using DGL::LinearColor ;
using DGL::Material_Phong;
using DGL::Matrix ;
using DGL::Matrix4x4 ;
using DGL::Model ;
using DGL::TimeValDec ;
using DGL::Vector3 ;
using DGL::Window ;
using DGL::BindVertexArray ;
using DGL::CanUseRawMouse ;
using DGL::ClearBuffer ;
using DGL::CreateWindow ;
using DGL::BindVertexArray ;
using DGL::DestoryWindow ;
using DGL::DisableVertexAttributeArray;
using DGL::EnableDepth ;
using DGL::EnableVertexAttributeArray ;
using DGL::GetCursorPosition ;
using DGL::GetTime ;
@ -80,7 +94,7 @@ namespace Execution
TimeValDec CycleStart , // Snapshot of cycle loop start time.
CycleEnd , // Snapshot of cycle loop end time.
DeltaTime , // Delta between last cycle start and end.
InputInterval = 1.0f / 400.0f, // Interval per second to complete the input process of the cycle.
InputInterval = 1.0f / 480.0f, // Interval per second to complete the input process of the cycle.
PhysicsInterval = 1.0f / 240.0f, // Interval per second to complete the physics process of the cycle.
RenderInterval = 1.0f / 144.0f ; // Interval per second to complete the render process of the cycle.
@ -90,7 +104,7 @@ namespace Execution
bool CursorOff = true;
gFloat CamMoveSpeed = 8.0f, // Rate at which the camera should move.
gFloat CamMoveSpeed = 8.0f, // Rate at which the camera should move.
CamRotationSpeed = 27.0f ; // Rate at which the camera should rotate.
TimeValDec InputDelta = 0.0, // Current delta since last input process.
@ -99,41 +113,76 @@ namespace Execution
ActionQueue ActionsToComplete; // Actions queue to run during the physics process of the cycle.
Model objectModel("torus.obj"); // Hardcoded to specified obj file for now.
Material_Phong ObjectMaterial;
Light_Basic Light ; // Hardcoded light. Rotates around object.
Entity_Basic ObjectToView; // Object that will be currently in the middle with the light source rotating.
// Functionality
// Temp fix for now... not sure how to make proper action handling that can reference member function delegates...
// Input Action common functions...
sfn RotateCamera(ERotationAxis _rotationAxis, gFloat _rotationAmount, gFloat _delta)
sfn RotateCamera(ERotationAxis _rotationAxis, gFloat _rotationAmount, double _delta)
{
WorldCamera.Rotate(_rotationAxis, _rotationAmount, _delta);
WorldCamera.Rotate(_rotationAxis, _rotationAmount, gFloat(_delta));
}
deduce RotateCamDelegate = Delegate<decltype(RotateCamera)>(RotateCamera);
sfn MoveCamera(EDirection _direction, gFloat _translationAmount, gFloat _delta)
sfn MoveCamera(EDirection _direction, gFloat _translationAmount, double _delta)
{
WorldCamera.Move(_direction, _translationAmount, _delta);
WorldCamera.Move(_direction, _translationAmount, gFloat(_delta));
}
deduce MoveCamDelegate = Delegate<decltype(MoveCamera)>(MoveCamera);
// End of temp stuff...
// This is here cause its super repetitive..
sfn ModifyCamSpeed(bool _isPositive, double _delta)
{
if (_isPositive)
{
CamMoveSpeed += CamMoveSpeed * gFloat(_delta);
}
else
{
CamMoveSpeed -= CamMoveSpeed * gFloat(_delta);
}
}
deduce ModifyCamSpeedDelegate = Delegate<decltype(ModifyCamSpeed)>(ModifyCamSpeed);
deduce SetPolyModeDelegate = Delegate<decltype(SetPolygonMode)>(SetPolygonMode);
// End of common input functions...
// Currently Does everything required before entering the cycler.
sfn PrepWorkspace()
{
// Baseline
InitalizeGLFW();
DefaultWindow = CreateWindow(ScreenWidth, ScreenHeight, "Assignment 1: Lighting Test", WindowedMode(), NotShared());
DefaultWindow = CreateWindow(ScreenWidth, ScreenHeight, "Assignment 1: Loading Model...", WindowedMode(), NotShared());
SetCurrentContext(DefaultWindow);
InitalizeGLEW(); // Glew must initialize only after a context is set.
EnableDepth();
SetPolygonMode(DGL::EFace::Front_and_Back, DGL::ERenderMode::Fill);
// Cursor stuff
SetInputMode(DefaultWindow, DGL::EMouseMode::Cursor, DGL::ECursorMode::Disable);
@ -147,25 +196,23 @@ namespace Execution
// End of cursor stuff...
// Shaders
LoadDefaultShaders();
//PrepareRenderObjects();
// Entities
SetPolygonMode(DGL::EFace::Front_and_Back, DGL::ERenderMode::Fill);
Light.Load();
RAW_MakeCube();
objectModel.Load ();
objectModel.Buffer();
RAW_MakeLightVAO();
ObjectMaterial.Color = DGL::Colors::GreyColor.Vector();
ObjectMaterial.Ambience = 0.01f ;
ObjectMaterial.Diffuse = 1.0f ;
ObjectMaterial.Specular = 0.4f ;
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);
ObjectToView = Entity_Basic(objectModel, ObjectMaterial);
}
@ -176,7 +223,7 @@ namespace Execution
Cycler is hardcoded to exit if escape key is pressed.
*/
sfn Cycler(Delegate< Func<void, ptr<Window>> > _inputProcedure, Delegate< Func<void>> _physicsProcedure, Delegate< Func<void>> _renderProcedure)
sfn Cycler(ro Ref(Delegate< Func<void, ptr<Window>> >) _inputProcedure, ro Ref(Delegate< Func<void>>) _physicsProcedure, ro Ref(Delegate< Func<void>>) _renderProcedure)
{
while (Exist)
{
@ -199,8 +246,6 @@ namespace Execution
{
ResetCursor(DefaultWindow, ScreenCenterWidth, ScreenCenterHeight);
}
InputDelta = 0.0;
}
if (PhysicsDelta >= PhysicsInterval)
@ -228,6 +273,11 @@ namespace Execution
RenderDelta = 0.0;
}
if (InputDelta >= InputInterval)
{
InputDelta = 0.0;
}
CycleEnd = GetTime();
DeltaTime = CycleEnd - CycleStart;
@ -240,24 +290,10 @@ namespace Execution
return;
}
sfn ModifyCamSpeed(bool _isPositive, gFloat _delta)
{
if (_isPositive)
{
CamMoveSpeed += CamMoveSpeed * _delta;
}
else
{
CamMoveSpeed -= CamMoveSpeed * _delta;
}
}
deduce ModifyCamSpeedDelegate = Delegate<decltype(ModifyCamSpeed)>(ModifyCamSpeed);
deduce SetPolyModeDelegate = Delegate<decltype(SetPolygonMode)>(SetPolygonMode);
sfn InputProcedure(ptr<Window> _currentWindowContext)
{
if (KeysPressed(_currentWindowContext, EKeyCodes::LeftShift, EKeyCodes::F1))
if (KeyPressed(_currentWindowContext, EKeyCodes::F1))
{
ECursorMode cursorMode = ECursorMode(GetMouseInputMode(DefaultWindow, EMouseMode::Cursor));
@ -304,12 +340,12 @@ namespace Execution
{
if (CursorX != 0)
{
ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Yaw, CursorX * CamRotationSpeed, PhysicsDelta);
ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Yaw, gFloat(CursorX) * CamRotationSpeed, PhysicsDelta);
}
if (CursorY != 0)
{
ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Pitch, CursorY * CamRotationSpeed, PhysicsDelta);
ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Pitch, gFloat(CursorY) * CamRotationSpeed, PhysicsDelta);
}
}
@ -365,15 +401,25 @@ namespace Execution
}
std::string windowTitle = "Assignment 1", deltaStr = "Delta: ", inputDeltaStr = "Input Delta: ", physicsDeltaStr = "Physics Delta: ", renderDeltaStr = "RenderDeltaStr: ";
std::string
windowTitle = "Assignment 1" ,
deltaStr = "Delta: " ,
inputDeltaStr = "Input Delta: " ,
physicsDeltaStr = "Physics Delta: " ,
renderDeltaStr = "RenderDeltaStr: " ;
std::stringstream somethingtoupdate;
sfn UpdateThisShit()
sfn UpdateWindowDeltaTitle()
{
somethingtoupdate.str("");
somethingtoupdate << windowTitle << " " << deltaStr << DeltaTime << " " << inputDeltaStr << InputDelta << " " << physicsDeltaStr << PhysicsDelta << " " << renderDeltaStr << RenderDelta;
somethingtoupdate
<< windowTitle << " "
<< deltaStr << DeltaTime << " "
<< inputDeltaStr << InputDelta << " "
<< physicsDeltaStr << PhysicsDelta << " "
<< renderDeltaStr << RenderDelta ;
}
sfn PhysicsProcedure()
@ -382,26 +428,20 @@ namespace Execution
UpdateScreenspace();
DGL::SS_Transformed::UpdateShader(Screenspace);
Light.Update();
//RAW_RotateLitCube(PhysicsDelta);
ObjectToView.Update();
RAW_UpdateLightTransform(PhysicsDelta);
ProperCube::Rotate(PhysicsDelta);
UpdateThisShit();
UpdateWindowDeltaTitle();
}
sfn RenderProcedure() -> void
{
glfwSetWindowTitle(DefaultWindow, somethingtoupdate.str().c_str());
RAW_RenderLight(WorldCamera.Perspective, WorldCamera.Viewport);
Light.Render(WorldCamera.Perspective, WorldCamera.Viewport);
ProperCube::Render(WorldCamera.Perspective, WorldCamera.Viewport, WorldCamera.Position);
ObjectToView.Render(WorldCamera.Perspective, WorldCamera.Viewport, Light.GetPosition(), Light.GetColor());
}
@ -414,6 +454,10 @@ namespace Execution
Cycler(InputProcedure, PhysicsProcedure, RenderProcedure);
// TODO: There should be more to properly close...
DestoryWindow(DefaultWindow);
TerminateGLFW();
return ExitCode::Success;
@ -421,7 +465,7 @@ namespace Execution
}
// Currently only can do one execution route.
int main(void)
{
return int(Execution::Execute());

View File

@ -5,11 +5,13 @@ out vec4 FragColor;
in vec3 FragPosition ;
in vec3 Normal ;
in vec3 LightViewPosition;
in vec3 LightRawPos ;
uniform vec3 ObjectColor;
uniform vec3 ObjectColor ;
uniform vec3 LightColor ;
uniform vec3 ViewPosition;
uniform float AmbientStrength ;
uniform float DiffuseStrength ;
uniform float SpecularStrength;
@ -17,30 +19,26 @@ void main()
{
// Ambient
float ambientStrength = 0.1;
vec3 ambient = ambientStrength * LightColor ;
vec3 ambient = AmbientStrength * LightColor ;
// Diffuse
vec3 direction = normalize(Normal );
vec3 lightDirection = normalize(LightViewPosition - FragPosition);
float diffuseStrength = max(dot(direction, lightDirection), 0.0);
vec3 diffuse = diffuseStrength * LightColor ;
float diffuseMagnitude = max(dot(direction, lightDirection), 0.0);
vec3 diffuse = DiffuseStrength * diffuseMagnitude * LightColor;
// Specular
float specularStrength = 0.5;
// vec3 viewDirection = normalize(ViewPosition - FragPosition);
vec3 viewDirection = normalize(-FragPosition);
vec3 reflectionDirection = reflect(-lightDirection, direction);
float spec = pow(max(dot(viewDirection, reflectionDirection), 0.0), 32);
vec3 specular = specularStrength * spec * LightColor;
vec3 specular = SpecularStrength * spec * LightColor;
// Combining

View File

@ -1,13 +1,16 @@
#version 330 core
layout (location = 0) in vec3 VertPosition;
layout (location = 1) in vec3 VertNormal ;
layout (location = 2) in vec3 VertTexture ;
#define VertexIndex 0
#define NormalIndex 1
#define TextureIndex 2
layout (location = VertexIndex ) in vec3 VertPosition;
layout (location = NormalIndex ) in vec3 VertNormal ;
layout (location = TextureIndex) in vec3 VertTexture ;
out vec3 FragPosition ;
out vec3 Normal ;
out vec3 LightViewPosition;
out vec3 LightRawPos;
uniform mat4 InverseModelSpace;
@ -25,9 +28,7 @@ void main()
FragPosition = vec3(Viewport * ModelSpace * vec4(VertPosition, 1.0));
Normal = mat3(transpose(inverse(Viewport * ModelSpace))) * VertNormal;
Normal = mat3(transpose(inverse(InverseModelSpace))) * VertNormal;
LightViewPosition = vec3(Viewport * vec4(LightPosition, 1.0));
LightRawPos = LightPosition;
}

View File

@ -182,14 +182,14 @@ TriTexCoords textureCoords =
sfn RAW_SetupBuffers()
{
DGL::GenerateVertexBuffers(Address(VertexArrayObj ), 1);
DGL::GenerateBuffers (Address(VertexBufferObj), 1);
DGL::GenerateBuffers (Address(ElemBufferObj ), 1);
DGL::GenerateVertexBuffers(VertexArrayObj , 1);
DGL::GenerateBuffers (VertexBufferObj, 1);
DGL::GenerateBuffers (ElemBufferObj , 1);
}
sfn RAW_SetupTriangleBuffer()
{
DGL::GenerateBuffers(Address(VertexBufferObj), 1);
DGL::GenerateBuffers(VertexBufferObj, 1);
}
sfn RAW_BindAndBufferDataToIDs()
@ -200,11 +200,11 @@ sfn RAW_BindAndBufferDataToIDs()
//GL::BufferData<TriangleRaw>(Address(EquilateralTriangleVerticies), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
DGL::BufferData<RectangleCompressed>(Address(rectCompress), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
DGL::BufferData<RectangleCompressed>(rectCompress, EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
DGL::BindBuffer(EBufferTarget::VertexIndices, ElemBufferObj);
DGL::BufferData<RectangleIndices>(Address(rectIndices), EBufferTarget::VertexIndices, EBufferUsage::StaticDraw);
DGL::BufferData<RectangleIndices>(rectIndices, EBufferTarget::VertexIndices, EBufferUsage::StaticDraw);
}
DGL::gInt VertexAttributeIndex = 0; // See shader source: (layout = 0).
@ -229,7 +229,7 @@ sfn CreateWindow_BasicLoop()
DGL::SetCurrentContext(windowObj);
DGL::RunBasicWindowLoop(windowObj);
//DGL::RunBasicWindowLoop(windowObj);
}
sfn CreateWindow_TimedRender()
@ -272,41 +272,7 @@ struct CubeElements
Edge3 front, right, back, left, bottom, top;
};
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},
// 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;
@ -324,24 +290,24 @@ ID<ElementBuffer> CubeModelElements;
sfn RAW_MakeCube()
{
DGL::GenerateVertexBuffers(Address(CubeVAO ), 1);
DGL::GenerateBuffers (Address(CubeModelBuffer ), 1);
DGL::GenerateBuffers (Address(CubeModelElements), 1);
DGL::GenerateVertexBuffers(CubeVAO , 1);
DGL::GenerateBuffers (CubeModelBuffer , 1);
DGL::GenerateBuffers (CubeModelElements, 1);
DGL::BindVertexArray(CubeVAO);
DGL::BindBuffer(EBufferTarget::VertexAttributes, CubeModelBuffer);
DGL::BufferData<CubeVerts>(Address(DefaultCube), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
DGL::BufferData<CubeVerts>(DefaultCube, EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
DGL::BindBuffer(EBufferTarget::VertexIndices, CubeModelElements);
DGL::BufferData<CubeElements>(Address(DefaultCubeElements), EBufferTarget::VertexIndices, EBufferUsage::StaticDraw);
DGL::BufferData<CubeElements>(DefaultCubeElements, EBufferTarget::VertexIndices, EBufferUsage::StaticDraw);
DGL::FormatVertexAttributes<Vertex3>(0, EDataType::Float, ZeroOffset(), Vertex3::ValueCount(), EBool::False);
DGL::FormatVertexAttributes<Vertex3>(0, EDataType::Float, ZeroOffset(), Vertex3::ValueCount(), false);
DGL::EnableVertexAttributeArray(0);
}
@ -350,18 +316,19 @@ sfn RAW_RenderCube()
{
DGL::BindBuffer(EBufferTarget::VertexIndices, CubeModelElements);
gInt Size; GetBufferParameterIV(EBufferTarget::VertexIndices, DGL::EBufferParam::Size, Address(Size));
gInt SizeRef; GetBufferParameterIV(EBufferTarget::VertexIndices, DGL::EBufferParam::Size, SizeRef);
Size /= sizeof(unsigned int);
SizeRef /= sizeof(unsigned int);
DGL::DrawElements(DGL::EPrimitives::Triangles, Size, EDataType::UnsignedInt, ZeroOffset());
DGL::DrawElements(DGL::EPrimitives::Triangles, SizeRef, EDataType::UnsignedInt, ZeroOffset());
}
LinearColor CoralColor(1.0f, 0.5f, 0.31f, 1.0f);
LinearColor SomeColor(0.60f, 0.60f, 0.60f, 1.0f);
LinearColor LightColor(1.0f, 1.0f, 1.0f , 1.0f);
Vector3 LightPosition(1.2f, 1.0f, 1.75f);
Vector3 LightPosition(0, 0, 0);
Vector3 LightScale = Vector3(0.2f);
@ -369,18 +336,20 @@ Vector3 result = LightColor.Vector() * CoralColor.Vector();
CoordSpace LightTransform = Matrix4x4(1.0f);
gFloat TranslationScale = 4.0f;
ID<VertexArray> LightVAO;
sfn RAW_MakeLightVAO()
{
DGL::GenerateVertexBuffers(Address(LightVAO), 1);
DGL::GenerateVertexBuffers(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::FormatVertexAttributes<Vertex3>(0, EDataType::Float, ZeroOffset(), Vertex3::ValueCount(), false);
DGL::EnableVertexAttributeArray(0);
@ -390,7 +359,7 @@ sfn RAW_MakeLightVAO()
sfn RAW_UpdateLightTransform(gFloat _delta)
{
static bool test = true;
/*static bool test = true;
LightTransform = CoordSpace(1.0f);
@ -417,7 +386,17 @@ sfn RAW_UpdateLightTransform(gFloat _delta)
LightTransform = DGL::Translate(LightTransform, LightPosition);
LightTransform = DGL::Scale (LightTransform, LightScale );
}
}*/
LightTransform = CoordSpace(1.0f);
LightPosition.x = TranslationScale * sin(DGL::GetTime());
LightPosition.z = TranslationScale * cos(DGL::GetTime());
LightTransform = DGL::Translate(LightTransform, LightPosition);
LightTransform = DGL::Scale (LightTransform, LightScale );
}
@ -427,7 +406,7 @@ sfn RAW_RenderLight(CoordSpace _projection, CoordSpace _viewport)
{
deduce screenspaceTransform = _projection * _viewport * LightTransform;
DGL::Basic_LampShader::SetupLampRender(screenspaceTransform);
DGL::Basic_LampShader::Use(screenspaceTransform);
DGL::BindVertexArray(LightVAO);
@ -450,21 +429,21 @@ ID<VertexArray> LitCubeVAO;
sfn RAW_MakeLitCube()
{
DGL::GenerateVertexBuffers(Address(LitCubeVAO), 1);
DGL::GenerateVertexBuffers(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::FormatVertexAttributes<Vertex3>(0, EDataType::Float, ZeroOffset(), Vertex3::ValueCount(), false);
DGL::EnableVertexAttributeArray(0);
}
sfn RAW_RotateLitCube(gFloat _delta)
{
LitCubeTransform = DGL::Rotate(LitCubeTransform, RotationRate * _delta, Vector3(0.0f, 1.0f, 0.0f));
//LitCubeTransform = DGL::Rotate(LitCubeTransform, RotationRate * _delta, Vector3(0.0f, 1.0f, 0.0f));
}
sfn RAW_RenderLitCube(CoordSpace _projection, CoordSpace _viewport)
@ -473,8 +452,6 @@ sfn RAW_RenderLitCube(CoordSpace _projection, CoordSpace _viewport)
Vector3 lightColor = LightColor.Vector();
//DGL::PhongShader::SetupRender(screenspaceTransform, LitCubeTransform, CubeColor, LightPosition, lightColor);
DGL::BindVertexArray(LitCubeVAO);
RAW_RenderCube();
@ -486,11 +463,11 @@ using DGL::NormalBuffer;
namespace ProperCube
{
Model model("topology.obj");
Model model("blenderCube2.obj");
Vector3 position = Vector3(0.0f);
Vector3 color = CoralColor.Vector();
Vector3 color = SomeColor.Vector();
CoordSpace transform = Matrix4x4(1.0f);
@ -498,7 +475,7 @@ namespace ProperCube
sfn Rotate(gFloat _delta)
{
transform = DGL::Rotate(transform, 0.75f * _delta, Vector3(0, 1, 0));
//transform = DGL::Rotate(transform, 0.75f * _delta, Vector3(0, 1, 0));
}
sfn Render(Ref(CoordSpace) _projection, Ref(CoordSpace) _viewport, Ref(Vector3) _cameraPosition)
@ -507,7 +484,7 @@ namespace ProperCube
Vector3 lightColor = LightColor.Vector();
DGL::PhongShader::Use
DGL::PhongShader::Use_Old
(
_projection ,
_viewport ,

24
blenderCube2.obj Normal file
View File

@ -0,0 +1,24 @@
# Blender v2.80 (sub 74) OBJ File: ''
# www.blender.org
o Cube
v 1.000000 1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 1.000000
v -1.000000 -1.000000 1.000000
s off
f 5 3 1
f 3 8 4
f 7 6 8
f 2 8 6
f 1 4 2
f 5 2 6
f 5 7 3
f 3 7 8
f 7 5 6
f 2 4 8
f 1 3 4
f 5 1 2