mirror of
https://github.com/Ed94/DuctTaped_GL.git
synced 2024-12-22 15:04:47 -08:00
Appied some gafting tape, getting ready to do lighting as well.
This commit is contained in:
parent
b3b81b65fe
commit
98851f32a4
119
Actions.hpp
Normal file
119
Actions.hpp
Normal file
@ -0,0 +1,119 @@
|
||||
/*
|
||||
Title : Actions
|
||||
Author: Edward R. Gonzalez
|
||||
|
||||
Description: This was a little experiment of mine to mess with action binding...
|
||||
|
||||
Allows for non-member functions to be binded to an action, implements a functioning queue as well.
|
||||
|
||||
TODO: Possibly add support for member functions. Have it so that deduction of delegate typef is not required to add to queue properly (right now it does, see input procedure for example);
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Cpp_Alias.hpp"
|
||||
|
||||
|
||||
|
||||
namespace Actions
|
||||
{
|
||||
struct IAction
|
||||
{
|
||||
virtual void DoAction() = NULL;
|
||||
};
|
||||
|
||||
template<typename FunctionType, typename... ActionParams>
|
||||
struct AAction : IAction
|
||||
{
|
||||
using ActionType = Delegate< FunctionType >;
|
||||
|
||||
public:
|
||||
AAction(ActionType _actionToAssign, ActionParams... _params) :
|
||||
action(_actionToAssign),
|
||||
params(_params...)
|
||||
{};
|
||||
|
||||
private:
|
||||
using IndexType = DataSize;
|
||||
|
||||
void DoAction_Implementation(ActionParams... _params) { action(_params...); }
|
||||
|
||||
template<IndexType... TuplePackIndex> // TuplePackSequence<TuplePackIndex...>
|
||||
void ExpandTuple_CallDoActionImplementaiton(const Ref(Tuple<ActionParams...>) _paramsToExpand, std::index_sequence <TuplePackIndex...>)
|
||||
{
|
||||
// ExpandTuplePack<TuplePackIndex>
|
||||
DoAction_Implementation(std::get <TuplePackIndex>(_paramsToExpand)...);
|
||||
}
|
||||
|
||||
Tuple<ActionParams...> params;
|
||||
|
||||
ActionType action;
|
||||
|
||||
public: // IAction
|
||||
|
||||
virtual void DoAction() override
|
||||
{
|
||||
ExpandTuple_CallDoActionImplementaiton
|
||||
(
|
||||
params,
|
||||
// MakeTuplePackSequence <ActionParams...>()
|
||||
std::index_sequence_for<ActionParams...>()
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
struct ActionQueue
|
||||
{
|
||||
sfn HasAction()
|
||||
{
|
||||
return actionQueue.size() > 0;
|
||||
}
|
||||
|
||||
template<typename FunctionType, typename... ActionParams>
|
||||
sfn AddToQueue(Delegate< FunctionType> _actionToQueue, ActionParams... _paramsForAction)
|
||||
{
|
||||
// This is extremely inefficient, but in order to fix requires an object pool or something else...
|
||||
SPtr< AAction<FunctionType, ActionParams...> > ptrToAction = MakeSPtr< AAction<FunctionType, ActionParams...> >(_actionToQueue, _paramsForAction...);
|
||||
|
||||
if (HasAction())
|
||||
{
|
||||
bool found = false;
|
||||
|
||||
using Element = decltype(actionQueue.begin());
|
||||
|
||||
for (Element element = actionQueue.begin(); element != actionQueue.end(); element++)
|
||||
{
|
||||
if ((*element).get() == ptrToAction.get())
|
||||
{
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (not found)
|
||||
{
|
||||
actionQueue.push_front(std::move(ptrToAction));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
actionQueue.push_front(std::move(ptrToAction));
|
||||
}
|
||||
}
|
||||
|
||||
sfn DoNextAction()
|
||||
{
|
||||
if (actionQueue.size() > 0)
|
||||
{
|
||||
actionQueue.back()->DoAction();
|
||||
|
||||
actionQueue.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
using QueueType = std::deque< SPtr<IAction>>;
|
||||
|
||||
QueueType actionQueue;
|
||||
};
|
||||
}
|
@ -12,19 +12,22 @@ This merely removes the need to use operators I don't like and wraps them in eas
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdarg>
|
||||
#include <exception>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#include <memory>
|
||||
#include <algorithm >
|
||||
#include <chrono >
|
||||
#include <cstdarg >
|
||||
#include <exception >
|
||||
#include <fstream >
|
||||
#include <functional>
|
||||
#include <iostream >
|
||||
#include <memory >
|
||||
#include <queue >
|
||||
#include <sstream >
|
||||
#include <stdexcept >
|
||||
#include <string >
|
||||
#include <vector >
|
||||
#include <thread >
|
||||
#include <tuple >
|
||||
#include <utility >
|
||||
|
||||
|
||||
|
||||
@ -43,12 +46,15 @@ _type&
|
||||
_type&&
|
||||
|
||||
|
||||
|
||||
// Aliases
|
||||
|
||||
// Fundamental
|
||||
|
||||
using uInt64 = unsigned long long int;
|
||||
|
||||
|
||||
|
||||
// Pointers
|
||||
|
||||
template<typename Type>
|
||||
@ -63,12 +69,31 @@ 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
|
||||
|
||||
template<typename CharType>
|
||||
using RawString = ptr<CharType>;
|
||||
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using DataSize = std::size_t;
|
||||
|
||||
using Thread = std::thread;
|
||||
|
||||
template<typename... ObjectTypes>
|
||||
using Tuple = std::tuple<ObjectTypes...>;
|
||||
|
||||
|
||||
|
||||
// Enum
|
||||
|
||||
enum class ExitCode
|
||||
@ -78,6 +103,7 @@ enum class ExitCode
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Functions
|
||||
|
||||
// Ptr
|
||||
@ -94,6 +120,19 @@ sfn Dref(ptr<Type> _type) -> Ref(Type)
|
||||
return *_type;
|
||||
}
|
||||
|
||||
template<typename Type, typename... ParamTypes>
|
||||
sfn MakeUPtr(rRef(ParamTypes)... _params) -> UPtr<Type>
|
||||
{
|
||||
return std::make_unique<Type>(_params...);
|
||||
}
|
||||
|
||||
template<typename Type, typename... ParamTypes>
|
||||
sfn MakeSPtr(rRef(ParamTypes)... _params) -> SPtr<Type>
|
||||
{
|
||||
return std::make_shared<Type>(_params...);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Exit
|
||||
|
||||
|
93
DGL.hpp
93
DGL.hpp
@ -1,12 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
// GL
|
||||
//#include <gl/GLU.h>
|
||||
#include <glew.h>
|
||||
#include <glfw3.h>
|
||||
#include <glm/glm.hpp>
|
||||
// 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_Enum.hpp"
|
||||
@ -63,6 +63,11 @@ namespace DGL
|
||||
return glfwWindowShouldClose(_theWindow);
|
||||
}
|
||||
|
||||
sfn CanUseRawMouse()
|
||||
{
|
||||
return glfwRawMouseMotionSupported();
|
||||
}
|
||||
|
||||
sfn CreateWindow
|
||||
(
|
||||
int _width,
|
||||
@ -92,6 +97,11 @@ namespace DGL
|
||||
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());
|
||||
@ -109,16 +119,6 @@ namespace DGL
|
||||
return;
|
||||
}
|
||||
|
||||
sfn CanUseRawMouse()
|
||||
{
|
||||
return glfwRawMouseMotionSupported();
|
||||
}
|
||||
|
||||
sfn CursorPositionUpdateBind(ptr<Window> _window, FnPtr<void, double, double> _functionToCall)
|
||||
{
|
||||
glfwSetCursorPosCallback(_window, GLFWcursorposfun(_functionToCall));
|
||||
}
|
||||
|
||||
sfn DrawArrays(EPrimitives _primitive, gInt _startingIndex, gInt _numToRender)
|
||||
{
|
||||
glDrawArrays(GLenum(_primitive), _startingIndex, _numToRender); // Starting from vertex 0; 3 vertices total -> 1 triangle.
|
||||
@ -129,15 +129,9 @@ namespace DGL
|
||||
glDrawElements(GLenum(_primitive), _numElements, GLenum(_dataType), _offfsetAddressFromFirstIndex);
|
||||
}
|
||||
|
||||
sfn KeyPressed(ptr<Window> _contextWindowRef, EKeyCodes _keyToCheck) -> bool
|
||||
sfn GetCursorPosition(ptr<Window> _window, ptr<double> _xAxis, ptr<double> _yAxis)
|
||||
{
|
||||
return glfwGetKey(_contextWindowRef, int(_keyToCheck)) ;
|
||||
}
|
||||
|
||||
template<typename... CodeType, typename = EKeyCodes>
|
||||
sfn KeysPressed(ptr<Window> _contextWindowRef, CodeType... _otherKeys) -> bool
|
||||
{
|
||||
return ( KeyPressed(_contextWindowRef, _otherKeys) && ... ) == true;
|
||||
glfwGetCursorPos(_window, _xAxis, _yAxis);
|
||||
}
|
||||
|
||||
sfn GetMouseInputMode(ptr<Window> _contextWindowRef, EMouseMode _mode)
|
||||
@ -145,27 +139,14 @@ namespace DGL
|
||||
return glfwGetInputMode(_contextWindowRef, GLenum(_mode));
|
||||
}
|
||||
|
||||
sfn GetTime() -> TimeValDec
|
||||
{
|
||||
return glfwGetTime();
|
||||
}
|
||||
|
||||
sfn GetRawTime() -> TimeValInt
|
||||
{
|
||||
return glfwGetTimerValue();
|
||||
}
|
||||
|
||||
sfn GetCursorPosition(ptr<Window> _window, ptr<double> _xAxis, ptr<double> _yAxis)
|
||||
sfn GetTime() -> TimeValDec
|
||||
{
|
||||
glfwGetCursorPos(_window, _xAxis, _yAxis);
|
||||
}
|
||||
|
||||
sfn ResetCursor(ptr<Window> _window, gFloat _screenCenterWidth, gFloat _screenCenterHeight)
|
||||
{
|
||||
glfwSetCursorPos(_window, _screenCenterWidth, _screenCenterHeight);
|
||||
|
||||
|
||||
glfwSetCursorPos(_window, 0, 0);
|
||||
return glfwGetTime();
|
||||
}
|
||||
|
||||
sfn InitalizeGLFW()
|
||||
@ -219,6 +200,17 @@ namespace DGL
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
@ -226,6 +218,14 @@ namespace DGL
|
||||
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 */
|
||||
@ -280,17 +280,6 @@ namespace DGL
|
||||
glClearColor(_colorToSet.Red, _colorToSet.Green, _colorToSet.Blue, _colorToSet.Alpha);
|
||||
}
|
||||
|
||||
template<typename ModeParam>
|
||||
sfn SetInputMode(ptr<Window> _window, EMouseMode _mouseMode, ModeParam _modeParam)
|
||||
{
|
||||
glfwSetInputMode(_window, GLenum(_mouseMode), GLenum(_modeParam));
|
||||
}
|
||||
|
||||
sfn RunTimingLoop()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
sfn SetCurrentContext(const ptr<Window> _window)
|
||||
{
|
||||
try
|
||||
@ -316,6 +305,12 @@ namespace DGL
|
||||
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));
|
||||
|
45
DGL_Enum.hpp
45
DGL_Enum.hpp
@ -12,33 +12,12 @@ namespace DGL
|
||||
X, Y, Z
|
||||
};
|
||||
|
||||
enum class ERotationAxis
|
||||
{
|
||||
Pitch, Yaw, Roll
|
||||
};
|
||||
|
||||
enum class EBool
|
||||
{
|
||||
True = GL_TRUE ,
|
||||
False = GL_FALSE
|
||||
};
|
||||
|
||||
enum class EMouseMode
|
||||
{
|
||||
Cursor = GLFW_CURSOR ,
|
||||
RawMouse = GLFW_RAW_MOUSE_MOTION ,
|
||||
StickyKeys = GLFW_STICKY_KEYS ,
|
||||
StickMouse = GLFW_STICKY_MOUSE_BUTTONS,
|
||||
LockKey = GLFW_LOCK_KEY_MODS ,
|
||||
};
|
||||
|
||||
enum class ECursorMode
|
||||
{
|
||||
Normal = GLFW_CURSOR_NORMAL ,
|
||||
Hidden = GLFW_CURSOR_HIDDEN ,
|
||||
Disable = GLFW_CURSOR_DISABLED
|
||||
};
|
||||
|
||||
enum class EBufferTarget
|
||||
{
|
||||
VertexAttributes = GL_ARRAY_BUFFER ,
|
||||
@ -78,6 +57,13 @@ namespace DGL
|
||||
None = GL_NONE
|
||||
};
|
||||
|
||||
enum class ECursorMode
|
||||
{
|
||||
Normal = GLFW_CURSOR_NORMAL ,
|
||||
Hidden = GLFW_CURSOR_HIDDEN ,
|
||||
Disable = GLFW_CURSOR_DISABLED
|
||||
};
|
||||
|
||||
enum class EDataType
|
||||
{
|
||||
Byte = GL_BYTE ,
|
||||
@ -126,7 +112,8 @@ namespace DGL
|
||||
Q = GLFW_KEY_Q ,
|
||||
S = GLFW_KEY_S ,
|
||||
W = GLFW_KEY_W ,
|
||||
LeftShift = GLFW_KEY_LEFT_SHIFT
|
||||
LeftShift = GLFW_KEY_LEFT_SHIFT,
|
||||
Escape = GLFW_KEY_ESCAPE
|
||||
};
|
||||
|
||||
enum class EKeyState
|
||||
@ -156,6 +143,15 @@ namespace DGL
|
||||
LinearToLinear = GL_LINEAR_MIPMAP_LINEAR
|
||||
};
|
||||
|
||||
enum class EMouseMode
|
||||
{
|
||||
Cursor = GLFW_CURSOR ,
|
||||
RawMouse = GLFW_RAW_MOUSE_MOTION ,
|
||||
StickyKeys = GLFW_STICKY_KEYS ,
|
||||
StickMouse = GLFW_STICKY_MOUSE_BUTTONS,
|
||||
LockKey = GLFW_LOCK_KEY_MODS ,
|
||||
};
|
||||
|
||||
enum class ERenderMode
|
||||
{
|
||||
Point = GL_POINT,
|
||||
@ -163,7 +159,10 @@ namespace DGL
|
||||
Fill = GL_FILL
|
||||
};
|
||||
|
||||
|
||||
enum class ERotationAxis
|
||||
{
|
||||
Pitch, Yaw, Roll
|
||||
};
|
||||
|
||||
enum class EPrimitives
|
||||
{
|
||||
|
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
// OpenGL
|
||||
#include <glew.h>
|
||||
#include <glew.h >
|
||||
#include <glm/detail/type_vec3.hpp>
|
||||
|
||||
|
||||
@ -37,11 +37,11 @@ namespace DGL
|
||||
|
||||
// ID Reference Types
|
||||
|
||||
class Buffer;
|
||||
class Matrix;
|
||||
class Shader;
|
||||
class Buffer ;
|
||||
class Matrix ;
|
||||
class Shader ;
|
||||
class ShaderProgram;
|
||||
class VertexBuffer;
|
||||
class VertexBuffer ;
|
||||
class ElementBuffer;
|
||||
|
||||
using Matrix4x4 = glm::mat4;
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
namespace DGL
|
||||
{
|
||||
|
||||
|
114
DGL_Shader.hpp
114
DGL_Shader.hpp
@ -37,18 +37,16 @@ namespace DGL
|
||||
// Default Shaders
|
||||
|
||||
ID<ShaderProgram> RawShader ,
|
||||
SimpleShader ,
|
||||
SimpleShader_Transformed ;
|
||||
SimpleShader ;
|
||||
|
||||
ID<CoordSpace> ScreenSpaceVarID;
|
||||
|
||||
|
||||
// Forward Declarations
|
||||
|
||||
sfn GetShaderInfo ( ID<Shader > _shader , gSize _logLength , ptr<gSize> _infoLengthRef , RawString<gChar> _infoLogRef) -> 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, 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 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;
|
||||
|
||||
|
||||
|
||||
@ -60,7 +58,7 @@ namespace DGL
|
||||
|
||||
glGetProgramiv(_shaderToQueryForUniforms, GL_ACTIVE_UNIFORMS, &uniforms);
|
||||
|
||||
for (int i = 0; i < uniforms; i++)
|
||||
for (int uniformIndex = 0; uniformIndex < uniforms; uniformIndex++)
|
||||
{
|
||||
int name_len = -1, num = -1;
|
||||
|
||||
@ -68,7 +66,7 @@ namespace DGL
|
||||
|
||||
char name[100];
|
||||
|
||||
glGetActiveUniform(_shaderToQueryForUniforms, GLuint(i), sizeof(name) - 1, &name_len, &num, &type, name);
|
||||
glGetActiveUniform(_shaderToQueryForUniforms, GLuint(uniformIndex), sizeof(name) - 1, &name_len, &num, &type, name);
|
||||
|
||||
name[name_len] = 0;
|
||||
}
|
||||
@ -264,47 +262,6 @@ namespace DGL
|
||||
}
|
||||
}
|
||||
|
||||
sfn LoadRawShader()
|
||||
{
|
||||
ID<Shader> VertexShader ;
|
||||
ID<Shader> FragmentShader;
|
||||
|
||||
MakeShader(VertexShader , EShaderType::Vertex , 1, Address(DGL::RawVertextShaderSource ), NULL);
|
||||
MakeShader(FragmentShader, EShaderType::Fragment, 1, Address(DGL::RawFragmentShaderSource), NULL);
|
||||
|
||||
DGL::MakeShaderProgram(RawShader, VertexShader, FragmentShader);
|
||||
|
||||
DGL::DeleteShader(VertexShader );
|
||||
DGL::DeleteShader(FragmentShader);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sfn LoadSimpleShader()
|
||||
{
|
||||
SimpleShader = LoadShaders("SimpleVertexShader.vert", "SimpleFragmentShader.frag");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sfn LoadSimpleShader_Transformed()
|
||||
{
|
||||
SimpleShader_Transformed = LoadShaders("SimpleTransform.vert", "SingleColor.frag");
|
||||
|
||||
ScreenSpaceVarID = DGL::GetUniformVariable(DGL::SimpleShader_Transformed, "modelViewProjection");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sfn LoadDefaultShaders()
|
||||
{
|
||||
LoadRawShader ();
|
||||
LoadSimpleShader ();
|
||||
LoadSimpleShader_Transformed();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sfn MakeShader
|
||||
(
|
||||
Ref(ID<Shader>) _shaderIDHolder ,
|
||||
@ -363,7 +320,8 @@ namespace DGL
|
||||
return;
|
||||
}
|
||||
|
||||
sfn SetUniformVariable_MatrixVariableArray(const ID<Matrix> _matrixID, const gSize _numMatricies, const EBool _shouldTransposeValues, ptr<const float> _dataPtr)
|
||||
// MVA: MatrixVariableArray
|
||||
sfn SetUniformVariable_MVA(const ID<Matrix> _matrixID, const gSize _numMatricies, const EBool _shouldTransposeValues, ptr<const float> _dataPtr)
|
||||
{
|
||||
glUniformMatrix4fv(_matrixID, _numMatricies, GLenum(_shouldTransposeValues), _dataPtr);
|
||||
|
||||
@ -376,4 +334,60 @@ namespace DGL
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
namespace SS_Transformed
|
||||
{
|
||||
ID<ShaderProgram> Shader;
|
||||
|
||||
ID<CoordSpace> ScreenSpaceVarID;
|
||||
|
||||
sfn UpdateShader(Ref(CoordSpace) _screenSpace)
|
||||
{
|
||||
SetUniformVariable_MVA(ScreenSpaceVarID, 1, DGL::EBool::False, Address(_screenSpace[0][0]));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sfn LoadShader()
|
||||
{
|
||||
Shader = LoadShaders("SimpleTransform.vert", "SingleColor.frag");
|
||||
|
||||
ScreenSpaceVarID = DGL::GetUniformVariable(Shader, "ScreenSpaceTransform");
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
sfn LoadRawShader()
|
||||
{
|
||||
ID<Shader> VertexShader;
|
||||
ID<Shader> FragmentShader;
|
||||
|
||||
MakeShader(VertexShader, EShaderType::Vertex, 1, Address(DGL::RawVertextShaderSource), NULL);
|
||||
MakeShader(FragmentShader, EShaderType::Fragment, 1, Address(DGL::RawFragmentShaderSource), NULL);
|
||||
|
||||
MakeShaderProgram(RawShader, VertexShader, FragmentShader);
|
||||
|
||||
DeleteShader(VertexShader);
|
||||
DeleteShader(FragmentShader);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sfn LoadSimpleShader()
|
||||
{
|
||||
SimpleShader = LoadShaders("SimpleVertexShader.vert", "SimpleFragmentShader.frag");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sfn LoadDefaultShaders()
|
||||
{
|
||||
LoadRawShader ();
|
||||
LoadSimpleShader();
|
||||
SS_Transformed::LoadShader ();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
101
DGL_Space.hpp
101
DGL_Space.hpp
@ -1,6 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
// GLM
|
||||
#include <glm/glm.hpp >
|
||||
#include <glm/ext/matrix_clip_space.hpp>
|
||||
#include <glm/ext/matrix_transform.hpp >
|
||||
|
||||
// DGL
|
||||
#include "DGL_FundamentalTypes.hpp"
|
||||
#include "DGL_MiscTypes.hpp"
|
||||
|
||||
@ -45,9 +50,14 @@ namespace DGL
|
||||
return glm::perspective(_fieldOfView, _aspectRatio, _nearPlane, _farPlane);
|
||||
}
|
||||
|
||||
sfn Translate(const Matrix4x4 _matrix, Vector3 _translationAmount)
|
||||
sfn GetCrossNormal(Vector3 _subj, Vector3 _ref) -> Vector3
|
||||
{
|
||||
return glm::translate(_matrix, _translationAmount);
|
||||
return glm::cross(_subj, _ref);
|
||||
}
|
||||
|
||||
sfn GetDirection(Vector3 _vectorSpecified)
|
||||
{
|
||||
return glm::normalize(_vectorSpecified);
|
||||
}
|
||||
|
||||
sfn Rotate(const Matrix4x4 _matrix, gFloat _rotationAngleAmount, Vector3 _axis) -> Matrix4x4
|
||||
@ -61,14 +71,9 @@ namespace DGL
|
||||
return glm::radians(_degrees);
|
||||
}
|
||||
|
||||
sfn GetCrossNormal(Vector3 _subj, Vector3 _ref) -> Vector3
|
||||
sfn Translate(const Matrix4x4 _matrix, Vector3 _translationAmount)
|
||||
{
|
||||
return glm::cross(_subj, _ref);
|
||||
}
|
||||
|
||||
sfn GetDirection(Vector3 _vectorSpecified)
|
||||
{
|
||||
return glm::normalize(_vectorSpecified);
|
||||
return glm::translate(_matrix, _translationAmount);
|
||||
}
|
||||
|
||||
|
||||
@ -97,8 +102,6 @@ namespace DGL
|
||||
gFloat ScreenWidth = 720.0f, ScreenHeight = 540.0f, ScreenCenterWidth = ScreenWidth / 2, ScreenCenterHeight = ScreenHeight / 2;
|
||||
}
|
||||
|
||||
using std::cout; using std::endl;
|
||||
|
||||
struct Camera
|
||||
{
|
||||
gFloat AspectRatio, FieldOfView, Yaw, Pitch, Roll;
|
||||
@ -130,16 +133,10 @@ namespace DGL
|
||||
UpDirection (_upDirection ),
|
||||
FrontDirection(_frontDirection)
|
||||
{
|
||||
std::cout << UpDirection.x << ", " << UpDirection.y << ", " << UpDirection.z << std::endl;
|
||||
|
||||
Yaw = -90.0f; Pitch = 0; Roll = 0;
|
||||
|
||||
//Yaw = 0;
|
||||
|
||||
UpdateCamera();
|
||||
|
||||
std::cout << UpDirection.x << ", " << UpDirection.y << ", " << UpDirection.z << std::endl;
|
||||
|
||||
Orthographic = CreateOrthographic(0.0f, DefaultSpace::ScreenWidth, 0.0f, DefaultSpace::ScreenHeight, ClipSpace.Near, ClipSpace.Far);
|
||||
|
||||
Perspective = CreatePerspective<gFloat>(ToRadians(FieldOfView), AspectRatio, ClipSpace.Near, ClipSpace.Far);
|
||||
@ -152,49 +149,37 @@ namespace DGL
|
||||
{
|
||||
case EDirection::Up:
|
||||
{
|
||||
Position += UpDirection * _translationAmount * _deltaTime;
|
||||
|
||||
LookAtPosition += UpDirection * _translationAmount * _deltaTime;
|
||||
Position -= UpDirection * _translationAmount * _deltaTime;
|
||||
|
||||
break;
|
||||
}
|
||||
case EDirection::Down:
|
||||
{
|
||||
Position -= UpDirection * _translationAmount * _deltaTime;
|
||||
|
||||
LookAtPosition -= UpDirection * _translationAmount * _deltaTime;
|
||||
Position += UpDirection * _translationAmount * _deltaTime;
|
||||
|
||||
break;
|
||||
}
|
||||
case EDirection::Left:
|
||||
{
|
||||
Position += GetDirection(GetCrossNormal(FrontDirection, UpDirection)) * _translationAmount * _deltaTime;
|
||||
|
||||
//LookAtPosition += GetDirection(GetCrossNormal(FrontDirection, UpDirection)) * _translationAmount * _deltaTime;
|
||||
Position -= GetDirection(GetCrossNormal(FrontDirection, UpDirection)) * _translationAmount * _deltaTime;
|
||||
|
||||
break;
|
||||
}
|
||||
case EDirection::Right:
|
||||
{
|
||||
Position -= GetDirection(GetCrossNormal(FrontDirection, UpDirection)) * _translationAmount * _deltaTime;
|
||||
|
||||
//LookAtPosition -= GetDirection(GetCrossNormal(FrontDirection, UpDirection)) * _translationAmount * _deltaTime;
|
||||
Position += GetDirection(GetCrossNormal(FrontDirection, UpDirection)) * _translationAmount * _deltaTime;
|
||||
|
||||
break;
|
||||
}
|
||||
case EDirection::Forward:
|
||||
{
|
||||
Position -= FrontDirection * _translationAmount * _deltaTime;
|
||||
|
||||
LookAtPosition -= FrontDirection * _translationAmount * _deltaTime;
|
||||
Position += FrontDirection * _translationAmount * _deltaTime;
|
||||
|
||||
break;
|
||||
}
|
||||
case EDirection::Backward:
|
||||
{
|
||||
Position += FrontDirection * _translationAmount * _deltaTime;
|
||||
|
||||
LookAtPosition += FrontDirection * _translationAmount * _deltaTime;
|
||||
Position -= FrontDirection * _translationAmount * _deltaTime;
|
||||
|
||||
break;
|
||||
}
|
||||
@ -203,11 +188,15 @@ namespace DGL
|
||||
throw std::logic_error("Direction move not defined.");
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sfn Move(Vector3 _translationAmount, Ref(gFloat) _deltaTime)
|
||||
{
|
||||
Position += _translationAmount * _deltaTime;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sfn Rotate(ERotationAxis _pivot, gFloat _rotationAmount, gFloat _deltaTime)
|
||||
@ -227,8 +216,6 @@ namespace DGL
|
||||
Pitch = -89.9f;
|
||||
}
|
||||
|
||||
//std::cout << "Pitch: " << Pitch << std::endl;
|
||||
|
||||
break;
|
||||
}
|
||||
case ERotationAxis::Roll:
|
||||
@ -250,34 +237,16 @@ namespace DGL
|
||||
{
|
||||
Yaw += _rotationAmount * _deltaTime;
|
||||
|
||||
/*if (Yaw > 89.9f)
|
||||
{
|
||||
Yaw = 89.9f;
|
||||
}
|
||||
else if (Yaw < -89.9f)
|
||||
{
|
||||
Pitch = -89.9f;
|
||||
}*/
|
||||
|
||||
//std::cout << "Yaw: " << Yaw << std::endl;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*std::cout << "Front Direction: " << FrontDirection.x << ", " << FrontDirection.y << ", " << FrontDirection.z << std::endl;
|
||||
std::cout << "Right Direction: " << RightDirection.x << ", " << RightDirection.y << ", " << RightDirection.z << std::endl;
|
||||
std::cout << "Up Direction: " << UpDirection.x << ", " << UpDirection.y << ", " << UpDirection.z << std::endl;*/
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
sfn UpdateCamera() -> void
|
||||
{
|
||||
//cout << Pitch << Yaw << Roll << endl;
|
||||
|
||||
//cout << "Cosine: " << Cosine(ToRadians(Yaw)) << endl;
|
||||
|
||||
FrontDirection.x = Cosine(ToRadians(Yaw )) * Cosine(ToRadians(Pitch));
|
||||
FrontDirection.y = Sine (ToRadians(Pitch)) ;
|
||||
FrontDirection.z = Sine (ToRadians(Yaw )) * Cosine(ToRadians(Pitch));
|
||||
@ -286,19 +255,11 @@ namespace DGL
|
||||
RightDirection = GetDirection(GetCrossNormal(FrontDirection, DefaultSpace::UpDirection ));
|
||||
UpDirection = GetDirection(GetCrossNormal(RightDirection, FrontDirection));
|
||||
|
||||
//Matrix4x4 mRoll = glm::rotate(mRoll , Roll , DefaultSpace::FrontDirection);
|
||||
//Matrix4x4 mPitch = glm::rotate(mPitch, Pitch, DefaultSpace::RightDirection);
|
||||
//Matrix4x4 mYaw = glm::rotate(mYaw , Roll , DefaultSpace::UpDirection );
|
||||
LookAtPosition = Position + FrontDirection;
|
||||
|
||||
//Matrix4x4 rotation = mPitch * mYaw;
|
||||
Viewport = CreateLookAtView(Position, LookAtPosition, UpDirection);
|
||||
|
||||
Viewport = CreateLookAtView(Position, LookAtPosition - FrontDirection, UpDirection);
|
||||
|
||||
//glm::mat4 translate = glm::mat4(1.0f);
|
||||
|
||||
//translate = glm::translate(translate, -LookAtPosition);
|
||||
|
||||
//Viewport = rotation * translate;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
@ -321,9 +282,9 @@ namespace DGL
|
||||
|
||||
sfn UpdateScreenspace()
|
||||
{
|
||||
//Screenspace = WorldCamera.Perspective * WorldCamera.Viewport * WorldSpace;
|
||||
Screenspace = WorldCamera.Perspective * WorldCamera.Viewport * WorldSpace;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
420
Execution.cpp
420
Execution.cpp
@ -2,225 +2,212 @@
|
||||
|
||||
// Project
|
||||
#include "DGL.hpp"
|
||||
#include "TriangleRaw.hpp"
|
||||
#include "Actions.hpp"
|
||||
#include "Testing.hpp"
|
||||
|
||||
#include "Cpp_Alias.hpp"
|
||||
|
||||
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
|
||||
namespace Execution
|
||||
{
|
||||
// C++ STL
|
||||
|
||||
using std::thread;
|
||||
|
||||
|
||||
|
||||
template<typename Type>
|
||||
using UPtr = std::unique_ptr<Type>;
|
||||
|
||||
template<typename Type, typename... ParamTypes>
|
||||
sfn MakeUPtr(rRef(ParamTypes)... _params) -> UPtr<Type>
|
||||
inline namespace Alias
|
||||
{
|
||||
return std::make_unique<Type>(_params...);
|
||||
}
|
||||
// DGL
|
||||
|
||||
|
||||
|
||||
// GL
|
||||
|
||||
using DGL::TimeValDec;
|
||||
using DGL::Window ;
|
||||
using DGL::Camera ;
|
||||
using DGL::ECursorMode ;
|
||||
using DGL::EDirection ;
|
||||
using DGL::EFrameBuffer ;
|
||||
using DGL::EKeyCodes ;
|
||||
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::gFloat ;
|
||||
using DGL::Window ;
|
||||
|
||||
using DGL::SimpleShader;
|
||||
|
||||
bool Exist = true;
|
||||
using DGL::CanUseRawMouse ;
|
||||
using DGL::ClearBuffer ;
|
||||
using DGL::CreateWindow ;
|
||||
using DGL::BindVertexArray ;
|
||||
using DGL::DisableVertexAttributeArray;
|
||||
using DGL::EnableVertexAttributeArray ;
|
||||
using DGL::GetCursorPosition ;
|
||||
using DGL::GetTime ;
|
||||
using DGL::InitalizeGLEW ;
|
||||
using DGL::InitalizeGLFW ;
|
||||
using DGL::KeyPressed ;
|
||||
using DGL::NotShared ;
|
||||
using DGL::PollEvents ;
|
||||
using DGL::ResetCursor ;
|
||||
using DGL::SetClearColor ;
|
||||
using DGL::SetCurrentContext ;
|
||||
using DGL::SetInputMode ;
|
||||
using DGL::SetPolygonMode ;
|
||||
using DGL::SetUniformVariable_MVA ;
|
||||
using DGL::SwapBuffers ;
|
||||
using DGL::UseProgramShader ;
|
||||
using DGL::TerminateGLFW ;
|
||||
using DGL::WindowedMode ;
|
||||
|
||||
TimeValDec CycleStart, CycleEnd, DeltaTime, InputPollingInterval = 1.0f / 240.0f, PhysicsInterval = 1.0f / 120.0f, RenderInterval = 1.0f / 60.0f;
|
||||
using DGL::DefaultSpace::ScreenWidth ;
|
||||
using DGL::DefaultSpace::ScreenHeight ;
|
||||
using DGL::DefaultSpace::ScreenCenterHeight;
|
||||
using DGL::DefaultSpace::ScreenCenterWidth ;
|
||||
using DGL::DefaultSpace::Screenspace ;
|
||||
using DGL::DefaultSpace::WorldCamera ;
|
||||
|
||||
UPtr<thread> BasicLoop, BasicTimedLoop;
|
||||
using DGL::DefaultSpace::UpdateScreenspace;
|
||||
|
||||
ptr<Window> DefaultWindow;
|
||||
// Actions
|
||||
|
||||
|
||||
gFloat CamMoveSpeed = 3.0f, CamRotationSpeed = 1.0f;
|
||||
|
||||
|
||||
|
||||
enum class CameraActions
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
enum class EMovement
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
template<typename Device>
|
||||
struct ActionBind
|
||||
{
|
||||
|
||||
|
||||
Delegate< Func<void>> Action;
|
||||
};
|
||||
|
||||
|
||||
|
||||
struct Keyboard
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
struct ActionBinds
|
||||
{
|
||||
static ActionBind<Keyboard> MoveFoward;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Testing
|
||||
|
||||
// Forward Declares
|
||||
|
||||
sfn RenderProcedure () -> void;
|
||||
sfn PrepareRenderObjects() -> void;
|
||||
|
||||
sfn CreateWindow_BasicLoop()
|
||||
{
|
||||
DGL::InitalizeGLFW();
|
||||
|
||||
deduce windowObj = DGL::CreateWindow(720, 540, "Assignment 1: RawLoop", DGL::WindowedMode(), DGL::NotShared());
|
||||
|
||||
DGL::SetCurrentContext(windowObj);
|
||||
|
||||
DGL::RunBasicWindowLoop(windowObj);
|
||||
using Actions::ActionQueue;
|
||||
}
|
||||
|
||||
sfn CreateWindow_TimedRender()
|
||||
|
||||
// Globals
|
||||
|
||||
bool Exist = true; // Determines if the the execution should exit cycler.
|
||||
|
||||
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 / 240.0f, // Interval per second to complete the input process of the cycle.
|
||||
PhysicsInterval = 1.0f / 120.0f, // Interval per second to complete the physics process of hte cycle.
|
||||
RenderInterval = 1.0f / 60.0f ; // Interval per second to complete the render process of the cycle.
|
||||
|
||||
ptr<Window> DefaultWindow; // Default window to use for execution.
|
||||
|
||||
double CursorX, CursorY; // Cursor axis position on the window.
|
||||
|
||||
gFloat CamMoveSpeed = 8.0f, // Rate at which the camera should move.
|
||||
CamRotationSpeed = 5.0f ; // Rate at which the camera should rotate.
|
||||
|
||||
TimeValDec InputDelta = 0.0, // Current delta since last input process.
|
||||
PhysicsDelta = 0.0, // Current delta since last physics process.
|
||||
RenderDelta = 0.0 ; // Current delta since last render process.
|
||||
|
||||
ActionQueue ActionsToComplete; // Actions queue to run during the physics process of the cycle.
|
||||
|
||||
|
||||
|
||||
// Functionality
|
||||
|
||||
// Temp fix for now... not sure how to make proper action handling that can reference member function delegates...
|
||||
|
||||
sfn RotateCamera(ERotationAxis _rotationAxis, gFloat _rotationAmount, gFloat _delta)
|
||||
{
|
||||
DGL::InitalizeGLFW();
|
||||
WorldCamera.Rotate(_rotationAxis, _rotationAmount, _delta);
|
||||
}
|
||||
|
||||
deduce windowObj = DGL::CreateWindow(720, 540, "Assignment 1: Timed Render", DGL::WindowedMode(), DGL::NotShared());
|
||||
deduce RotateCamDelegate = Delegate<decltype(RotateCamera)>(RotateCamera);
|
||||
|
||||
DGL::SetCurrentContext(windowObj);
|
||||
sfn MoveCamera(EDirection _direction, gFloat _translationAmount, gFloat _delta)
|
||||
{
|
||||
WorldCamera.Move(_direction, _translationAmount, _delta);
|
||||
}
|
||||
|
||||
DGL::InitalizeGLEW();
|
||||
deduce MoveCamDelegate = Delegate<decltype(MoveCamera)>(MoveCamera);
|
||||
|
||||
// End of temp stuff...
|
||||
|
||||
|
||||
|
||||
// Currently Does everything required before entering the cycler.
|
||||
sfn PrepWorkspace()
|
||||
{
|
||||
InitalizeGLFW();
|
||||
|
||||
DefaultWindow = CreateWindow(ScreenWidth, ScreenHeight, "Assignment 1: Lighting Test", WindowedMode(), NotShared());
|
||||
|
||||
SetCurrentContext(DefaultWindow);
|
||||
|
||||
InitalizeGLEW(); // Glew must initialize only after a context is set.
|
||||
|
||||
// Cursor stuff
|
||||
|
||||
SetInputMode(DefaultWindow, DGL::EMouseMode::Cursor, DGL::ECursorMode::Disable);
|
||||
|
||||
ResetCursor(DefaultWindow, ScreenCenterWidth, ScreenCenterHeight);
|
||||
|
||||
if (CanUseRawMouse())
|
||||
{
|
||||
SetInputMode(DefaultWindow, DGL::EMouseMode::RawMouse, DGL::EBool::True);
|
||||
}
|
||||
|
||||
// End of cursor stuff...
|
||||
|
||||
PrepareRenderObjects();
|
||||
|
||||
DGL::RunBasicWindowLoop_Timed(windowObj, 1.0 / 60.0, Address(RenderProcedure));
|
||||
SetPolygonMode(DGL::EFace::Front_and_Back, DGL::ERenderMode::Fill);
|
||||
}
|
||||
|
||||
sfn PrepareRenderObjects() -> void
|
||||
{
|
||||
RAW_SetupBuffers();
|
||||
|
||||
RAW_BindAndBufferDataToIDs();
|
||||
|
||||
DGL::LoadDefaultShaders();
|
||||
|
||||
DGL::FormatVertexAttributes<Vertex3>(VertexAttributeIndex, EDataType::Float, ZeroOffset(), Vertex3::ValueCount(), EBool::False);
|
||||
|
||||
DGL::BindBuffer(EBufferTarget::VertexAttributes, 0); // Dunno. Prob unbinding...
|
||||
|
||||
DGL::BindVertexArray(0);
|
||||
}
|
||||
|
||||
using DGL::EFrameBuffer;
|
||||
using DGL::LinearColor;
|
||||
using DGL::DefaultSpace::WorldCamera;
|
||||
|
||||
using std::cout; using std::endl;
|
||||
|
||||
using DGL::KeyPressed;
|
||||
using DGL::EKeyCodes;
|
||||
|
||||
using DGL::DefaultSpace::WorldCamera;
|
||||
using DGL::EDirection;
|
||||
|
||||
|
||||
struct CamShouldMove
|
||||
{
|
||||
bool Up, Down, Left, Right, Forward, Backward;
|
||||
/*
|
||||
Cycles the process of what to do while a window is open.
|
||||
|
||||
short int numActive;
|
||||
};
|
||||
The input, physics, and render procedures can be specified with extra functionality by specifying delegates to those procedures.
|
||||
|
||||
CamShouldMove CamMoveRequests = { false, false, false, false, false, false, 0 };
|
||||
|
||||
double CursorX, CursorY;
|
||||
|
||||
using DGL::DefaultSpace::ScreenCenterWidth; using DGL::DefaultSpace::ScreenCenterHeight;
|
||||
|
||||
|
||||
TimeValDec InputDelta = 0.0, PhysicsDelta = 0.0, RenderDelta = 0.0;
|
||||
|
||||
using DGL::DefaultSpace::Screenspace;
|
||||
|
||||
sfn Cycler(Delegate< Func<void, ptr<Window>> > _inputProcedure, Delegate< Func<void>> _renderProcedure)
|
||||
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)
|
||||
{
|
||||
while (Exist)
|
||||
{
|
||||
CycleStart = DGL::GetTime();
|
||||
CycleStart = GetTime();
|
||||
|
||||
if (InputDelta >= InputPollingInterval)
|
||||
if (InputDelta >= InputInterval)
|
||||
{
|
||||
DGL::PollEvents();
|
||||
PollEvents();
|
||||
|
||||
glfwGetCursorPos(DefaultWindow, Address(CursorX), Address(CursorY));
|
||||
if (KeyPressed(DefaultWindow, EKeyCodes::Escape))
|
||||
{
|
||||
Exist = false;
|
||||
}
|
||||
|
||||
GetCursorPosition(DefaultWindow, Address(CursorX), Address(CursorY));
|
||||
|
||||
_inputProcedure(DefaultWindow);
|
||||
|
||||
DGL::ResetCursor(DefaultWindow, ScreenCenterWidth, ScreenCenterHeight);
|
||||
ResetCursor(DefaultWindow, ScreenCenterWidth, ScreenCenterHeight);
|
||||
|
||||
InputDelta = 0.0;
|
||||
}
|
||||
|
||||
if (PhysicsDelta >= PhysicsInterval)
|
||||
{
|
||||
if (CamMoveRequests.Up ) WorldCamera.Move(EDirection::Up , CamMoveSpeed / CamMoveRequests.numActive, PhysicsDelta);
|
||||
if (CamMoveRequests.Down ) WorldCamera.Move(EDirection::Down , CamMoveSpeed / CamMoveRequests.numActive, PhysicsDelta);
|
||||
if (CamMoveRequests.Left ) WorldCamera.Move(EDirection::Left , CamMoveSpeed / CamMoveRequests.numActive, PhysicsDelta);
|
||||
if (CamMoveRequests.Right ) WorldCamera.Move(EDirection::Right , CamMoveSpeed / CamMoveRequests.numActive, PhysicsDelta);
|
||||
if (CamMoveRequests.Forward ) WorldCamera.Move(EDirection::Forward , CamMoveSpeed / CamMoveRequests.numActive, PhysicsDelta);
|
||||
if (CamMoveRequests.Backward) WorldCamera.Move(EDirection::Backward, CamMoveSpeed / CamMoveRequests.numActive, PhysicsDelta);
|
||||
while (ActionsToComplete.HasAction())
|
||||
{
|
||||
ActionsToComplete.DoNextAction();
|
||||
}
|
||||
|
||||
WorldCamera.UpdateCamera();
|
||||
|
||||
//WorldCamera.Position.y = 0.0;
|
||||
//WorldCamera.LookAtPosition.y = 0.0;
|
||||
|
||||
DGL::DefaultSpace::UpdateScreenspace();
|
||||
|
||||
CamMoveRequests = { false, false, false, false, false, false, 0 };
|
||||
_physicsProcedure();
|
||||
|
||||
PhysicsDelta = 0.0;
|
||||
}
|
||||
|
||||
if (RenderDelta >= RenderInterval)
|
||||
{
|
||||
DGL::ClearBuffer(EFrameBuffer::Color, EFrameBuffer::Depth);
|
||||
ClearBuffer(EFrameBuffer::Color, EFrameBuffer::Depth);
|
||||
|
||||
DGL::SetClearColor(LinearColor(0.12f, 0.12f, 0.12f, 1.0f));
|
||||
SetClearColor(LinearColor(0.12f, 0.12f, 0.12f, 1.0f));
|
||||
|
||||
_renderProcedure();
|
||||
|
||||
DGL::SwapBuffers(DefaultWindow);
|
||||
SwapBuffers(DefaultWindow);
|
||||
|
||||
RenderDelta = 0.0;
|
||||
}
|
||||
|
||||
CycleEnd = DGL::GetTime();
|
||||
CycleEnd = GetTime();
|
||||
|
||||
DeltaTime = CycleEnd - CycleStart;
|
||||
|
||||
@ -232,9 +219,7 @@ namespace Execution
|
||||
return;
|
||||
}
|
||||
|
||||
using DGL::EMouseMode; using DGL::ECursorMode;
|
||||
|
||||
using DGL::DefaultSpace::ScreenCenterWidth; using DGL::DefaultSpace::ScreenCenterHeight;
|
||||
|
||||
sfn InputProcedure(ptr<Window> _currentWindowContext)
|
||||
{
|
||||
@ -242,145 +227,96 @@ namespace Execution
|
||||
{
|
||||
ECursorMode cursorMode = ECursorMode(GetMouseInputMode(DefaultWindow, EMouseMode::Cursor));
|
||||
|
||||
deduce delegate = Delegate<decltype(SetInputMode<ECursorMode>)>(SetInputMode<ECursorMode>);
|
||||
|
||||
if (cursorMode == ECursorMode::Normal || cursorMode == ECursorMode::Hidden)
|
||||
{
|
||||
SetInputMode(_currentWindowContext, EMouseMode::Cursor, ECursorMode::Disable);
|
||||
ActionsToComplete.AddToQueue(delegate, _currentWindowContext, EMouseMode::Cursor, ECursorMode::Disable);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetInputMode(_currentWindowContext, EMouseMode::Cursor, ECursorMode::Normal);
|
||||
ActionsToComplete.AddToQueue(delegate, _currentWindowContext, EMouseMode::Cursor, ECursorMode::Normal);
|
||||
}
|
||||
}
|
||||
|
||||
if (CursorX != 0)//!= ScreenCenterWidth)
|
||||
if (CursorX != 0)
|
||||
{
|
||||
WorldCamera.Rotate(DGL::ERotationAxis::Yaw, CursorX * CamMoveSpeed, InputDelta);
|
||||
|
||||
//cout << "Cursor X: " << CursorX << endl;
|
||||
ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Yaw, CursorX * CamMoveSpeed, PhysicsDelta);
|
||||
}
|
||||
|
||||
if (CursorY != 0)
|
||||
{
|
||||
WorldCamera.Rotate(DGL::ERotationAxis::Pitch, CursorY * CamMoveSpeed, InputDelta);
|
||||
|
||||
//cout << "Cursor Y: " << CursorX << endl;
|
||||
ActionsToComplete.AddToQueue(RotateCamDelegate, ERotationAxis::Pitch, CursorY * CamMoveSpeed, PhysicsDelta);
|
||||
}
|
||||
|
||||
if (KeyPressed(_currentWindowContext, EKeyCodes::E))
|
||||
{
|
||||
WorldCamera.Move(EDirection::Up, CamMoveSpeed, InputDelta);
|
||||
|
||||
CamMoveRequests.Up = true;
|
||||
|
||||
CamMoveRequests.numActive++;
|
||||
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Up, CamMoveSpeed, PhysicsDelta);
|
||||
}
|
||||
|
||||
if (KeyPressed(_currentWindowContext, EKeyCodes::Q))
|
||||
{
|
||||
WorldCamera.Move(EDirection::Down, CamMoveSpeed, InputDelta);
|
||||
|
||||
CamMoveRequests.Down = true;
|
||||
|
||||
CamMoveRequests.numActive++;
|
||||
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Down, CamMoveSpeed, PhysicsDelta);
|
||||
}
|
||||
|
||||
if (KeyPressed(_currentWindowContext, EKeyCodes::A))
|
||||
{
|
||||
WorldCamera.Move(EDirection::Left, CamMoveSpeed, InputDelta);
|
||||
|
||||
CamMoveRequests.Left = true;
|
||||
|
||||
CamMoveRequests.numActive++;
|
||||
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Left, CamMoveSpeed, PhysicsDelta);
|
||||
}
|
||||
|
||||
if (KeyPressed(_currentWindowContext, EKeyCodes::D))
|
||||
{
|
||||
WorldCamera.Move(EDirection::Right, CamMoveSpeed, InputDelta);
|
||||
|
||||
CamMoveRequests.Right = true;
|
||||
|
||||
CamMoveRequests.numActive++;
|
||||
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Right, CamMoveSpeed, PhysicsDelta);
|
||||
}
|
||||
|
||||
if (KeyPressed(_currentWindowContext, EKeyCodes::W))
|
||||
{
|
||||
WorldCamera.Move(EDirection::Forward, CamMoveSpeed, InputDelta);
|
||||
|
||||
CamMoveRequests.Forward = true;
|
||||
|
||||
CamMoveRequests.numActive++;
|
||||
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Forward, CamMoveSpeed, PhysicsDelta);
|
||||
}
|
||||
|
||||
if (KeyPressed(_currentWindowContext, EKeyCodes::S))
|
||||
{
|
||||
WorldCamera.Move(EDirection::Backward, CamMoveSpeed, InputDelta);
|
||||
|
||||
CamMoveRequests.Backward = true;
|
||||
|
||||
CamMoveRequests.numActive++;
|
||||
ActionsToComplete.AddToQueue(MoveCamDelegate, EDirection::Backward, CamMoveSpeed, PhysicsDelta);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
sfn PhysicsProcedure()
|
||||
{
|
||||
WorldCamera.UpdateCamera();
|
||||
|
||||
UpdateScreenspace();
|
||||
|
||||
DGL::SS_Transformed::UpdateShader(Screenspace);
|
||||
}
|
||||
|
||||
|
||||
|
||||
sfn RenderProcedure() -> void
|
||||
{
|
||||
DGL::EnableVertexAttributeArray(VertexAttributeIndex);
|
||||
EnableVertexAttributeArray(VertexAttributeIndex);
|
||||
|
||||
DGL::SetPolygonMode(DGL::EFace::Front_and_Back, DGL::ERenderMode::Line);
|
||||
UseProgramShader(DGL::SS_Transformed::Shader);
|
||||
|
||||
DGL::DefaultSpace::WorldSpace = DGL::Rotate(DGL::DefaultSpace::WorldSpace, 0.0035f, Vector3(0.0f, 0.5f, 0.0f));
|
||||
BindVertexArray(VertexArrayObj);
|
||||
|
||||
DGL::DefaultSpace::Screenspace = DGL::DefaultSpace::WorldCamera.Perspective * DGL::DefaultSpace::WorldCamera.Viewport * DGL::DefaultSpace::WorldSpace;
|
||||
DrawElements(EPrimitives::Triangles, 6, EDataType::UnsignedInt, ZeroOffset());
|
||||
|
||||
DGL::UseProgramShader(DGL::SimpleShader_Transformed);
|
||||
|
||||
DGL::SetUniformVariable_MatrixVariableArray(DGL::ScreenSpaceVarID, 1, DGL::EBool::False, Address(DGL::DefaultSpace::Screenspace[0][0]));
|
||||
|
||||
DGL::BindVertexArray(VertexArrayObj);
|
||||
|
||||
DGL::DrawArrays(DGL::EPrimitives::Triangles, 0, TriangleRaw::VertexCount());
|
||||
|
||||
DGL::DrawElements(DGL::EPrimitives::Triangles, 6, EDataType::UnsignedInt, ZeroOffset());
|
||||
|
||||
//GL::BindVertexArray(0);
|
||||
|
||||
DGL::DisableVertexAttributeArray(VertexAttributeIndex);
|
||||
}
|
||||
|
||||
sfn PrepWorkspace()
|
||||
{
|
||||
using DGL::DefaultSpace::ScreenWidth ;
|
||||
using DGL::DefaultSpace::ScreenHeight;
|
||||
|
||||
DGL::InitalizeGLFW();
|
||||
|
||||
DefaultWindow = DGL::CreateWindow(ScreenWidth, ScreenHeight, "Assignment 1: Cam Movement Test", DGL::WindowedMode(), DGL::NotShared());
|
||||
|
||||
DGL::SetCurrentContext(DefaultWindow);
|
||||
|
||||
DGL::SetInputMode(DefaultWindow, DGL::EMouseMode::Cursor, DGL::ECursorMode::Disable);
|
||||
|
||||
DGL::ResetCursor(DefaultWindow, ScreenCenterWidth, ScreenCenterHeight);
|
||||
|
||||
if (DGL::CanUseRawMouse())
|
||||
{
|
||||
DGL::SetInputMode(DefaultWindow, DGL::EMouseMode::RawMouse, DGL::EBool::True);
|
||||
}
|
||||
|
||||
DGL::InitalizeGLEW();
|
||||
|
||||
PrepareRenderObjects();
|
||||
DisableVertexAttributeArray(VertexAttributeIndex);
|
||||
}
|
||||
|
||||
|
||||
// Runtime Execution: Loop must be specified here to use.
|
||||
|
||||
// Runtime Execution: Default Execution
|
||||
|
||||
sfn Execute() -> ExitCode
|
||||
{
|
||||
PrepWorkspace();
|
||||
|
||||
Cycler(InputProcedure, RenderProcedure);
|
||||
Cycler(InputProcedure, PhysicsProcedure, RenderProcedure);
|
||||
|
||||
DGL::TerminateGLFW();
|
||||
TerminateGLFW();
|
||||
|
||||
return ExitCode::Success;
|
||||
}
|
||||
|
@ -5,11 +5,11 @@ layout (location = 0) in vec3 aPos;
|
||||
// uniform mat4 view;
|
||||
// uniform mat4 projection;
|
||||
|
||||
uniform mat4 modelViewProjection;
|
||||
uniform mat4 ScreenSpaceTransform;
|
||||
|
||||
void main()
|
||||
{
|
||||
//gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||
|
||||
gl_Position = modelViewProjection * vec4(aPos, 1.0);
|
||||
gl_Position = ScreenSpaceTransform * vec4(aPos, 1.0);
|
||||
}
|
212
Testing.hpp
Normal file
212
Testing.hpp
Normal file
@ -0,0 +1,212 @@
|
||||
#pragma once
|
||||
|
||||
#include "DGL.hpp"
|
||||
|
||||
#include "Cpp_Alias.hpp"
|
||||
|
||||
|
||||
|
||||
using DGL::gFloat;
|
||||
using DGL::VertexBuffer;
|
||||
using DGL::EBufferTarget;
|
||||
using DGL::EBufferUsage;
|
||||
using DGL::Buffer;
|
||||
using DGL::ID;
|
||||
using DGL::gInt;
|
||||
using DGL::gSize;
|
||||
|
||||
|
||||
|
||||
//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;
|
||||
|
||||
struct Vertex3
|
||||
{
|
||||
gFloat x, y, z;
|
||||
|
||||
static constexpr sfn ValueCount() -> gSize { return 3; }
|
||||
};
|
||||
|
||||
struct TriangleRaw
|
||||
{
|
||||
Vertex3 a, b, c;
|
||||
|
||||
static constexpr sfn VertexCount() -> gSize { return 3; }
|
||||
};
|
||||
|
||||
|
||||
TriangleRaw EquilateralTriangleVerticies =
|
||||
{
|
||||
{ -1.0f, -1.0f, 0.0f }, // Vert1
|
||||
{ 1.0f, -1.0f, 0.0f }, // Vert2
|
||||
{ 0.0f, 1.0f, 0.0f } // Vert 3
|
||||
};
|
||||
|
||||
|
||||
struct RectangleRaw
|
||||
{
|
||||
TriangleRaw first, second;
|
||||
|
||||
static constexpr sfn VertexCount() -> gSize { return 6; }
|
||||
};
|
||||
|
||||
|
||||
RectangleRaw SquareVerticies =
|
||||
{
|
||||
{
|
||||
{ -0.5f, -0.5f, 0.0f },
|
||||
{ 0.5f, -0.5f, 0.0f },
|
||||
{ 0.0f, 0.5f, 0.0f }
|
||||
},
|
||||
{
|
||||
{ 0.5f, -0.5f, 0.0f },
|
||||
{ -0.5f, -0.5f, 0.0f },
|
||||
{ -0.5f, 0.5f, 0.0f }
|
||||
}
|
||||
};
|
||||
|
||||
ID<VertexBuffer> VertexArrayObj;
|
||||
|
||||
struct RectangleCompressed
|
||||
{
|
||||
Vertex3 a, b, c, d;
|
||||
|
||||
static constexpr sfn VertexCount() -> gSize { return 4; }
|
||||
};
|
||||
|
||||
struct TriIndex
|
||||
{
|
||||
gInt a, b, c;
|
||||
};
|
||||
|
||||
struct RectangleIndices
|
||||
{
|
||||
TriIndex first, second;
|
||||
};
|
||||
|
||||
|
||||
RectangleCompressed rectCompress =
|
||||
{
|
||||
{ 1.0f, 1.0f, 0.0f },
|
||||
{ 1.0f, -1.0f, 0.0f },
|
||||
{ -1.0f, -1.0f, 0.0f },
|
||||
{ -1.0f, 1.0f, 0.0f }
|
||||
};
|
||||
|
||||
RectangleIndices rectIndices =
|
||||
{
|
||||
{ 0, 1, 3 },
|
||||
{ 1, 2, 3 }
|
||||
};
|
||||
|
||||
using DGL::ElementBuffer;
|
||||
|
||||
ID<ElementBuffer> ElemBufferObj;
|
||||
|
||||
struct Vertex2
|
||||
{
|
||||
gFloat x, y;
|
||||
};
|
||||
|
||||
struct TriTexCoords
|
||||
{
|
||||
Vertex2 a, b, c;
|
||||
};
|
||||
|
||||
|
||||
TriTexCoords textureCoords =
|
||||
{
|
||||
{ 0.0f, 0.0f },
|
||||
{ 1.0f, 0.0f },
|
||||
{ 0.5f, 1.0f }
|
||||
};
|
||||
|
||||
|
||||
sfn RAW_SetupBuffers()
|
||||
{
|
||||
DGL::GenerateVertexBuffers(Address(VertexArrayObj ), 1);
|
||||
DGL::GenerateBuffers (Address(VertexBufferObj), 1);
|
||||
DGL::GenerateBuffers (Address(ElemBufferObj ), 1);
|
||||
}
|
||||
|
||||
sfn RAW_SetupTriangleBuffer()
|
||||
{
|
||||
DGL::GenerateBuffers(Address(VertexBufferObj), 1);
|
||||
}
|
||||
|
||||
sfn RAW_BindAndBufferDataToIDs()
|
||||
{
|
||||
DGL::BindVertexArray(VertexArrayObj);
|
||||
|
||||
DGL::BindBuffer(EBufferTarget::VertexAttributes, VertexBufferObj);
|
||||
|
||||
//GL::BufferData<TriangleRaw>(Address(EquilateralTriangleVerticies), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
|
||||
|
||||
DGL::BufferData<RectangleCompressed>(Address(rectCompress), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
|
||||
|
||||
DGL::BindBuffer(EBufferTarget::VertexIndices, ElemBufferObj);
|
||||
|
||||
DGL::BufferData<RectangleIndices>(Address(rectIndices), EBufferTarget::VertexIndices, EBufferUsage::StaticDraw);
|
||||
}
|
||||
|
||||
DGL::gInt VertexAttributeIndex = 0; // See shader source: (layout = 0).
|
||||
|
||||
using DGL::EBool;
|
||||
using DGL::EDataType;
|
||||
|
||||
constexpr sfn ZeroOffset() -> ptr<void>
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Testing
|
||||
|
||||
// Forward Declares
|
||||
|
||||
sfn RenderProcedure () -> void;
|
||||
sfn PrepareRenderObjects() -> void;
|
||||
|
||||
sfn CreateWindow_BasicLoop()
|
||||
{
|
||||
DGL::InitalizeGLFW();
|
||||
|
||||
deduce windowObj = DGL::CreateWindow(720, 540, "Assignment 1: RawLoop", DGL::WindowedMode(), DGL::NotShared());
|
||||
|
||||
DGL::SetCurrentContext(windowObj);
|
||||
|
||||
DGL::RunBasicWindowLoop(windowObj);
|
||||
}
|
||||
|
||||
sfn CreateWindow_TimedRender()
|
||||
{
|
||||
DGL::InitalizeGLFW();
|
||||
|
||||
deduce windowObj = DGL::CreateWindow(720, 540, "Assignment 1: Timed Render", DGL::WindowedMode(), DGL::NotShared());
|
||||
|
||||
DGL::SetCurrentContext(windowObj);
|
||||
|
||||
DGL::InitalizeGLEW();
|
||||
|
||||
PrepareRenderObjects();
|
||||
|
||||
//DGL::RunBasicWindowLoop_Timed(windowObj, 1.0 / 60.0, Address(RenderProcedure));
|
||||
}
|
||||
|
||||
sfn PrepareRenderObjects() -> void
|
||||
{
|
||||
RAW_SetupBuffers();
|
||||
|
||||
RAW_BindAndBufferDataToIDs();
|
||||
|
||||
DGL::LoadDefaultShaders();
|
||||
|
||||
DGL::FormatVertexAttributes<Vertex3>(VertexAttributeIndex, EDataType::Float, ZeroOffset(), Vertex3::ValueCount(), EBool::False);
|
||||
|
||||
DGL::BindBuffer(EBufferTarget::VertexAttributes, 0); // Dunno. Prob unbinding...
|
||||
|
||||
DGL::BindVertexArray(0);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user