diff --git a/3.3.shader.frag b/3.3.shader.frag deleted file mode 100644 index ad6e077..0000000 --- a/3.3.shader.frag +++ /dev/null @@ -1,10 +0,0 @@ -#version 330 core -out vec4 FragColor; - -in vec3 ourColor; - -void main() -{ - FragColor = vec4(ourColor, 1.0f); -} - diff --git a/3.3.shader.vert b/3.3.shader.vert deleted file mode 100644 index f391c5f..0000000 --- a/3.3.shader.vert +++ /dev/null @@ -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 diff --git a/5.1.transform.frag b/5.1.transform.frag deleted file mode 100644 index 73ce33b..0000000 --- a/5.1.transform.frag +++ /dev/null @@ -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); -} - diff --git a/5.1.transform.vert b/5.1.transform.vert deleted file mode 100644 index 036ab96..0000000 --- a/5.1.transform.vert +++ /dev/null @@ -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); -} - diff --git a/6.3.coordinate_systems.frag b/6.3.coordinate_systems.frag deleted file mode 100644 index 0bbee43..0000000 --- a/6.3.coordinate_systems.frag +++ /dev/null @@ -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); -} - diff --git a/6.3.coordinate_systems.vert b/6.3.coordinate_systems.vert deleted file mode 100644 index 3be8fc0..0000000 --- a/6.3.coordinate_systems.vert +++ /dev/null @@ -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); -} - diff --git a/Actions.hpp b/Actions.hpp index 926c5ab..abeacbe 100644 --- a/Actions.hpp +++ b/Actions.hpp @@ -2,13 +2,12 @@ Title : Actions 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. 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 { - using IndexType = DataSize; + using IndexType = DataSize ; + using TypeIndex = std::type_index; struct IAction { - virtual sfn DoAction() -> void = NULL; + virtual sfn DoAction () -> void = NULL; }; template struct AAction : IAction { + public: using ActionType = Delegate< FunctionType >; - public: AAction(ro Ref(ActionType) _actionToAssign, ro Ref(ActionParams)... _params) : action(_actionToAssign), params(_params... ), @@ -49,11 +49,23 @@ namespace Actions return done; } - sfn IsSame(ro Ref(ActionParams)... _paramsForAction) -> bool + sfn IsSame(ro Ref(ActionType) _action, ro Ref(ActionParams)... _paramsForAction) -> bool { Tuple paramsToCheck(_paramsForAction...); - if (params == paramsToCheck) + if (params == paramsToCheck && SameAction(_action)) + { + return true; + } + else + { + return false; + } + } + + sfn SameAction(ro Ref(ActionType) _action) + { + if (action.target() == _action.target()) { return true; } @@ -70,11 +82,11 @@ namespace Actions done = false; } - private: - sfn DoAction_Implementation(ro Ref(ActionParams)... _params) { action(_params...); } + protected: + virtual sfn DoAction_Implementation(ro Ref(ActionParams)... _params) -> void { action(_params...); } template // TuplePackSequence - sfn ExpandTuple_CallDoActionImplementaiton(ro Ref(Tuple) _paramsToExpand, std::index_sequence ) + sfn ExpandTuple_CallDoActionImplementaiton(ro Ref(Tuple) _paramsToExpand, std::index_sequence ) -> void { // ExpandTuplePack DoAction_Implementation(std::get(_paramsToExpand)...); @@ -82,7 +94,7 @@ namespace Actions Tuple params; - ActionType action; + ro Ref(ActionType) action; bool done; @@ -101,12 +113,87 @@ namespace Actions }; }; + // TODO: This doesn't work yet... + template + class AAction_ObjectBound : public AAction + { + public: + using ActionType = Delegate; + + AAction_ObjectBound(Ref(ObjectType) _objectRef, ro Ref(ActionType) _actionToAssign, ro Ref(ActionParams)... _params) : + AAction::action(_actionToAssign), + AAction::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 paramsToCheck(_params...); + + if (AAction::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::action)(_params...); + } + + template // TuplePackSequence + sfn ExpandTuple_CallDoActionImplementaiton(ro Ref(Tuple) _paramsToExpand, std::index_sequence ) -> void + { + // ExpandTuplePack + DoAction_Implementation(std::get(_paramsToExpand)...); + } + + + Ref(ObjectType) object; + + + public: // IAction + + virtual sfn DoAction() -> void override + { + ExpandTuple_CallDoActionImplementaiton + ( + AAction::params, + // MakeTuplePackSequence () + std::index_sequence_for() + ); + + AAction::params::done = true; + }; + }; + struct ActionPool_Dynamic { template using AllocationsOf = std::forward_list; - - using TypeIndex = std::type_index ; + using Managed_AAction = SPtr < IAction >; using Managed_AActions = AllocationsOf < Managed_AAction >; using AActions_Registry = std::map ; @@ -141,13 +228,60 @@ namespace Actions 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>(possibleAction->get()); - if (castedEntry->IsSame(_paramsForAction...)) + if (castedEntry->IsSame(_actionToQueue, _paramsForAction...)) { return castedEntry; } - else if (castedEntry->Used()) + else if (castedEntry->Used() && castedEntry->SameAction(_actionToQueue)) + { + castedEntry->ReInitalize(_paramsForAction...); + + return castedEntry; + } + } + + SPtr< IAction> newAction = MakeSPtr< AAction>(_actionToQueue, _paramsForAction...); + ptr < IAction> returnRef = newAction.get (); + + aActions_Available.at(AActionID).push_front(newAction); + + return returnRef; + } + + SPtr< IAction> newAction = MakeSPtr< AAction>(_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 + sfn Request_AAction(ro Ref(ObjectType) _objectRef, ro Ref(Delegate< FunctionType>) _actionToQueue, ro Ref(ActionParams)... _paramsForAction) -> ptr + { + using ActionType = AAction_ObjectBound; + + 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>(possibleAction->get()); + + if (castedEntry->IsSame(_actionToQueue, _paramsForAction...)) + { + return castedEntry; + } + else if (castedEntry->Used() && castedEntry->SameAction(_actionToQueue)) { castedEntry->ReInitalize(_paramsForAction...); @@ -222,6 +356,38 @@ namespace Actions } } + template + sfn AddToQueue(ro Ref(ObjectType) _objectRef, ro Ref(Delegate< FunctionType>) _actionToQueue, ro Ref(ActionParams)... _paramsForAction) + { + using GeneratedActionType = AAction_ObjectBound; + + 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() { if (actionQueue.size() > 0) diff --git a/BasicLighting.frag b/BasicLighting.frag deleted file mode 100644 index d972c42..0000000 --- a/BasicLighting.frag +++ /dev/null @@ -1,15 +0,0 @@ -#version 330 core - - - -out vec4 FragColor; - -uniform vec3 ObjectColor; -uniform vec3 LightColor ; - - - -void main() -{ - FragColor = vec4(LightColor * ObjectColor, 1.0); -} \ No newline at end of file diff --git a/DGL.hpp b/DGL.hpp deleted file mode 100644 index 7777233..0000000 --- a/DGL.hpp +++ /dev/null @@ -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" diff --git a/DGL/DGL.hpp b/DGL/DGL.hpp new file mode 100644 index 0000000..9a64ebe --- /dev/null +++ b/DGL/DGL.hpp @@ -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" diff --git a/DGL_Buffers.hpp b/DGL/DGL_Buffers.hpp similarity index 96% rename from DGL_Buffers.hpp rename to DGL/DGL_Buffers.hpp index a45c033..3efee7e 100644 --- a/DGL_Buffers.hpp +++ b/DGL/DGL_Buffers.hpp @@ -1,3 +1,11 @@ +/* +Title : Ducktaped GL: Buffers +Author: Edward R. Gonzalez + +Description: +Contains wrappers to buffer related functionality. +*/ + #pragma once // GLEW diff --git a/DGL_Entity.hpp b/DGL/DGL_Entity.hpp similarity index 69% rename from DGL_Entity.hpp rename to DGL/DGL_Entity.hpp index 15693fa..5d0d164 100644 --- a/DGL_Entity.hpp +++ b/DGL/DGL_Entity.hpp @@ -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 @@ -12,13 +20,15 @@ #include "Cpp_Alias.hpp" + namespace DGL { namespace Colors { - LinearColor CoralColor(1.0f , 0.5f , 0.31f, 1.0f); - LinearColor GreyColor (0.60f, 0.60f, 0.60f, 1.0f); - LinearColor LightColor(1.0f , 1.0f , 1.0f , 1.0f); + LinearColor Coral (1.0f , 0.5f , 0.31f, 1.0f); + LinearColor Grey (0.60f, 0.60f, 0.60f, 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: Light_Basic() : - color (Colors::LightColor.Vector()), - position (Vector3 (0.0f) ), - scale (Vector3 (0.2f) ), - transform (CoordSpace(1.0f) ), - translationRadius(4.0f ) + color (Colors::White.Vector()), + position (Vector3 (0.0f) ), + scale (Vector3 (0.2f) ), + transform (CoordSpace(1.0f) ), + translationRadius(4.0f ) {} @@ -67,22 +77,26 @@ namespace DGL UnbindVertexArray(); } - sfn Update() + sfn Update(double _delta) { + static gFloat valueLoop = 0.0f; + transform = CoordSpace(1.0f); - position.x = translationRadius * sin(GetTime()); - position.z = translationRadius * cos(GetTime()); + position.x = translationRadius * sin(valueLoop); + position.z = translationRadius * cos(valueLoop); transform = Translate(transform, position); transform = Scale (transform, scale ); + + valueLoop += 0.31879f * _delta; } sfn Render(ro Ref(CoordSpace) _projection, ro Ref(CoordSpace) _viewport) { deduce screenspaceTransform = _projection * _viewport * transform; - Basic_LampShader::Use(screenspaceTransform); + Basic_LightShader::Use(screenspaceTransform); BindVertexArray(modelVAO); @@ -92,7 +106,9 @@ namespace DGL DrawElements(EPrimitives::Triangles, SizeRef, EDataType::UnsignedInt, ZeroOffset()); - Basic_LampShader::Stop(); + //UnbindVertexArray(); + + Basic_LightShader::Stop(); } private: @@ -183,18 +199,47 @@ namespace DGL public: Entity_Basic() : position (Vector3(0.0f) ), - model ("" ), + scale (Vector3(1.0f) ), + model (NULL ), transform(CoordSpace(1.0f)) {}; Entity_Basic(Ref(Model) _model, Ref(Material_Phong) _material) : position (Vector3(0.0f) ), - model (_model ), + scale (Vector3(1.0f) ), + model (Address(_model) ), transform(CoordSpace(1.0f)), material (_material ) //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() { @@ -204,7 +249,7 @@ namespace DGL { PhongShader::Use(_projection, _viewport, transform, _lightPosition,_lightColor, material); - model.Render(); + Dref(model).Render(); PhongShader::Stop(); @@ -214,6 +259,7 @@ namespace DGL sfn operator= (ro Ref(Entity_Basic) _entity)->Ref(Entity_Basic) { position = _entity.position ; + scale = _entity.scale; model = _entity.model ; transform = _entity.transform; material = _entity.material ; @@ -226,7 +272,8 @@ namespace DGL //EEntityType type; Vector3 position ; - Model model ; + Vector3 scale ; + ptr model ; CoordSpace transform ; Material_Phong material ; }; diff --git a/DGL_Enum.hpp b/DGL/DGL_Enum.hpp similarity index 96% rename from DGL_Enum.hpp rename to DGL/DGL_Enum.hpp index 48af0f2..1a0f237 100644 --- a/DGL_Enum.hpp +++ b/DGL/DGL_Enum.hpp @@ -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 // GLEW #include +// GLFW +#include + namespace DGL @@ -119,10 +130,12 @@ namespace DGL A = GLFW_KEY_A , D = GLFW_KEY_D , E = GLFW_KEY_E , + H = GLFW_KEY_H , I = GLFW_KEY_I , J = GLFW_KEY_J , K = GLFW_KEY_K , L = GLFW_KEY_L , + M = GLFW_KEY_M , Q = GLFW_KEY_Q , S = GLFW_KEY_S , W = GLFW_KEY_W , diff --git a/DGL_Model.hpp b/DGL/DGL_Model.hpp similarity index 97% rename from DGL_Model.hpp rename to DGL/DGL_Model.hpp index 59316d0..78c9990 100644 --- a/DGL_Model.hpp +++ b/DGL/DGL_Model.hpp @@ -1,3 +1,11 @@ +/* +Title : Ducktaped GL: Model +Author: Edward R. Gonzalez + +Description: + +*/ + #pragma once // DGL @@ -158,6 +166,7 @@ namespace DGL public: Model(ro Ref(string) _filePath) : + loaded (false ), vertexArrayID (0 ), vertexBufferID (0 ), normalBuffferID(0 ), @@ -385,6 +394,10 @@ namespace DGL fileBuffer.close(); + Buffer(); + + loaded = true; + return; } else @@ -393,6 +406,11 @@ namespace DGL } } + sfn Ready() -> bool + { + return loaded; + } + sfn Render() { BindVertexArray(vertexArrayID); @@ -430,6 +448,8 @@ namespace DGL // Components + bool loaded; + ID vertexArrayID ; ID vertexBufferID ; ID normalBuffferID; diff --git a/DGL_Shader.hpp b/DGL/DGL_Shader.hpp similarity index 64% rename from DGL_Shader.hpp rename to DGL/DGL_Shader.hpp index d1baaf3..0eacfe1 100644 --- a/DGL_Shader.hpp +++ b/DGL/DGL_Shader.hpp @@ -159,7 +159,6 @@ namespace DGL { using std::vector; - string vertexShaderCode ; string fragmentShaderCode ; @@ -308,195 +307,7 @@ namespace DGL return; } - - - // 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 shaderID; - - // ID modelSpaceID, inverseModelSpaceID, viewportID, projectionID; - - // ID lightPositionID, viewPositionID, objectColorID, lightColorID; - - // gInt vertexIndexID, normalIndexID; - //}; - - - - - - // Old - - // Some Raw Source Defaults: - - RawString 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 RawFragmentShaderSource = - "#version 400\n" - - "out vec4 frag_colour;" - - "void main() {" - - " frag_colour = vec4(0.5, 0.0, 0.5, 1.0);" - - "}"; - - - // Default Shaders - - ID RawShader , - SimpleShader ; - - - - namespace SS_Transformed - { - ID Shader; - - ID 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 Shader; - - ID ScreenSpaceVarID; - - ID 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 + namespace Basic_LightShader { ID Shader; @@ -504,7 +315,7 @@ namespace DGL sfn LoadShader() { - Shader = LoadShaders("SimpleTransform.vert", "BasicLamp.frag"); + Shader = LoadShaders("./Shaders/BasicLight.vert", "./Shaders/BasicLight.frag"); ScreenSpaceVarID = GetUniformVariable(Shader, "ScreenSpaceTransform"); @@ -554,7 +365,7 @@ namespace DGL sfn LoadShader() { - ShaderID = LoadShaders("PhongShader.vert", "PhongShader.frag"); + ShaderID = LoadShaders("./Shaders/PhongShader.vert", "./Shaders/PhongShader.frag"); InverseModelSpaceID = GetUniformVariable(ShaderID, "InverseModelSpace"); ModelSpaceID = GetUniformVariable(ShaderID, "ModelSpace" ); @@ -572,37 +383,6 @@ namespace DGL 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 ( ro Ref(CoordSpace ) _projection , @@ -646,37 +426,10 @@ namespace DGL } } - sfn LoadRawShader() - { - ID VertexShader = 0; - ID 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() { - LoadRawShader (); - LoadSimpleShader(); - SS_Transformed ::LoadShader (); - Basic_LampShader ::LoadShader (); - Basic_LightingShader::LoadShader (); - PhongShader ::LoadShader (); + Basic_LightShader::LoadShader(); + PhongShader ::LoadShader(); return; } diff --git a/DGL_Space.hpp b/DGL/DGL_Space.hpp similarity index 98% rename from DGL_Space.hpp rename to DGL/DGL_Space.hpp index fe3eb36..6f603d2 100644 --- a/DGL_Space.hpp +++ b/DGL/DGL_Space.hpp @@ -106,7 +106,7 @@ namespace DGL UpDirection ( 0, 1, 0), 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 diff --git a/DGL_Types.hpp b/DGL/DGL_Types.hpp similarity index 100% rename from DGL_Types.hpp rename to DGL/DGL_Types.hpp diff --git a/DGL_Utilities.hpp b/DGL/DGL_Utilities.hpp similarity index 100% rename from DGL_Utilities.hpp rename to DGL/DGL_Utilities.hpp diff --git a/Execution.cpp b/Execution.cpp index b60cd96..7f04062 100644 --- a/Execution.cpp +++ b/Execution.cpp @@ -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 -#include "DGL.hpp" +#include "DGL/DGL.hpp" // Utility #include "Actions.hpp" @@ -86,25 +94,37 @@ namespace Execution using Actions::ActionQueue; } + enum class EModels + { + Bunny , + Cube , + Eight , + Gargoyle , + Hand , + Sculpture, + Topology , + Torus + }; + // 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 / 480.0f, // Interval per second to complete the input process of the cycle. - PhysicsInterval = 1.0f / 240.0f, // Interval per second to complete the physics process of the cycle. + 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 / 144.0f, // Interval per second to complete the input 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. ptr DefaultWindow; // Default window to use for execution. 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. 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. - 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; @@ -121,11 +151,183 @@ namespace Execution 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 + 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(ChangeModel); + + sfn ToggleLight() + { + if (ShowLight) + { + ShowLight = false; + } + else + { + ShowLight = true; + } + } + + deduce ToogleLightDelegate = Delegate(ToggleLight); // Input Action common functions... @@ -164,6 +366,18 @@ namespace Execution // 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. @@ -204,15 +418,14 @@ namespace Execution Light.Load(); - objectModel.Load (); - objectModel.Buffer(); + Torus.Load(); - ObjectMaterial.Color = DGL::Colors::GreyColor.Vector(); - ObjectMaterial.Ambience = 0.01f ; - ObjectMaterial.Diffuse = 1.0f ; - ObjectMaterial.Specular = 0.4f ; + ObjectMaterial.Color = DGL::Colors::WarmSphia.Vector(); + ObjectMaterial.Ambience = 0.112f ; + ObjectMaterial.Diffuse = 0.928f ; + 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); - SetClearColor(LinearColor(0.12f, 0.12f, 0.12f, 1.0f)); + SetClearColor(LinearColor(0.02f, 0.02f, 0.02f, 1.0f)); _renderProcedure(); @@ -290,7 +503,6 @@ namespace Execution return; } - sfn InputProcedure(ptr _currentWindowContext) { 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)) { 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() { WorldCamera.UpdateCamera(); UpdateScreenspace(); - Light.Update(); + Light.Update(gFloat(PhysicsDelta)); ObjectToView.Update(); @@ -437,15 +637,17 @@ namespace Execution 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()); } - // Runtime Execution: Default Execution sfn Execute() -> ExitCode diff --git a/blenderCube2.obj b/Models/blenderCube2.obj similarity index 100% rename from blenderCube2.obj rename to Models/blenderCube2.obj diff --git a/bunny.obj b/Models/bunny.obj similarity index 100% rename from bunny.obj rename to Models/bunny.obj diff --git a/cube.obj b/Models/cube.obj similarity index 100% rename from cube.obj rename to Models/cube.obj diff --git a/cubeNoNormals.obj b/Models/cubeNoNormals.obj similarity index 100% rename from cubeNoNormals.obj rename to Models/cubeNoNormals.obj diff --git a/eight.obj b/Models/eight.obj similarity index 100% rename from eight.obj rename to Models/eight.obj diff --git a/gargoyle.obj b/Models/gargoyle.obj similarity index 100% rename from gargoyle.obj rename to Models/gargoyle.obj diff --git a/hand.obj b/Models/hand.obj similarity index 100% rename from hand.obj rename to Models/hand.obj diff --git a/horse.obj b/Models/horse.obj similarity index 100% rename from horse.obj rename to Models/horse.obj diff --git a/sculpture.obj b/Models/sculpture.obj similarity index 100% rename from sculpture.obj rename to Models/sculpture.obj diff --git a/topology.obj b/Models/topology.obj similarity index 100% rename from topology.obj rename to Models/topology.obj diff --git a/torus.obj b/Models/torus.obj similarity index 100% rename from torus.obj rename to Models/torus.obj diff --git a/BasicLamp.frag b/Shaders/BasicLight.frag similarity index 100% rename from BasicLamp.frag rename to Shaders/BasicLight.frag diff --git a/SimpleTransform.vert b/Shaders/BasicLight.vert similarity index 99% rename from SimpleTransform.vert rename to Shaders/BasicLight.vert index 6ccbea3..230da3a 100644 --- a/SimpleTransform.vert +++ b/Shaders/BasicLight.vert @@ -1,4 +1,5 @@ #version 330 core + layout (location = 0) in vec3 aPos; diff --git a/PhongShader.frag b/Shaders/PhongShader.frag similarity index 100% rename from PhongShader.frag rename to Shaders/PhongShader.frag diff --git a/PhongShader.vert b/Shaders/PhongShader.vert similarity index 90% rename from PhongShader.vert rename to Shaders/PhongShader.vert index bf0530d..5c683f0 100644 --- a/PhongShader.vert +++ b/Shaders/PhongShader.vert @@ -28,7 +28,7 @@ void main() 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)); } \ No newline at end of file diff --git a/SimpleFragmentShader.frag b/SimpleFragmentShader.frag deleted file mode 100644 index 354c68d..0000000 --- a/SimpleFragmentShader.frag +++ /dev/null @@ -1,12 +0,0 @@ -#version 330 core - - - -out vec3 color; - - - -void main() -{ - color = vec3(0.345, 0.345, 1); -} \ No newline at end of file diff --git a/SimpleVertexShader.vert b/SimpleVertexShader.vert deleted file mode 100644 index 65aca1f..0000000 --- a/SimpleVertexShader.vert +++ /dev/null @@ -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 ; -} \ No newline at end of file diff --git a/SingleColor.frag b/SingleColor.frag deleted file mode 100644 index 4bbe722..0000000 --- a/SingleColor.frag +++ /dev/null @@ -1,12 +0,0 @@ -#version 330 core - -// Output data -out vec3 color; - -void main() -{ - - // Output color = red - color = vec3(1,0,0); - -} \ No newline at end of file diff --git a/Testing.hpp b/Testing.hpp deleted file mode 100644 index f7eeeec..0000000 --- a/Testing.hpp +++ /dev/null @@ -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 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 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 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(Address(EquilateralTriangleVerticies), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw); - - DGL::BufferData(rectCompress, EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw); - - DGL::BindBuffer(EBufferTarget::VertexIndices, ElemBufferObj); - - DGL::BufferData(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 CubeVAO; -ID CubeModelBuffer ; -ID 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(DefaultCube, EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw); - - - DGL::BindBuffer(EBufferTarget::VertexIndices, CubeModelElements); - - DGL::BufferData(DefaultCubeElements, EBufferTarget::VertexIndices, EBufferUsage::StaticDraw); - - - DGL::FormatVertexAttributes(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 LightVAO; - -sfn RAW_MakeLightVAO() -{ - DGL::GenerateVertexBuffers(LightVAO, 1); - - DGL::BindVertexArray(LightVAO); - - DGL::BindBuffer(EBufferTarget::VertexAttributes, CubeModelBuffer ); - DGL::BindBuffer(EBufferTarget::VertexIndices , CubeModelElements); - - DGL::FormatVertexAttributes(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 LitCubeVAO; - -sfn RAW_MakeLitCube() -{ - DGL::GenerateVertexBuffers(LitCubeVAO, 1); - - DGL::BindVertexArray(LitCubeVAO); - - DGL::BindBuffer(EBufferTarget::VertexAttributes, CubeModelBuffer ); - DGL::BindBuffer(EBufferTarget::VertexIndices , CubeModelElements); - - DGL::FormatVertexAttributes(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)); - } -}