Sectioned off layers of modeling glue and finished sanding off all excess adhesive I could find.

This commit is contained in:
Edward R. Gonzalez 2020-02-21 06:45:32 -05:00
parent da4a38c11f
commit abac626973
38 changed files with 562 additions and 999 deletions

View File

@ -1,10 +0,0 @@
#version 330 core
out vec4 FragColor;
in vec3 ourColor;
void main()
{
FragColor = vec4(ourColor, 1.0f);
}

View File

@ -1,11 +0,0 @@
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aColor;
out vec3 ourColor;
void main()
{
gl_Position = vec4(aPos, 1.0);
ourColor = aColor;
}#pragma once

View File

@ -1,15 +0,0 @@
#version 330 core
out vec4 FragColor;
// in vec2 TexCoord;
// texture samplers
// uniform sampler2D texture1;
// uniform sampler2D texture2;
void main()
{
// linearly interpolate between both textures (80% container, 20% awesomeface)
//FragColor = mix(texture(texture1, TexCoord), texture(texture2, TexCoord), 0.2);
}

View File

@ -1,16 +0,0 @@
#version 330 core
layout (location = 0) in vec3 aPos;
// layout (location = 1) in vec2 aTexCoord;
// out vec2 TexCoord;
uniform mat4 transform;
void main()
{
gl_Position = transform * vec4(aPos, 1.0);
// TexCoord = vec2(aTexCoord.x, aTexCoord.y);
}

View File

@ -1,22 +0,0 @@
#version 330 core
out vec4 FragColor;
in vec2 TexCoord;
uniform sampler2D texture1;
uniform sampler2D texture2;
void main()
{
FragColor = mix(texture(texture1, TexCoord), texture(texture2, TexCoord), 0.2);
}

View File

@ -1,18 +0,0 @@
#version 330 core
layout (location = 0) in vec3 aPos;
// layout (location = 1) in vec2 aTexCoord;
// out vec2 TexCoord;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
gl_Position = projection * view * model * vec4(aPos, 1.0);
// TexCoord = vec2(aTexCoord.x, 1.0 - aTexCoord.y);
}

View File

@ -2,13 +2,12 @@
Title : Actions Title : Actions
Author: Edward R. Gonzalez Author: Edward R. Gonzalez
Description: This was a little experiment of mine to mess with action binding... 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. 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); 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);
Note: Right now due to type dynamics all actions are allocated via a pool and reuse is attempted by not guaranteed...
*/ */
@ -23,21 +22,22 @@ Note: Right now due to type dynamics all actions are allocated via a pool and re
namespace Actions namespace Actions
{ {
using IndexType = DataSize; using IndexType = DataSize ;
using TypeIndex = std::type_index;
struct IAction struct IAction
{ {
virtual sfn DoAction() -> void = NULL; virtual sfn DoAction () -> void = NULL;
}; };
template<typename FunctionType, typename... ActionParams> template<typename FunctionType, typename... ActionParams>
struct AAction : IAction struct AAction : IAction
{ {
public:
using ActionType = Delegate< FunctionType >; using ActionType = Delegate< FunctionType >;
public:
AAction(ro Ref(ActionType) _actionToAssign, ro Ref(ActionParams)... _params) : AAction(ro Ref(ActionType) _actionToAssign, ro Ref(ActionParams)... _params) :
action(_actionToAssign), action(_actionToAssign),
params(_params... ), params(_params... ),
@ -49,11 +49,23 @@ namespace Actions
return done; return done;
} }
sfn IsSame(ro Ref(ActionParams)... _paramsForAction) -> bool sfn IsSame(ro Ref(ActionType) _action, ro Ref(ActionParams)... _paramsForAction) -> bool
{ {
Tuple<ActionParams...> paramsToCheck(_paramsForAction...); Tuple<ActionParams...> paramsToCheck(_paramsForAction...);
if (params == paramsToCheck) if (params == paramsToCheck && SameAction(_action))
{
return true;
}
else
{
return false;
}
}
sfn SameAction(ro Ref(ActionType) _action)
{
if (action.target<FunctionType*>() == _action.target<FunctionType*>())
{ {
return true; return true;
} }
@ -70,11 +82,11 @@ namespace Actions
done = false; done = false;
} }
private: protected:
sfn DoAction_Implementation(ro Ref(ActionParams)... _params) { action(_params...); } virtual sfn DoAction_Implementation(ro Ref(ActionParams)... _params) -> void { action(_params...); }
template<IndexType... TuplePackIndex> // TuplePackSequence<TuplePackIndex...> template<IndexType... TuplePackIndex> // TuplePackSequence<TuplePackIndex...>
sfn ExpandTuple_CallDoActionImplementaiton(ro Ref(Tuple<ActionParams...>) _paramsToExpand, std::index_sequence <TuplePackIndex...>) sfn ExpandTuple_CallDoActionImplementaiton(ro Ref(Tuple<ActionParams...>) _paramsToExpand, std::index_sequence <TuplePackIndex...>) -> void
{ {
// ExpandTuplePack<TuplePackIndex> // ExpandTuplePack<TuplePackIndex>
DoAction_Implementation(std::get<TuplePackIndex>(_paramsToExpand)...); DoAction_Implementation(std::get<TuplePackIndex>(_paramsToExpand)...);
@ -82,7 +94,7 @@ namespace Actions
Tuple<ActionParams...> params; Tuple<ActionParams...> params;
ActionType action; ro Ref(ActionType) action;
bool done; bool done;
@ -101,12 +113,87 @@ namespace Actions
}; };
}; };
// TODO: This doesn't work yet...
template<typename ObjectType, typename FunctionType, typename... ActionParams>
class AAction_ObjectBound : public AAction<FunctionType, ActionParams...>
{
public:
using ActionType = Delegate<FunctionType>;
AAction_ObjectBound(Ref(ObjectType) _objectRef, ro Ref(ActionType) _actionToAssign, ro Ref(ActionParams)... _params) :
AAction<FunctionType, ActionParams...>::action(_actionToAssign),
AAction<FunctionType, ActionParams...>::params(_params... ),
object (_objectRef )
{}
sfn IsSame(ro Ref(ObjectType) _object, ro Ref(ActionType) _action, ro Ref(ActionParams)... _params) -> bool
{
if (SameObject(_object) && SameAction(_action))
{
Tuple<ActionParams...> paramsToCheck(_params...);
if (AAction<FunctionType, ActionParams...>::params == paramsToCheck)
{
return true;
}
else
{
return false;
}
}
}
sfn SameObject(ro Ref(ObjectType) _object) -> bool
{
if (Address(object) == Address(_object))
{
return true;
}
else
{
return false;
}
}
protected:
virtual sfn DoAction_Implementation(ro Ref(ActionParams)... _params) -> void override
{
(Address(object).*AAction<FunctionType, ActionParams...>::action)(_params...);
}
template<IndexType... TuplePackIndex> // TuplePackSequence<TuplePackIndex...>
sfn ExpandTuple_CallDoActionImplementaiton(ro Ref(Tuple<ActionParams...>) _paramsToExpand, std::index_sequence <TuplePackIndex...>) -> void
{
// ExpandTuplePack<TuplePackIndex>
DoAction_Implementation(std::get<TuplePackIndex>(_paramsToExpand)...);
}
Ref(ObjectType) object;
public: // IAction
virtual sfn DoAction() -> void override
{
ExpandTuple_CallDoActionImplementaiton
(
AAction<FunctionType, ActionParams...>::params,
// MakeTuplePackSequence <ActionParams...>()
std::index_sequence_for<ActionParams...>()
);
AAction<FunctionType, ActionParams...>::params::done = true;
};
};
struct ActionPool_Dynamic struct ActionPool_Dynamic
{ {
template<typename Type> template<typename Type>
using AllocationsOf = std::forward_list<Type>; using AllocationsOf = std::forward_list<Type>;
using TypeIndex = std::type_index ;
using Managed_AAction = SPtr < IAction >; using Managed_AAction = SPtr < IAction >;
using Managed_AActions = AllocationsOf < Managed_AAction >; using Managed_AActions = AllocationsOf < Managed_AAction >;
using AActions_Registry = std::map <TypeIndex , Managed_AActions>; using AActions_Registry = std::map <TypeIndex , Managed_AActions>;
@ -141,13 +228,60 @@ namespace Actions
for (Element possibleAction = possibleEntry->second.begin(); possibleAction != possibleEntry->second.end(); possibleAction++) for (Element possibleAction = possibleEntry->second.begin(); possibleAction != possibleEntry->second.end(); possibleAction++)
{ {
ptr< ActionType> castedEntry = static_cast< ptr< ActionType>>(possibleAction->get()); ptr< ActionType> castedEntry = static_cast<ptr< ActionType>>(possibleAction->get());
if (castedEntry->IsSame(_paramsForAction...)) if (castedEntry->IsSame(_actionToQueue, _paramsForAction...))
{ {
return castedEntry; return castedEntry;
} }
else if (castedEntry->Used()) else if (castedEntry->Used() && castedEntry->SameAction(_actionToQueue))
{
castedEntry->ReInitalize(_paramsForAction...);
return castedEntry;
}
}
SPtr< IAction> newAction = MakeSPtr< AAction<FunctionType, ActionParams...>>(_actionToQueue, _paramsForAction...);
ptr < IAction> returnRef = newAction.get ();
aActions_Available.at(AActionID).push_front(newAction);
return returnRef;
}
SPtr< IAction> newAction = MakeSPtr< AAction<FunctionType, ActionParams...>>(_actionToQueue, _paramsForAction...);
ptr < IAction> returnRef = newAction.get ();
aActions_Available.insert(std::make_pair(AActionID, Make_Managed_Actions()));
aActions_Available.at(AActionID).push_front(newAction);
return returnRef;
}
template<typename ObjectType, typename FunctionType, typename... ActionParams>
sfn Request_AAction(ro Ref(ObjectType) _objectRef, ro Ref(Delegate< FunctionType>) _actionToQueue, ro Ref(ActionParams)... _paramsForAction) -> ptr<IAction>
{
using ActionType = AAction_ObjectBound<ObjectType, FunctionType, ActionParams...>;
TypeIndex AActionID = typeid(ActionType);
deduce possibleEntry = aActions_Available.find(AActionID);
if (Contains(possibleEntry))
{
using Element = decltype(possibleEntry->second.begin());
for (Element possibleAction = possibleEntry->second.begin(); possibleAction != possibleEntry->second.end(); possibleAction++)
{
ptr< ActionType> castedEntry = static_cast<ptr< ActionType>>(possibleAction->get());
if (castedEntry->IsSame(_actionToQueue, _paramsForAction...))
{
return castedEntry;
}
else if (castedEntry->Used() && castedEntry->SameAction(_actionToQueue))
{ {
castedEntry->ReInitalize(_paramsForAction...); castedEntry->ReInitalize(_paramsForAction...);
@ -222,6 +356,38 @@ namespace Actions
} }
} }
template<typename ObjectType, typename FunctionType, typename... ActionParams>
sfn AddToQueue(ro Ref(ObjectType) _objectRef, ro Ref(Delegate< FunctionType>) _actionToQueue, ro Ref(ActionParams)... _paramsForAction)
{
using GeneratedActionType = AAction_ObjectBound<ObjectType, FunctionType, ActionParams...>;
ptr< IAction > actionRequested = DefaultActionPool_Dynamic.Request_AAction(_objectRef, _actionToQueue, _paramsForAction...);
if (HasAction())
{
bool found = false;
using Element = decltype(actionQueue.begin());
for (Element element = actionQueue.begin(); element != actionQueue.end(); element++)
{
if ((*element) == actionRequested)
{
found = true;
}
}
if (not found)
{
actionQueue.push_front(actionRequested);
}
}
else
{
actionQueue.push_front(actionRequested);
}
}
sfn DoNextAction() sfn DoNextAction()
{ {
if (actionQueue.size() > 0) if (actionQueue.size() > 0)

View File

@ -1,15 +0,0 @@
#version 330 core
out vec4 FragColor;
uniform vec3 ObjectColor;
uniform vec3 LightColor ;
void main()
{
FragColor = vec4(LightColor * ObjectColor, 1.0);
}

10
DGL.hpp
View File

@ -1,10 +0,0 @@
#pragma once
// 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"
#include "DGL_Entity.hpp"

20
DGL/DGL.hpp Normal file
View File

@ -0,0 +1,20 @@
/*
Title : Ducktaped GL: Library Head
Author: Edward R. Gonzalez
Description:
This is the header that should be included into the application using this library.
Includes the rest of the library.
*/
#pragma once
// DGL
#include "DGL_Enum.hpp"
#include "DGL_Types.hpp"
#include "DGL_Buffers.hpp"
#include "DGL_Shader.hpp"
#include "DGL_Space.hpp"
#include "DGL_Model.hpp"
#include "DGL_Entity.hpp"

View File

@ -1,3 +1,11 @@
/*
Title : Ducktaped GL: Buffers
Author: Edward R. Gonzalez
Description:
Contains wrappers to buffer related functionality.
*/
#pragma once #pragma once
// GLEW // GLEW

View File

@ -1,3 +1,11 @@
/*
Title : Ducktaped GL: Entity
Author: Edward R. Gonzalez
Description:
Contains implementation for useful entity classes that brings together much of the OpenGL functionality to be used as individual objects.
*/
#pragma once #pragma once
@ -12,13 +20,15 @@
#include "Cpp_Alias.hpp" #include "Cpp_Alias.hpp"
namespace DGL namespace DGL
{ {
namespace Colors namespace Colors
{ {
LinearColor CoralColor(1.0f , 0.5f , 0.31f, 1.0f); LinearColor Coral (1.0f , 0.5f , 0.31f, 1.0f);
LinearColor GreyColor (0.60f, 0.60f, 0.60f, 1.0f); LinearColor Grey (0.60f, 0.60f, 0.60f, 1.0f);
LinearColor LightColor(1.0f , 1.0f , 1.0f , 1.0f); LinearColor WarmSphia(0.54f, 0.52f, 0.5f, 1.0f);
LinearColor White (1.0f , 1.0f , 1.0f , 1.0f);
} }
@ -26,11 +36,11 @@ namespace DGL
{ {
public: public:
Light_Basic() : Light_Basic() :
color (Colors::LightColor.Vector()), color (Colors::White.Vector()),
position (Vector3 (0.0f) ), position (Vector3 (0.0f) ),
scale (Vector3 (0.2f) ), scale (Vector3 (0.2f) ),
transform (CoordSpace(1.0f) ), transform (CoordSpace(1.0f) ),
translationRadius(4.0f ) translationRadius(4.0f )
{} {}
@ -67,22 +77,26 @@ namespace DGL
UnbindVertexArray(); UnbindVertexArray();
} }
sfn Update() sfn Update(double _delta)
{ {
static gFloat valueLoop = 0.0f;
transform = CoordSpace(1.0f); transform = CoordSpace(1.0f);
position.x = translationRadius * sin(GetTime()); position.x = translationRadius * sin(valueLoop);
position.z = translationRadius * cos(GetTime()); position.z = translationRadius * cos(valueLoop);
transform = Translate(transform, position); transform = Translate(transform, position);
transform = Scale (transform, scale ); transform = Scale (transform, scale );
valueLoop += 0.31879f * _delta;
} }
sfn Render(ro Ref(CoordSpace) _projection, ro Ref(CoordSpace) _viewport) sfn Render(ro Ref(CoordSpace) _projection, ro Ref(CoordSpace) _viewport)
{ {
deduce screenspaceTransform = _projection * _viewport * transform; deduce screenspaceTransform = _projection * _viewport * transform;
Basic_LampShader::Use(screenspaceTransform); Basic_LightShader::Use(screenspaceTransform);
BindVertexArray(modelVAO); BindVertexArray(modelVAO);
@ -92,7 +106,9 @@ namespace DGL
DrawElements(EPrimitives::Triangles, SizeRef, EDataType::UnsignedInt, ZeroOffset()); DrawElements(EPrimitives::Triangles, SizeRef, EDataType::UnsignedInt, ZeroOffset());
Basic_LampShader::Stop(); //UnbindVertexArray();
Basic_LightShader::Stop();
} }
private: private:
@ -183,18 +199,47 @@ namespace DGL
public: public:
Entity_Basic() : Entity_Basic() :
position (Vector3(0.0f) ), position (Vector3(0.0f) ),
model ("" ), scale (Vector3(1.0f) ),
model (NULL ),
transform(CoordSpace(1.0f)) transform(CoordSpace(1.0f))
{}; {};
Entity_Basic(Ref(Model) _model, Ref(Material_Phong) _material) : Entity_Basic(Ref(Model) _model, Ref(Material_Phong) _material) :
position (Vector3(0.0f) ), position (Vector3(0.0f) ),
model (_model ), scale (Vector3(1.0f) ),
model (Address(_model) ),
transform(CoordSpace(1.0f)), transform(CoordSpace(1.0f)),
material (_material ) material (_material )
//type (_type ) //type (_type )
{}; {};
sfn SetModel(Ref(Model) _model)
{
model = Address(_model);
}
sfn SetScale(gFloat _scaleBy)
{
scale = Vector3(_scaleBy);
transform = CoordSpace(1.0f);
transform = DGL::Translate(transform, position);
transform = DGL::Scale(transform, scale);
}
sfn SetPosition(ro Ref(Vector3) _position)
{
position = _position;
transform = CoordSpace(1.0f);
transform = DGL::Translate(transform, position);
transform = DGL::Scale(transform, scale);
}
sfn Update() sfn Update()
{ {
@ -204,7 +249,7 @@ namespace DGL
{ {
PhongShader::Use(_projection, _viewport, transform, _lightPosition,_lightColor, material); PhongShader::Use(_projection, _viewport, transform, _lightPosition,_lightColor, material);
model.Render(); Dref(model).Render();
PhongShader::Stop(); PhongShader::Stop();
@ -214,6 +259,7 @@ namespace DGL
sfn operator= (ro Ref(Entity_Basic) _entity)->Ref(Entity_Basic) sfn operator= (ro Ref(Entity_Basic) _entity)->Ref(Entity_Basic)
{ {
position = _entity.position ; position = _entity.position ;
scale = _entity.scale;
model = _entity.model ; model = _entity.model ;
transform = _entity.transform; transform = _entity.transform;
material = _entity.material ; material = _entity.material ;
@ -226,7 +272,8 @@ namespace DGL
//EEntityType type; //EEntityType type;
Vector3 position ; Vector3 position ;
Model model ; Vector3 scale ;
ptr<Model> model ;
CoordSpace transform ; CoordSpace transform ;
Material_Phong material ; Material_Phong material ;
}; };

View File

@ -1,8 +1,19 @@
/*
Title : Ducktaped GL: Enums
Author: Edward R. Gonzalez
Description:
Wraps the currently used enumerated macros used for various GFLW/OpenGL functions into enum classes.
*/
#pragma once #pragma once
// GLEW // GLEW
#include <glew.h> #include <glew.h>
// GLFW
#include <glfw3.h>
namespace DGL namespace DGL
@ -119,10 +130,12 @@ namespace DGL
A = GLFW_KEY_A , A = GLFW_KEY_A ,
D = GLFW_KEY_D , D = GLFW_KEY_D ,
E = GLFW_KEY_E , E = GLFW_KEY_E ,
H = GLFW_KEY_H ,
I = GLFW_KEY_I , I = GLFW_KEY_I ,
J = GLFW_KEY_J , J = GLFW_KEY_J ,
K = GLFW_KEY_K , K = GLFW_KEY_K ,
L = GLFW_KEY_L , L = GLFW_KEY_L ,
M = GLFW_KEY_M ,
Q = GLFW_KEY_Q , Q = GLFW_KEY_Q ,
S = GLFW_KEY_S , S = GLFW_KEY_S ,
W = GLFW_KEY_W , W = GLFW_KEY_W ,

View File

@ -1,3 +1,11 @@
/*
Title : Ducktaped GL: Model
Author: Edward R. Gonzalez
Description:
*/
#pragma once #pragma once
// DGL // DGL
@ -158,6 +166,7 @@ namespace DGL
public: public:
Model(ro Ref(string) _filePath) : Model(ro Ref(string) _filePath) :
loaded (false ),
vertexArrayID (0 ), vertexArrayID (0 ),
vertexBufferID (0 ), vertexBufferID (0 ),
normalBuffferID(0 ), normalBuffferID(0 ),
@ -385,6 +394,10 @@ namespace DGL
fileBuffer.close(); fileBuffer.close();
Buffer();
loaded = true;
return; return;
} }
else else
@ -393,6 +406,11 @@ namespace DGL
} }
} }
sfn Ready() -> bool
{
return loaded;
}
sfn Render() sfn Render()
{ {
BindVertexArray(vertexArrayID); BindVertexArray(vertexArrayID);
@ -430,6 +448,8 @@ namespace DGL
// Components // Components
bool loaded;
ID<VertexArray > vertexArrayID ; ID<VertexArray > vertexArrayID ;
ID<VertexBuffer > vertexBufferID ; ID<VertexBuffer > vertexBufferID ;
ID<NormalBuffer > normalBuffferID; ID<NormalBuffer > normalBuffferID;

View File

@ -159,7 +159,6 @@ namespace DGL
{ {
using std::vector; using std::vector;
string vertexShaderCode ; string vertexShaderCode ;
string fragmentShaderCode ; string fragmentShaderCode ;
@ -308,195 +307,7 @@ namespace DGL
return; return;
} }
namespace Basic_LightShader
// 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(ro Ref(CoordSpace) _screenSpace)
{
SetUniformVariable_MVA(ScreenSpaceVarID, 1, false, _screenSpace[0][0]);
return;
}
sfn LoadShader()
{
Shader = LoadShaders("SimpleTransform.vert", "SingleColor.frag");
ScreenSpaceVarID = DGL::GetUniformVariable(Shader, "ScreenSpaceTransform");
return;
}
}
namespace Basic_LightingShader
{
ID<ShaderProgram> Shader;
ID<CoordSpace> ScreenSpaceVarID;
ID<Vec3> ObjectColorID, LightColorID;
sfn LoadShader()
{
Shader = LoadShaders("SimpleTransform.vert", "BasicLighting.frag");
ScreenSpaceVarID = GetUniformVariable(Shader, "ScreenSpaceTransform");
ObjectColorID = GetUniformVariable(Shader, "ObjectColor");
LightColorID = GetUniformVariable(Shader, "LightColor" );
}
sfn 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;
}
}
namespace Basic_LampShader
{ {
ID<ShaderProgram> Shader; ID<ShaderProgram> Shader;
@ -504,7 +315,7 @@ namespace DGL
sfn LoadShader() sfn LoadShader()
{ {
Shader = LoadShaders("SimpleTransform.vert", "BasicLamp.frag"); Shader = LoadShaders("./Shaders/BasicLight.vert", "./Shaders/BasicLight.frag");
ScreenSpaceVarID = GetUniformVariable(Shader, "ScreenSpaceTransform"); ScreenSpaceVarID = GetUniformVariable(Shader, "ScreenSpaceTransform");
@ -554,7 +365,7 @@ namespace DGL
sfn LoadShader() sfn LoadShader()
{ {
ShaderID = LoadShaders("PhongShader.vert", "PhongShader.frag"); ShaderID = LoadShaders("./Shaders/PhongShader.vert", "./Shaders/PhongShader.frag");
InverseModelSpaceID = GetUniformVariable(ShaderID, "InverseModelSpace"); InverseModelSpaceID = GetUniformVariable(ShaderID, "InverseModelSpace");
ModelSpaceID = GetUniformVariable(ShaderID, "ModelSpace" ); ModelSpaceID = GetUniformVariable(ShaderID, "ModelSpace" );
@ -572,37 +383,6 @@ namespace DGL
return; return;
} }
sfn Use_Old
(
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]);
EnableVertexAttributeArray(0);
EnableVertexAttributeArray(1);
return;
}
sfn Use sfn Use
( (
ro Ref(CoordSpace ) _projection , ro Ref(CoordSpace ) _projection ,
@ -646,37 +426,10 @@ namespace DGL
} }
} }
sfn LoadRawShader()
{
ID<Shader> VertexShader = 0;
ID<Shader> FragmentShader = 0;
MakeShader(VertexShader , EShaderType::Vertex , 1, Address(RawVertextShaderSource ), NULL);
MakeShader(FragmentShader, EShaderType::Fragment, 1, Address(RawFragmentShaderSource), NULL);
MakeShaderProgram(RawShader, VertexShader, FragmentShader);
DeleteShader(VertexShader );
DeleteShader(FragmentShader);
return;
}
sfn LoadSimpleShader()
{
SimpleShader = LoadShaders("SimpleVertexShader.vert", "SimpleFragmentShader.frag");
return;
}
sfn LoadDefaultShaders() sfn LoadDefaultShaders()
{ {
LoadRawShader (); Basic_LightShader::LoadShader();
LoadSimpleShader(); PhongShader ::LoadShader();
SS_Transformed ::LoadShader ();
Basic_LampShader ::LoadShader ();
Basic_LightingShader::LoadShader ();
PhongShader ::LoadShader ();
return; return;
} }

View File

@ -106,7 +106,7 @@ namespace DGL
UpDirection ( 0, 1, 0), UpDirection ( 0, 1, 0),
FrontDirection( 0, 0, 1) ; FrontDirection( 0, 0, 1) ;
gInt ScreenWidth = 720, ScreenHeight = 540, ScreenCenterWidth = ScreenWidth / 2, ScreenCenterHeight = ScreenHeight / 2; gInt ScreenWidth = 1280, ScreenHeight = 800, ScreenCenterWidth = ScreenWidth / 2, ScreenCenterHeight = ScreenHeight / 2;
} }
struct Camera struct Camera

View File

@ -1,13 +1,21 @@
/* /*
Title : Execution
Author: Edward R. Gonzalez
Description:
This brings together the functionality I made in DGL and the Actions libraries to produce an OpenGL Workspace.
Currently the workspace is heavily hardcoded and has one light rotating around the specified object. The material for the object is set during prep as well.
All exposed library references are inside the inline namespace right after declaring the namespace execution.
After I have the global objects used, followed by the functionality implementations, and at the very end the main function running the default execution implementation.
*/ */
// DGL // DGL
#include "DGL.hpp" #include "DGL/DGL.hpp"
// Utility // Utility
#include "Actions.hpp" #include "Actions.hpp"
@ -86,25 +94,37 @@ namespace Execution
using Actions::ActionQueue; using Actions::ActionQueue;
} }
enum class EModels
{
Bunny ,
Cube ,
Eight ,
Gargoyle ,
Hand ,
Sculpture,
Topology ,
Torus
};
// Globals // Globals
bool Exist = true; // Determines if the the execution should exit cycler. bool Exist = true; // Determines if the the execution should exit cycler.
TimeValDec CycleStart , // Snapshot of cycle loop start time. TimeValDec CycleStart , // Snapshot of cycle loop start time.
CycleEnd , // Snapshot of cycle loop end time. CycleEnd , // Snapshot of cycle loop end time.
DeltaTime , // Delta between last cycle start and end. DeltaTime , // Delta between last cycle start and end.
InputInterval = 1.0f / 480.0f, // Interval per second to complete the input process of the cycle. InputInterval = 1.0f / 144.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. PhysicsInterval = 1.0f / 144.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. RenderInterval = 1.0f / 144.0f ; // Interval per second to complete the render process of the cycle.
ptr<Window> DefaultWindow; // Default window to use for execution. ptr<Window> DefaultWindow; // Default window to use for execution.
double CursorX, CursorY; // Cursor axis position on the window. double CursorX, CursorY; // Cursor axis position on the window.
bool CursorOff = true; bool CursorOff = true, ShowLight = true;
gFloat CamMoveSpeed = 8.0f, // Rate at which the camera should move. gFloat CamMoveSpeed = 7.0f, // Rate at which the camera should move.
CamRotationSpeed = 27.0f ; // Rate at which the camera should rotate. CamRotationSpeed = 27.0f ; // Rate at which the camera should rotate.
TimeValDec InputDelta = 0.0, // Current delta since last input process. TimeValDec InputDelta = 0.0, // Current delta since last input process.
@ -113,7 +133,17 @@ namespace Execution
ActionQueue ActionsToComplete; // Actions queue to run during the physics process of the cycle. ActionQueue ActionsToComplete; // Actions queue to run during the physics process of the cycle.
Model objectModel("torus.obj"); // Hardcoded to specified obj file for now. EModels CurrentModel = EModels::Torus;
Model Bunny ("./Models/bunny.obj" );
Model Cube ("./Models/blenderCube2.obj");
Model Eight ("./Models/eight.obj" );
Model Gargoyle ("./Models/gargoyle.obj" );
Model Hand ("./Models/hand.obj" );
Model Horse ("./Models/horse.obj" );
Model Sculpture("./Models/sculpture.obj" );
Model Topology ("./Models/topology.obj" );
Model Torus ("./Models/Torus.obj" );
Material_Phong ObjectMaterial; Material_Phong ObjectMaterial;
@ -121,11 +151,183 @@ namespace Execution
Entity_Basic ObjectToView; // Object that will be currently in the middle with the light source rotating. Entity_Basic ObjectToView; // Object that will be currently in the middle with the light source rotating.
string
windowTitle = "Assignment 1" ,
deltaStr = "Delta: " ,
inputDeltaStr = "Input Delta: " ,
physicsDeltaStr = "Physics Delta: " ,
renderDeltaStr = "RenderDeltaStr: " ;
stringstream WindowTitle;
// Functionality // Functionality
sfn ChangeModel()
{
if (CurrentModel == EModels::Torus)
{
CurrentModel = EModels::Bunny;
}
else
{
CurrentModel = EModels(int(CurrentModel) + 1);
}
switch (CurrentModel)
{
case EModels::Bunny:
{
if (not Bunny.Ready())
{
glfwSetWindowTitle(DefaultWindow, "Assignment 1: Loading Bunny...");
Bunny.Load();
}
ObjectToView.SetModel(Bunny);
ObjectToView.SetScale(4.0f);
ObjectToView.SetPosition(Vector3(-0.05, -4.4f, 0));
return;
}
case EModels::Cube:
{
if (not Cube.Ready())
{
glfwSetWindowTitle(DefaultWindow, "Assignment 1: Loading Cube...");
Cube.Load();
}
ObjectToView.SetModel(Cube);
ObjectToView.SetScale(1.0f);
ObjectToView.SetPosition(Vector3(0, -1.0, 0));
return;
}
case EModels::Eight:
{
if (not Eight.Ready())
{
glfwSetWindowTitle(DefaultWindow, "Assignment 1: Loading Eight...");
Eight.Load();
}
ObjectToView.SetModel(Eight);
//ObjectToView.Scale(1.0f);
ObjectToView.SetPosition(Vector3(0, -1.0, 0));
return;
}
case EModels::Gargoyle:
{
if (not Gargoyle.Ready())
{
glfwSetWindowTitle(DefaultWindow, "Assignment 1: Loading Gargoyle...");
Gargoyle.Load();
}
ObjectToView.SetModel(Gargoyle);
ObjectToView.SetPosition(Vector3(-1, -5.4f, 0));
ObjectToView.SetScale(6.0f);
return;
}
case EModels::Hand:
{
if (not Hand.Ready())
{
glfwSetWindowTitle(DefaultWindow, "Assignment 1: Loading Hand...");
Hand.Load();
}
ObjectToView.SetModel(Hand);
ObjectToView.SetScale(0.03f);
ObjectToView.SetPosition(Vector3(0, -1.1f, 0));
return;
}
case EModels::Sculpture:
{
if (not Sculpture.Ready())
{
glfwSetWindowTitle(DefaultWindow, "Assignment 1: Loading Sculpture...");
Sculpture.Load();
}
ObjectToView.SetModel(Sculpture);
ObjectToView.SetScale(0.01f);
return;
}
case EModels::Topology:
{
if (not Topology.Ready())
{
glfwSetWindowTitle(DefaultWindow, "Assignment 1: Loading Topology...");
Topology.Load();
}
ObjectToView.SetModel(Topology);
ObjectToView.SetScale(0.2f);
return;
}
case EModels::Torus:
{
if (not Torus.Ready())
{
glfwSetWindowTitle(DefaultWindow, "Assignment 1: Loading Torus...");
Torus.Load();
}
ObjectToView.SetModel(Torus);
ObjectToView.SetScale(1.0f);
return;
}
}
}
deduce ChangeModelDelegate = Delegate<decltype(ChangeModel)>(ChangeModel);
sfn ToggleLight()
{
if (ShowLight)
{
ShowLight = false;
}
else
{
ShowLight = true;
}
}
deduce ToogleLightDelegate = Delegate<decltype(ToggleLight)>(ToggleLight);
// Input Action common functions... // Input Action common functions...
@ -164,6 +366,18 @@ namespace Execution
// End of common input functions... // End of common input functions...
sfn UpdateWindowDeltaTitle()
{
WindowTitle.str("");
WindowTitle
<< windowTitle << " "
<< deltaStr << DeltaTime << " "
<< inputDeltaStr << InputDelta << " "
<< physicsDeltaStr << PhysicsDelta << " "
<< renderDeltaStr << RenderDelta ;
}
// Currently Does everything required before entering the cycler. // Currently Does everything required before entering the cycler.
@ -204,15 +418,14 @@ namespace Execution
Light.Load(); Light.Load();
objectModel.Load (); Torus.Load();
objectModel.Buffer();
ObjectMaterial.Color = DGL::Colors::GreyColor.Vector(); ObjectMaterial.Color = DGL::Colors::WarmSphia.Vector();
ObjectMaterial.Ambience = 0.01f ; ObjectMaterial.Ambience = 0.112f ;
ObjectMaterial.Diffuse = 1.0f ; ObjectMaterial.Diffuse = 0.928f ;
ObjectMaterial.Specular = 0.4f ; ObjectMaterial.Specular = 0.21f ;
ObjectToView = Entity_Basic(objectModel, ObjectMaterial); ObjectToView = Entity_Basic(Torus, ObjectMaterial);
} }
@ -264,7 +477,7 @@ namespace Execution
{ {
ClearBuffer(EFrameBuffer::Color, EFrameBuffer::Depth); ClearBuffer(EFrameBuffer::Color, EFrameBuffer::Depth);
SetClearColor(LinearColor(0.12f, 0.12f, 0.12f, 1.0f)); SetClearColor(LinearColor(0.02f, 0.02f, 0.02f, 1.0f));
_renderProcedure(); _renderProcedure();
@ -290,7 +503,6 @@ namespace Execution
return; return;
} }
sfn InputProcedure(ptr<Window> _currentWindowContext) sfn InputProcedure(ptr<Window> _currentWindowContext)
{ {
if (KeyPressed(_currentWindowContext, EKeyCodes::F1)) if (KeyPressed(_currentWindowContext, EKeyCodes::F1))
@ -316,6 +528,16 @@ namespace Execution
} }
} }
if (KeyPressed(_currentWindowContext, EKeyCodes::H))
{
ActionsToComplete.AddToQueue(ToogleLightDelegate);
}
if (KeyPressed(_currentWindowContext, EKeyCodes::M))
{
ActionsToComplete.AddToQueue(ChangeModelDelegate);
}
if (KeyPressed(_currentWindowContext, EKeyCodes::UpArrow)) if (KeyPressed(_currentWindowContext, EKeyCodes::UpArrow))
{ {
ActionsToComplete.AddToQueue(ModifyCamSpeedDelegate, true, PhysicsDelta); ActionsToComplete.AddToQueue(ModifyCamSpeedDelegate, true, PhysicsDelta);
@ -400,35 +622,13 @@ namespace Execution
} }
} }
std::string
windowTitle = "Assignment 1" ,
deltaStr = "Delta: " ,
inputDeltaStr = "Input Delta: " ,
physicsDeltaStr = "Physics Delta: " ,
renderDeltaStr = "RenderDeltaStr: " ;
std::stringstream somethingtoupdate;
sfn UpdateWindowDeltaTitle()
{
somethingtoupdate.str("");
somethingtoupdate
<< windowTitle << " "
<< deltaStr << DeltaTime << " "
<< inputDeltaStr << InputDelta << " "
<< physicsDeltaStr << PhysicsDelta << " "
<< renderDeltaStr << RenderDelta ;
}
sfn PhysicsProcedure() sfn PhysicsProcedure()
{ {
WorldCamera.UpdateCamera(); WorldCamera.UpdateCamera();
UpdateScreenspace(); UpdateScreenspace();
Light.Update(); Light.Update(gFloat(PhysicsDelta));
ObjectToView.Update(); ObjectToView.Update();
@ -437,15 +637,17 @@ namespace Execution
sfn RenderProcedure() -> void sfn RenderProcedure() -> void
{ {
glfwSetWindowTitle(DefaultWindow, somethingtoupdate.str().c_str()); glfwSetWindowTitle(DefaultWindow, WindowTitle.str().c_str());
Light.Render(WorldCamera.Perspective, WorldCamera.Viewport); if (ShowLight)
{
Light.Render(WorldCamera.Perspective, WorldCamera.Viewport);
}
ObjectToView.Render(WorldCamera.Perspective, WorldCamera.Viewport, Light.GetPosition(), Light.GetColor()); ObjectToView.Render(WorldCamera.Perspective, WorldCamera.Viewport, Light.GetPosition(), Light.GetColor());
} }
// Runtime Execution: Default Execution // Runtime Execution: Default Execution
sfn Execute() -> ExitCode sfn Execute() -> ExitCode

View File

@ -1,4 +1,5 @@
#version 330 core #version 330 core
layout (location = 0) in vec3 aPos; layout (location = 0) in vec3 aPos;

View File

@ -28,7 +28,7 @@ void main()
FragPosition = vec3(Viewport * ModelSpace * vec4(VertPosition, 1.0)); FragPosition = vec3(Viewport * ModelSpace * vec4(VertPosition, 1.0));
Normal = mat3(transpose(inverse(InverseModelSpace))) * VertNormal; Normal = mat3(transpose(InverseModelSpace)) * VertNormal;
LightViewPosition = vec3(Viewport * vec4(LightPosition, 1.0)); LightViewPosition = vec3(Viewport * vec4(LightPosition, 1.0));
} }

View File

@ -1,12 +0,0 @@
#version 330 core
out vec3 color;
void main()
{
color = vec3(0.345, 0.345, 1);
}

View File

@ -1,13 +0,0 @@
#version 330 core
layout (location = 0) in vec3 vertexPosition_modelSpace;
void main()
{
gl_Position.xyz = vertexPosition_modelSpace;
gl_Position.w = 1.0 ;
}

View File

@ -1,12 +0,0 @@
#version 330 core
// Output data
out vec3 color;
void main()
{
// Output color = red
color = vec3(1,0,0);
}

View File

@ -1,513 +0,0 @@
#pragma once
#include "DGL.hpp"
#include "Cpp_Alias.hpp"
using DGL::gFloat;
using DGL::VertexArray;
using DGL::EBufferTarget;
using DGL::EBufferUsage;
using DGL::VertexBuffer;
using DGL::ID;
using DGL::gInt;
using DGL::gSize;
using DGL::LinearColor;
using DGL::Vector3;
using DGL::ZeroOffset;
struct RAWBS
{
float bullshit[6 * 6 * 2 *3];
};
float vertices[] = {
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
-0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
-0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f,
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
-0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
-0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
-0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f,
-0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
-0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f,
0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f,
-0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
-0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f,
-0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
-0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f,
-0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f
};
//DGL::DefaultSpace::WorldSpace = DGL::Rotate(DGL::DefaultSpace::WorldSpace, 0.015f, Vector3(0.0f, 1.0f, 0.0f));
// This will identify our vertex buffer
ID<VertexBuffer> 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<VertexArray> 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(VertexArrayObj , 1);
DGL::GenerateBuffers (VertexBufferObj, 1);
DGL::GenerateBuffers (ElemBufferObj , 1);
}
sfn RAW_SetupTriangleBuffer()
{
DGL::GenerateBuffers(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>(rectCompress, EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
DGL::BindBuffer(EBufferTarget::VertexIndices, ElemBufferObj);
DGL::BufferData<RectangleIndices>(rectIndices, EBufferTarget::VertexIndices, EBufferUsage::StaticDraw);
}
DGL::gInt VertexAttributeIndex = 0; // See shader source: (layout = 0).
using DGL::EBool;
using DGL::EDataType;
// 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));
}
struct Edge3
{
TriIndex a, b;
};
struct VertPhong
{
Vertex3 locationPad,
normalPad ;
};
struct CubeVerts
{
Vertex3
f1, f2, f3, f4, // Front
b1, b2, b3, b4; // Back
};
struct CubeElements
{
Edge3 front, right, back, left, bottom, top;
};
using DGL::CoordSpace;
using DGL::Matrix4x4;
using DGL::Model;
ID<VertexArray> CubeVAO;
ID<VertexBuffer > CubeModelBuffer ;
ID<ElementBuffer> CubeModelElements;
sfn RAW_MakeCube()
{
DGL::GenerateVertexBuffers(CubeVAO , 1);
DGL::GenerateBuffers (CubeModelBuffer , 1);
DGL::GenerateBuffers (CubeModelElements, 1);
DGL::BindVertexArray(CubeVAO);
DGL::BindBuffer(EBufferTarget::VertexAttributes, CubeModelBuffer);
DGL::BufferData<CubeVerts>(DefaultCube, EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw);
DGL::BindBuffer(EBufferTarget::VertexIndices, CubeModelElements);
DGL::BufferData<CubeElements>(DefaultCubeElements, EBufferTarget::VertexIndices, EBufferUsage::StaticDraw);
DGL::FormatVertexAttributes<Vertex3>(0, EDataType::Float, ZeroOffset(), Vertex3::ValueCount(), false);
DGL::EnableVertexAttributeArray(0);
}
sfn RAW_RenderCube()
{
DGL::BindBuffer(EBufferTarget::VertexIndices, CubeModelElements);
gInt SizeRef; GetBufferParameterIV(EBufferTarget::VertexIndices, DGL::EBufferParam::Size, SizeRef);
SizeRef /= sizeof(unsigned int);
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(0, 0, 0);
Vector3 LightScale = Vector3(0.2f);
Vector3 result = LightColor.Vector() * CoralColor.Vector();
CoordSpace LightTransform = Matrix4x4(1.0f);
gFloat TranslationScale = 4.0f;
ID<VertexArray> LightVAO;
sfn RAW_MakeLightVAO()
{
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(), false);
DGL::EnableVertexAttributeArray(0);
LightTransform = DGL::Translate(LightTransform, LightPosition);
LightTransform = DGL::Scale (LightTransform, LightScale );
}
sfn RAW_UpdateLightTransform(gFloat _delta)
{
/*static bool test = true;
LightTransform = CoordSpace(1.0f);
if (test)
{
LightPosition.x += 0.021f + _delta;
if (LightPosition.x > 10)
{
test = false;
}
LightTransform = DGL::Translate(LightTransform, LightPosition);
LightTransform = DGL::Scale (LightTransform, LightScale );
}
else
{
LightPosition.x -= 0.021f + _delta;
if (LightPosition.x < -10)
{
test = true;
}
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 );
}
using DGL::GetBufferParameterIV;
sfn RAW_RenderLight(CoordSpace _projection, CoordSpace _viewport)
{
deduce screenspaceTransform = _projection * _viewport * LightTransform;
DGL::Basic_LampShader::Use(screenspaceTransform);
DGL::BindVertexArray(LightVAO);
RAW_RenderCube();
DGL::Basic_LampShader::Stop();
}
Vector3 LitCubePosition = Vector3(0.0f);
Vector3 CubeColor = CoralColor.Vector();
CoordSpace LitCubeTransform = Matrix4x4(1.0f);
gFloat RotationRate = 0.015f;
ID<VertexArray> LitCubeVAO;
sfn RAW_MakeLitCube()
{
DGL::GenerateVertexBuffers(LitCubeVAO, 1);
DGL::BindVertexArray(LitCubeVAO);
DGL::BindBuffer(EBufferTarget::VertexAttributes, CubeModelBuffer );
DGL::BindBuffer(EBufferTarget::VertexIndices , CubeModelElements);
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));
}
sfn RAW_RenderLitCube(CoordSpace _projection, CoordSpace _viewport)
{
CoordSpace screenspaceTransform = _projection * _viewport * LitCubeTransform;
Vector3 lightColor = LightColor.Vector();
DGL::BindVertexArray(LitCubeVAO);
RAW_RenderCube();
}
using DGL::NormalBuffer;
namespace ProperCube
{
Model model("blenderCube2.obj");
Vector3 position = Vector3(0.0f);
Vector3 color = SomeColor.Vector();
CoordSpace transform = Matrix4x4(1.0f);
sfn Rotate(gFloat _delta)
{
//transform = DGL::Rotate(transform, 0.75f * _delta, Vector3(0, 1, 0));
}
sfn Render(Ref(CoordSpace) _projection, Ref(CoordSpace) _viewport, Ref(Vector3) _cameraPosition)
{
CoordSpace screenspaceTransform = _projection * _viewport * transform;
Vector3 lightColor = LightColor.Vector();
DGL::PhongShader::Use_Old
(
_projection ,
_viewport ,
transform ,
color ,
LightPosition ,
lightColor ,
_cameraPosition
);
model.Render();
DGL::PhongShader::Stop();
}
using DGL::Offset;
sfn Setup()
{
model.Load();
model.Buffer();
//transform = DGL::Scale(transform, Vector3(0.01));
}
}