From 2b71f572847dc11e25a764c7b1f09f90a041a79e Mon Sep 17 00:00:00 2001 From: Ed94 Date: Fri, 14 Feb 2020 01:13:16 -0500 Subject: [PATCH] Started to apply the adhesive... A triangle is rotating on a invisible super elastic rubberband and the camera is attached with ethereal paperclips. --- 3.3.shader.frag | 10 ++ 3.3.shader.vert | 11 ++ 5.1.transform.frag | 15 ++ 5.1.transform.vert | 16 +++ 6.3.coordinate_systems.frag | 15 ++ 6.3.coordinate_systems.vert | 18 +++ Cpp_Alias.hpp | 21 +++ DGL.hpp | 72 ++++++---- DGL_Buffers.hpp | 33 +++-- DGL_Enum.hpp | 174 +++++++++++++++++++++-- DGL_FundamentalTypes.hpp | 11 +- DGL_MiscTypes.hpp | 23 ++- DGL_Primitive.hpp | 14 ++ DGL_Shader.hpp | 271 +++++++++++++++++++++++++++++++++--- DGL_Space.hpp | 116 +++++++++++++++ DGL_Variable.hpp | 1 + Execution.cpp | 183 ++++++++++++++++++++++++ ShaderFromTut.hpp | 203 +++++++++++++++++++++++++++ SimpleFragmentShader.frag | 12 ++ SimpleTransform.vert | 15 ++ SimpleVertexShader.vert | 13 ++ SingleColor.frag | 12 ++ TriangleRaw.hpp | 160 +++++++++++++++++++++ 23 files changed, 1342 insertions(+), 77 deletions(-) create mode 100644 3.3.shader.frag create mode 100644 3.3.shader.vert create mode 100644 5.1.transform.frag create mode 100644 5.1.transform.vert create mode 100644 6.3.coordinate_systems.frag create mode 100644 6.3.coordinate_systems.vert create mode 100644 DGL_Primitive.hpp create mode 100644 DGL_Space.hpp create mode 100644 DGL_Variable.hpp create mode 100644 Execution.cpp create mode 100644 ShaderFromTut.hpp create mode 100644 SimpleFragmentShader.frag create mode 100644 SimpleTransform.vert create mode 100644 SimpleVertexShader.vert create mode 100644 SingleColor.frag create mode 100644 TriangleRaw.hpp diff --git a/3.3.shader.frag b/3.3.shader.frag new file mode 100644 index 0000000..ad6e077 --- /dev/null +++ b/3.3.shader.frag @@ -0,0 +1,10 @@ +#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 new file mode 100644 index 0000000..f391c5f --- /dev/null +++ b/3.3.shader.vert @@ -0,0 +1,11 @@ +#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 new file mode 100644 index 0000000..73ce33b --- /dev/null +++ b/5.1.transform.frag @@ -0,0 +1,15 @@ +#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 new file mode 100644 index 0000000..036ab96 --- /dev/null +++ b/5.1.transform.vert @@ -0,0 +1,16 @@ + + +#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 new file mode 100644 index 0000000..8034550 --- /dev/null +++ b/6.3.coordinate_systems.frag @@ -0,0 +1,15 @@ + + +#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 new file mode 100644 index 0000000..3be8fc0 --- /dev/null +++ b/6.3.coordinate_systems.vert @@ -0,0 +1,18 @@ + + +#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/Cpp_Alias.hpp b/Cpp_Alias.hpp index 03a357a..62d756f 100644 --- a/Cpp_Alias.hpp +++ b/Cpp_Alias.hpp @@ -12,6 +12,18 @@ This merely removes the need to use operators I don't like and wraps them in eas #pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + // Macros #define sfn \ @@ -79,3 +91,12 @@ sfn Exit(ExitCode _code) { exit(int(_code)); } + +// Error Stuff + +sfn ErrorRuntime(const Ref(std::runtime_error) _error) +{ + std::cout << "Runtime error occurred: " << _error.what() << std::endl; + + return; +} diff --git a/DGL.hpp b/DGL.hpp index 81d0ea3..d0a90b5 100644 --- a/DGL.hpp +++ b/DGL.hpp @@ -1,19 +1,18 @@ #pragma once -// C++ STL -#include -#include -#include - // GL +//#include #include #include +#include +#include #include "DGL_FundamentalTypes.hpp" #include "DGL_MiscTypes.hpp" #include "DGL_Enum.hpp" #include "DGL_Shader.hpp" #include "DGL_Buffers.hpp" +#include "DGL_Space.hpp" // Non-Standard C++ #include "Cpp_Alias.hpp" @@ -45,18 +44,6 @@ namespace GL WindowRefList Windows; - - // Error Stuff - - sfn ErrorRuntime(Ref(std::runtime_error) _error) - { - cout << "Runtime error occurred: " << _error.what() << endl; - - return; - } - - - // Constants sfn constexpr NotShared () -> ptr { return NULL; } @@ -64,15 +51,13 @@ namespace GL + // Forward Declares + + sfn SwapBuffers(const ptr _window) -> void; + + // Functionality - sfn SwapBuffers(const ptr _window) -> void - { - glfwSwapBuffers(_window); - - return; - } - sfn CanClose(const ptr _theWindow) { return glfwWindowShouldClose(_theWindow); @@ -124,6 +109,16 @@ namespace GL return; } + sfn DrawArrays(EPrimitives _primitive, gInt _startingIndex, gInt _numToRender) + { + glDrawArrays(GLenum(_primitive), _startingIndex, _numToRender); // Starting from vertex 0; 3 vertices total -> 1 triangle. + } + + sfn DrawElements(EPrimitives _primitive, gSize _numElements, EDataType _dataType, DataPtr _offfsetAddressFromFirstIndex) + { + glDrawElements(GLenum(_primitive), _numElements, GLenum(_dataType), _offfsetAddressFromFirstIndex); + } + sfn GetTime() -> TimeValDec { return glfwGetTime(); @@ -146,7 +141,7 @@ namespace GL throw std::runtime_error("Failed to initialize GLFW"); } } - catch (std::runtime_error _error) + catch (const std::runtime_error _error) { ErrorRuntime(_error); @@ -177,7 +172,7 @@ namespace GL cout << "OpenGL Version: " << glGetString(GL_VERSION) << endl; } - catch (std::runtime_error _error) + catch (const std::runtime_error _error) { ErrorRuntime(_error); @@ -197,7 +192,7 @@ namespace GL /* Loop until the user closes the window */ while (not CanClose(_window)) { - ClearBuffer(); + ClearBuffer(EFrameBuffer::Color); SwapBuffers(_window); @@ -217,7 +212,14 @@ namespace GL if (deltaSinceClear > _interval) { - ClearBuffer(); + + ClearBuffer(EFrameBuffer::Color, EFrameBuffer::Depth); + //glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClearColor(0.25f, 0.25f, 0.25f, 1.0f); + + //glMatrixMode(GL_MODELVIEW); + + //glLoadIdentity(); _renderProcedure(); @@ -254,7 +256,7 @@ namespace GL throw std::runtime_error( Dref(ErrorMsg) ); } } - catch (std::runtime_error _error) + catch (const std::runtime_error _error) { ErrorRuntime(_error); @@ -264,6 +266,18 @@ namespace GL return; } + sfn SetPolygonMode(EFace _desiredFaces, EMode _desiredMode) + { + glPolygonMode(GLenum(_desiredFaces), GLenum(_desiredMode)); + } + + sfn SwapBuffers(const ptr _window) -> void + { + glfwSwapBuffers(_window); + + return; + } + sfn TerminateGLFW() { glfwTerminate(); diff --git a/DGL_Buffers.hpp b/DGL_Buffers.hpp index d588d4e..7f6808b 100644 --- a/DGL_Buffers.hpp +++ b/DGL_Buffers.hpp @@ -15,35 +15,46 @@ namespace GL { - sfn ClearBuffer() - { - glClear(GL_COLOR_BUFFER_BIT); - - return; - } - - sfn BindBuffer(EBufferTarget _targetType, ID _buffer) + sfn BindBuffer(const EBufferTarget _targetType, const ID _buffer) { glBindBuffer(GLenum(_targetType), _buffer); return; } - sfn BindVertexArray(ptr _referenceToTrackArray) + sfn BindVertexArray(const gUInt _referenceToTrackArray) { - glBindVertexArray(Dref(_referenceToTrackArray)); + glBindVertexArray(_referenceToTrackArray); return; } template - sfn BufferData(ptr _data, EBufferTarget _targetType, EBufferUsage _usageType) + sfn BufferData(ptr _data, const EBufferTarget _targetType, const EBufferUsage _usageType) { glBufferData(GLenum(_targetType), sizeof(TypeOfData), _data, GLenum(_usageType)); return; } + template + sfn ClearBuffer(const Type... _buffersToClear) + { + glClear((gBitfield(_buffersToClear) | ...)); + + return; + } + + sfn DisableVertexAttributeArray(const gInt _vertexAttributeArrayIndex) + { + glDisableVertexAttribArray(_vertexAttributeArrayIndex); + } + + sfn EnableVertexAttributeArray(const gInt _vertexAttributeArrayIndex) + { + glEnableVertexAttribArray(_vertexAttributeArrayIndex); + } + template sfn FormatVertexAttributes ( diff --git a/DGL_Enum.hpp b/DGL_Enum.hpp index d443db7..f9c3adb 100644 --- a/DGL_Enum.hpp +++ b/DGL_Enum.hpp @@ -12,7 +12,7 @@ namespace GL True = GL_TRUE , False = GL_FALSE }; - + enum class EBufferTarget { VertexAttributes = GL_ARRAY_BUFFER , @@ -46,6 +46,12 @@ namespace GL StaticRead = GL_STATIC_READ }; + enum class ECompareMode + { + RefToTexture = GL_COMPARE_REF_TO_TEXTURE, + None = GL_NONE + }; + enum class EDataType { Byte = GL_BYTE , @@ -60,19 +66,56 @@ namespace GL Double = GL_DOUBLE }; - enum class EShaderType + enum class EFace { - Vertex = GL_VERTEX_SHADER , - Fragment = GL_FRAGMENT_SHADER + Front = GL_FRONT, + Back = GL_BACK, + Front_and_Back = GL_FRONT_AND_BACK + }; + + enum class EFrameBuffer + { + Accumulation = GL_ACCUM_BUFFER_BIT , + Color = GL_COLOR_BUFFER_BIT , + Depth = GL_DEPTH_BUFFER_BIT , + Stencil = GL_STENCIL_BUFFER_BIT + }; + + enum class ELODBias + { + Max = GL_MAX_TEXTURE_LOD_BIAS + }; + + enum class EMaxFilter + { + Nearest = GL_NEAREST, + Linear = GL_LINEAR + }; + + enum class EMinFilter + { + Nearest = GL_NEAREST , + Linear = GL_LINEAR , + NearestToNearest = GL_NEAREST_MIPMAP_NEAREST, + LinearToNearest = GL_NEAREST_MIPMAP_LINEAR , + NearestToLinear = GL_NEAREST_MIPMAP_LINEAR , + LinearToLinear = GL_LINEAR_MIPMAP_LINEAR + }; + + enum class EMode + { + Point = GL_POINT, + Line = GL_LINE , + Fill = GL_FILL }; enum class EPrimitives { - Points = GL_POINTS, + Points = GL_POINTS, - Lines = GL_LINES , - LineStrip = GL_LINE_STRIP, - LineLoop = GL_LINE_LOOP , + Lines = GL_LINES , + LineStrip = GL_LINE_STRIP, + LineLoop = GL_LINE_LOOP , Triangles = GL_TRIANGLES , TriangleStrip = GL_TRIANGLE_STRIP, @@ -81,6 +124,119 @@ namespace GL Quads = GL_QUADS , QuadsStrip = GL_QUAD_STRIP, - Patches = GL_PATCHES + Patches = GL_PATCHES, + + Polygon = GL_POLYGON + }; + + enum class EShaderInfo + { + Type = GL_SHADER_TYPE , + DeleteStatus = GL_DELETE_STATUS , + CompileStatus = GL_COMPILE_STATUS , + InfoLogLength = GL_INFO_LOG_LENGTH , + ShaderSourceLength = GL_SHADER_SOURCE_LENGTH + }; + + enum class EShaderProgramInfo + { + DeleteStatus = GL_DELETE_STATUS , + LinkStatus = GL_LINK_STATUS , + ValidateStatus = GL_VALIDATE_STATUS , + InfoLogLength = GL_INFO_LOG_LENGTH , + AttachedShaders = GL_ATTACHED_SHADERS , + ActiveAttributes = GL_ACTIVE_ATTRIBUTES , + ActiveAttributesMaxLength = GL_ACTIVE_ATTRIBUTE_MAX_LENGTH , + ActiveUniforms = GL_ACTIVE_UNIFORMS , + TransformFeedbackActive = GL_TRANSFORM_FEEDBACK_BUFFER_MODE , + TransformFeedbackVaryings = GL_TRANSFORM_FEEDBACK_VARYING , + TransformFeedbackVaryingsMax = GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH, + ShaderVerticiesMax = GL_GEOMETRY_VERTICES_OUT , + GeometryInputType = GL_GEOMETRY_INPUT_TYPE , + GeometryOutputType = GL_GEOMETRY_OUTPUT_TYPE + }; + + enum class EShaderType + { + Vertex = GL_VERTEX_SHADER , + Fragment = GL_FRAGMENT_SHADER + }; + + enum class EStencilMode + { + DepthComponent = GL_DEPTH_COMPONENT, + StencilIndex = GL_STENCIL_INDEX + }; + + enum class ESWIZZLE + { + Red = GL_RED , + Green = GL_GREEN, + Blue = GL_BLUE , + Alpha = GL_ALPHA, + Zero = GL_ZERO , + One = GL_ONE + }; + + enum class ETexCompareFuncs + { + LessOrEqual = GL_LEQUAL , + GreaterOrEqual = GL_GEQUAL , + Less = GL_LESS , + Greater = GL_GREATER , + Equal = GL_EQUAL , + NotEqual = GL_NOTEQUAL, + Always = GL_ALWAYS , + Never = GL_NEVER + }; + + enum class ETextureMode + { + DepthStencil = GL_DEPTH_STENCIL_TEXTURE_MODE, + MipmapLowest = GL_TEXTURE_BASE_LEVEL , + ComparisonOperator = GL_TEXTURE_COMPARE_FUNC , + Comparision = GL_TEXTURE_COMPARE_MODE , + LevelOfDetailBias = GL_TEXTURE_LOD_BIAS , + MinimizingFilter = GL_TEXTURE_MIN_FILTER , + MagnificationFilter = GL_TEXTURE_MAG_FILTER , + MinimumLOD = GL_TEXTURE_MIN_LOD , + MaximumLOD = GL_TEXTURE_MAX_LOD , + MipmapMax = GL_TEXTURE_MAX_LEVEL , + Swizzle_R = GL_TEXTURE_SWIZZLE_R , + Swizzle_G = GL_TEXTURE_SWIZZLE_G , + Swizzle_B = GL_TEXTURE_SWIZZLE_B , + Swizzle_A = GL_TEXTURE_SWIZZLE_A , + Swizzle_RGBA = GL_TEXTURE_SWIZZLE_RGBA , + Wrap_S = GL_TEXTURE_WRAP_S , + Wrap_T = GL_TEXTURE_WRAP_T , + Wrap_R = GL_TEXTURE_WRAP_R + }; + + enum class ETextureType + { + _1D = GL_TEXTURE_1D, + _2D = GL_TEXTURE_2D, + _3D = GL_TEXTURE_3D, + + Rectangle = GL_TEXTURE_RECTANGLE, + Buffer = GL_TEXTURE_BUFFER , + + CubeMap = GL_TEXTURE_CUBE_MAP , + CubeMapArray = GL_TEXTURE_CUBE_MAP_ARRAY, + + Array1D = GL_TEXTURE_1D_ARRAY, + Array2D = GL_TEXTURE_2D_ARRAY, + + Multisample = GL_TEXTURE_2D_MULTISAMPLE , + Multisample2D = GL_TEXTURE_2D_MULTISAMPLE_ARRAY + }; + + enum class EWrap + { + ClampToEdge = GL_CLAMP_TO_EDGE , + ClampToBorder = GL_CLAMP_TO_BORDER , + MirroredRepeat = GL_MIRRORED_REPEAT , + Repeat = GL_REPEAT , + MirrorClampToEdge = GL_MIRROR_CLAMP_TO_EDGE }; } diff --git a/DGL_FundamentalTypes.hpp b/DGL_FundamentalTypes.hpp index f11cbad..a46a010 100644 --- a/DGL_FundamentalTypes.hpp +++ b/DGL_FundamentalTypes.hpp @@ -9,9 +9,10 @@ namespace GL { // Fundamental Types - using gChar = GLchar ; - using gFloat = GLfloat; - using gInt = GLint ; - using gUInt = GLuint ; - using gSize = GLsizei; + using gChar = GLchar ; + using gBitfield = GLbitfield; + using gFloat = GLfloat ; + using gInt = GLint ; + using gUInt = GLuint ; + using gSize = GLsizei ; } diff --git a/DGL_MiscTypes.hpp b/DGL_MiscTypes.hpp index 4d4c05b..eaa0fa6 100644 --- a/DGL_MiscTypes.hpp +++ b/DGL_MiscTypes.hpp @@ -2,6 +2,8 @@ // OpenGL #include +#include + // Duck Tape #include "DGL_FundamentalTypes.hpp" @@ -13,17 +15,28 @@ namespace GL { - // Made up types. + namespace Generic + { + template + using Vector3 = glm::tvec3; + } + + using DataPtr = ptr; template using ID = gUInt; // ID Reference Types - class Buffer ; - class Shader ; + class Buffer; + class Matrix; + class Shader; class ShaderProgram; + class VertexBuffer; + class ElementBuffer; - using DataPtr = ptr; - using VertexBuffer = gUInt ; + using Matrix4x4 = glm::mat4; + + using Vector3 = glm::vec3; + using Vector4 = glm::vec4; } diff --git a/DGL_Primitive.hpp b/DGL_Primitive.hpp new file mode 100644 index 0000000..5817125 --- /dev/null +++ b/DGL_Primitive.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include "DGL_Space.hpp" + + + + +namespace GL +{ + + struct Primitive + { + }; +} diff --git a/DGL_Shader.hpp b/DGL_Shader.hpp index 3610d81..a0f5633 100644 --- a/DGL_Shader.hpp +++ b/DGL_Shader.hpp @@ -1,12 +1,10 @@ #pragma once -// C++ -#include - //DGL #include "DGL_FundamentalTypes.hpp" #include "DGL_MiscTypes.hpp" #include "DGL_Enum.hpp" +#include "DGL_Space.hpp" @@ -36,8 +34,48 @@ namespace GL "}"; + // Default Shaders + + ID RawShader , + SimpleShader , + SimpleShader_Transformed ; + + ID ScreenSpaceVarID; + + + // Forward Declarations + + sfn GetShaderInfo(ID _shader , gSize _logLength , ptr _infoLengthRef , RawString _infoLogRef) -> void; + sfn QueryShader (ID _shaderToQuery, EShaderInfo _shaderInfoDesired, ptr _requestedInfoObject ) -> void; + sfn MakeShader(Ref(ID) _shaderIDHolder, EShaderType _typeOfShader, uInt64 _numberOfStringElements, ptr> _sourceCode, ptr _lengthsOfStrings) -> void; + sfn MakeShaderProgram(Ref(ID) _shaderProgramIDHolder, const ID _vertexShader, const ID _fragShader) -> void; + + + // Functions + sfn ActiveUniforms(ID _shaderToQueryForUniforms) -> GLint + { + GLint uniforms; + + glGetProgramiv(_shaderToQueryForUniforms, GL_ACTIVE_UNIFORMS, &uniforms); + + for (int i = 0; i < uniforms; i++) + { + int name_len = -1, num = -1; + + GLenum type = GL_ZERO; + + char name[100]; + + glGetActiveUniform(_shaderToQueryForUniforms, GLuint(i), sizeof(name) - 1, &name_len, &num, &type, name); + + name[name_len] = 0; + } + + return uniforms; + } + sfn AttachShader(ID _shaderProgram, ID _shaderToAttach) { glAttachShader(_shaderProgram, _shaderToAttach); @@ -52,10 +90,34 @@ namespace GL return; } - sfn CompileShader(ID _shaderToCompile) + sfn CompileShader(const ID _shaderToCompile) { glCompileShader(_shaderToCompile); + gInt Result = gInt(EBool::False); + + gSize InfoLogLength; + + QueryShader(_shaderToCompile, EShaderInfo::CompileStatus, Address(Result)); + + if (!Result) + { + QueryShader(_shaderToCompile, EShaderInfo::InfoLogLength, Address(InfoLogLength)); + + if (InfoLogLength > 0) + { + std::vector ErrorMessage(InfoLogLength + 1); + + GetShaderInfo(_shaderToCompile, InfoLogLength, nullptr, Address(ErrorMessage.at(0))); + + throw std::runtime_error(Address(ErrorMessage.at(0))); + } + else + { + throw std::runtime_error("Shader compilation failed and did not get a proper info log."); + } + } + return; } @@ -75,7 +137,31 @@ namespace GL return; } - + + sfn DetachShader(ID _shaderProgram, ID _shaderToDetach) + { + glDetachShader(_shaderProgram, _shaderToDetach); + + return; + } + + sfn GetShaderInfo(ID _shader, gSize _logLength, ptr _infoLengthRef, RawString _infoLogRef) -> void + { + glGetShaderInfoLog(_shader, _logLength, _infoLengthRef, _infoLogRef); + + return; + } + + sfn GetShaderProgramInfo(ID _shaderProgram, gSize _logLength, ptr _infoLengthRef, RawString _infoLogRef) -> void + { + glGetProgramInfoLog(_shaderProgram, _logLength, _infoLengthRef, _infoLogRef); + } + + sfn GetUniformVariable(const ID _programID, RawString _nameOfVariable) -> ID + { + return glGetUniformLocation(_programID, _nameOfVariable); + } + sfn LinkProgramShader(ID _shaderProgramToLink) { glLinkProgram(_shaderProgramToLink); @@ -83,15 +169,127 @@ namespace GL return; } - sfn UseProgramShader(ID _shaderProgramToUse) + sfn QueryShader(ID _shaderToQuery, EShaderInfo _shaderInfoDesired, ptr _requestedInfoObject) -> void { - glUseProgram(_shaderProgramToUse); - - return; + glGetShaderiv(_shaderToQuery, GLenum(_shaderInfoDesired), _requestedInfoObject); } + sfn QueryShaderProgram(ID _shaderToQuery, EShaderProgramInfo _shaderProgramInfoDesired, ptr _requestedInfoObject) -> void + { + glGetProgramiv(_shaderToQuery, GLenum(_shaderProgramInfoDesired), _requestedInfoObject); + } - // Raw Tape + sfn LoadShaders(RawString _vertexShaderFilePath, RawString _fragmentShaderFilePath) -> ID + { + using std::cout ; + using std::endl ; + using std::ifstream ; + using std::ios ; + using std::string ; + using std::stringstream; + using std::vector ; + + + string vertexShaderCode ; + string fragmentShaderCode ; + + ifstream vertexShaderFileStream ; + ifstream fragmentShaderFileStream; + + vertexShaderFileStream .open(_vertexShaderFilePath); + fragmentShaderFileStream.open(_fragmentShaderFilePath); + + try + { + if (vertexShaderFileStream.is_open() and fragmentShaderFileStream.is_open()) + { + stringstream vertSourceStrStream; + stringstream fragSourceStrStream; + + vertSourceStrStream << vertexShaderFileStream .rdbuf(); + fragSourceStrStream << fragmentShaderFileStream.rdbuf(); + + vertexShaderFileStream .close(); + fragmentShaderFileStream.close(); + + vertexShaderCode = vertSourceStrStream.str(); + fragmentShaderCode = fragSourceStrStream.str(); + } + else + { + throw std::runtime_error("Impossible to open% s.Are you in the right directory ? Don't forget to read the FAQ !"); + } + + + RawString vertexSourcePtr = vertexShaderCode .c_str(); + RawString fragmentSourcePtr = fragmentShaderCode.c_str(); + + cout << "Compiling shader: " << _vertexShaderFilePath << endl; + + ID vertexShader = CreateShader(EShaderType::Vertex); + + BindShaderSource(vertexShader, 1, Address(vertexSourcePtr), NULL); + CompileShader (vertexShader ); + + cout << "Compiling shader: " << _fragmentShaderFilePath << endl; + + ID fragmentShader = CreateShader(EShaderType::Fragment); + + BindShaderSource(fragmentShader, 1, Address(fragmentSourcePtr), NULL); + CompileShader (fragmentShader ); + + + cout << "Making Shader Program and Linking..." << endl; + + ID generatedProgram; + + MakeShaderProgram(generatedProgram, vertexShader, fragmentShader); + + DeleteShader(vertexShader ); + DeleteShader(fragmentShader); + + return generatedProgram; + } + catch (const std::runtime_error _error) + { + ErrorRuntime(_error); + + Exit(ExitCode::Failed); + } + } + + sfn LoadRawShader() + { + ID VertexShader ; + ID FragmentShader; + + MakeShader(VertexShader , EShaderType::Vertex , 1, Address(GL::RawVertextShaderSource ), NULL); + MakeShader(FragmentShader, EShaderType::Fragment, 1, Address(GL::RawFragmentShaderSource), NULL); + + GL::MakeShaderProgram(RawShader, VertexShader, FragmentShader); + + GL::DeleteShader(VertexShader ); + GL::DeleteShader(FragmentShader); + } + + sfn LoadSimpleShader() + { + SimpleShader = LoadShaders("SimpleVertexShader.vert", "SimpleFragmentShader.frag"); + } + + sfn LoadSimpleShader_Transformed() + { + SimpleShader_Transformed = LoadShaders("SimpleTransform.vert", "SingleColor.frag"); + + ScreenSpaceVarID = GL::GetUniformVariable(GL::SimpleShader_Transformed, "modelViewProjection"); + } + + sfn LoadDefaultShaders() + { + LoadRawShader (); + LoadSimpleShader (); + LoadSimpleShader_Transformed(); + } sfn MakeShader ( @@ -101,6 +299,7 @@ namespace GL ptr> _sourceCode , ptr< const gInt > _lengthsOfStrings ) + -> void { _shaderIDHolder = CreateShader(_typeOfShader); @@ -109,18 +308,54 @@ namespace GL CompileShader(_shaderIDHolder); } - sfn MakeShaderProgram(Ref(ID) _shaderProgramIDHolder, ID _shadersToAttach...) + sfn MakeShaderProgram(Ref(ID) _shaderProgramIDHolder, const ID _vertexShader, const ID _fragShader) -> void { _shaderProgramIDHolder = CreateShaderProgram(); - va_list args; - - va_start(args, _shadersToAttach); - - AttachShader(_shaderProgramIDHolder, va_arg(args, ID)); - - va_end(args); + AttachShader(_shaderProgramIDHolder, _vertexShader); + AttachShader(_shaderProgramIDHolder, _fragShader ); LinkProgramShader(_shaderProgramIDHolder); + + gInt Result = false; + + QueryShaderProgram(_shaderProgramIDHolder, EShaderProgramInfo::LinkStatus, Address(Result)); + + if (!Result) + { + gInt infoLogLength; + + QueryShaderProgram(_shaderProgramIDHolder, EShaderProgramInfo::InfoLogLength, Address(infoLogLength)); + + if (infoLogLength > 0) + { + std::vector ErrorMessage(infoLogLength + 1); + + GetShaderProgramInfo(_shaderProgramIDHolder, infoLogLength, NULL, Address(ErrorMessage.at(0))); + + throw std::runtime_error(Address(ErrorMessage.at(0))); + } + else + { + throw std::runtime_error("ShaderProgram compilation failed and did not get a proper info log."); + } + } + + DetachShader(_shaderProgramIDHolder, _vertexShader); + DetachShader(_shaderProgramIDHolder, _fragShader ); + + return; + } + + sfn SetUniformVariable_MatrixVariableArray(const ID _matrixID, const gSize _numMatricies, const EBool _shouldTransposeValues, ptr _dataPtr) + { + glUniformMatrix4fv(_matrixID, _numMatricies, GLenum(_shouldTransposeValues), _dataPtr); + } + + sfn UseProgramShader(ID _shaderProgramToUse) + { + glUseProgram(_shaderProgramToUse); + + return; } } diff --git a/DGL_Space.hpp b/DGL_Space.hpp new file mode 100644 index 0000000..42d3e12 --- /dev/null +++ b/DGL_Space.hpp @@ -0,0 +1,116 @@ +#pragma once + + +#include "DGL_FundamentalTypes.hpp" +#include "DGL_MiscTypes.hpp" + + + +#include "Cpp_Alias.hpp" + + + +namespace GL +{ + using CoordSpace = Matrix4x4; + using Projection = Matrix4x4; + + + // Function + + template + sfn CreateLookAtView(const Generic::Vector3 _viewPosition, const Generic::Vector3 _lookAtPosition, const Generic::Vector3 _upDirection) -> Matrix4x4 + { + return glm::lookAt(_viewPosition, _lookAtPosition, _upDirection); + } + + sfn CreateOrthographic(gFloat _leftScreenCoord, gFloat _rightScreenCoord, gFloat _bottomScreenCoord, gFloat _topScreenCoord, gFloat _nearPlane, gFloat _farPlane) + { + return glm::ortho(_leftScreenCoord, _rightScreenCoord, _bottomScreenCoord, _topScreenCoord, _nearPlane, _farPlane); + } + + template + sfn CreatePerspective(const FloatType _fieldOfView, const FloatType _aspectRatio, const FloatType _nearPlane, const FloatType _farPlane) + { + return glm::perspective(_fieldOfView, _aspectRatio, _nearPlane, _farPlane); + } + + sfn Rotate(const Matrix4x4 _matrix, gFloat _rotationAngleAmount, Vector3 _axis) -> Matrix4x4 + { + return glm::rotate(_matrix, _rotationAngleAmount, _axis); + } + + template + sfn ToRadians(const Ref(Type) _degrees) -> Type + { + return glm::radians(_degrees); + } + + struct ClippingPlanes + { + gFloat Near, Far; + + ClippingPlanes(gFloat _near, gFloat _far) : Near(_near), Far(_far) {}; + }; + + namespace DefaultSpace + { + gFloat + AspectRatio = 16.0f / 10.0f, + FieldOfView = 90.0f , + NearClippingPlane = 0.1f , + FarClippingPlane = 100.0f ; + + Vector3 CameraPosition(-3, 0, 0), + LookAtPosition( 0, 0, 0), + UpDirection ( 0, 1, 0) ; + + gFloat ScreenWidth = 720.0f, ScreenHeight = 450.0f; + } + + struct Camera + { + gFloat AspectRatio, FieldOfView; + + ClippingPlanes ClipSpace; + + CoordSpace ViewPort; + + Projection Orthographic, Perspective; + + Vector3 Position, LookAtPosition, UpDirection; + + + Camera + ( + gFloat _aspectRatio , + gFloat _fieldOfView , + ClippingPlanes _clippingPlanes, + Vector3 _position , + Vector3 _lookAtPosition, + Vector3 _upDirection + ) : + AspectRatio (_aspectRatio ), + FieldOfView (_fieldOfView ), + ClipSpace (_clippingPlanes), + Position (_position ), + LookAtPosition(_lookAtPosition), + UpDirection (_upDirection ) + { + ViewPort = CreateLookAtView(Position, LookAtPosition, UpDirection); + + Orthographic = CreateOrthographic(0.0f, DefaultSpace::ScreenWidth, 0.0f, DefaultSpace::ScreenHeight, ClipSpace.Near, ClipSpace.Far); + + Perspective = CreatePerspective(ToRadians(FieldOfView), AspectRatio, ClipSpace.Near, ClipSpace.Far); + } + }; + + namespace DefaultSpace + { + Camera WorldCamera(AspectRatio, FieldOfView, ClippingPlanes(NearClippingPlane, FarClippingPlane), CameraPosition, LookAtPosition, UpDirection); + + CoordSpace WorldSpace(Matrix4x4(1.0f)); + + CoordSpace Screenspace = WorldCamera.Perspective * WorldCamera.ViewPort * WorldSpace; + } +} \ No newline at end of file diff --git a/DGL_Variable.hpp b/DGL_Variable.hpp new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/DGL_Variable.hpp @@ -0,0 +1 @@ +#pragma once diff --git a/Execution.cpp b/Execution.cpp new file mode 100644 index 0000000..980d242 --- /dev/null +++ b/Execution.cpp @@ -0,0 +1,183 @@ +// Cpp STL +#include +#include +#include + + + +// Project +#include "DGL.hpp" +#include "TriangleRaw.hpp" + +#include "Cpp_Alias.hpp" + + +#include +#include +#include + + +namespace Execution +{ + // C++ STL + + using std::thread; + + template + using UPtr = std::unique_ptr; + + template + sfn MakeUPtr(rRef(ParamTypes)... _params) -> UPtr + { + return std::make_unique(_params...); + } + + + + // GL + + using GL::TimeValDec; + using GL::Window ; + using GL::Matrix ; + using GL::Matrix4x4 ; + using GL::Vector3 ; + using GL::gFloat ; + + + bool Exist = true; + + TimeValDec CycleStart, CycleEnd, DeltaTime, InputPollingInterval = 1.0f / 240.0f, RenderInterval = 1.0f / 60.0f; + + UPtr BasicLoop, BasicTimedLoop; + + + + // Testing + + // Foward Declares + + sfn RenderProcedure () -> void; + sfn PrepareRenderObjects() -> void; + + sfn CreateWindow_BasicLoop() + { + GL::InitalizeGLFW(); + + deduce windowObj = GL::CreateWindow(720, 450, "Assignment 1: RawLoop", GL::WindowedMode(), GL::NotShared()); + + GL::SetCurrentContext(windowObj); + + GL::RunBasicWindowLoop(windowObj); + } + + sfn CreateWindow_TimedRender() + { + GL::InitalizeGLFW(); + + deduce windowObj = GL::CreateWindow(720, 540, "Assignment 1: Timed Render", GL::WindowedMode(), GL::NotShared()); + + GL::SetCurrentContext(windowObj); + + GL::InitalizeGLEW(); + + PrepareRenderObjects(); + + GL::RunBasicWindowLoop_Timed(windowObj, 1.0 / 60.0, Address(RenderProcedure)); + } + + sfn PrepareRenderObjects() -> void + { + RAW_SetupBuffers(); + + RAW_BindAndBufferDataToIDs(); + + GL::LoadDefaultShaders(); + + GL::FormatVertexAttributes(VertexAttributeIndex, EDataType::Float, ZeroOffset(), Vertex3::ValueCount(), EBool::True); + + GL::BindBuffer(EBufferTarget::VertexAttributes, 0); // Dunno. Prob unbinding... + + GL::BindVertexArray(0); + } + + sfn Cycler(FnPtr _inputProcedure, FnPtr _renderProcedure) + { + while (Exist) + { + CycleStart = GL::GetTime(); + + if (DeltaTime >= InputPollingInterval) + { + GL::PollEvents(); + + _inputProcedure(); + } + + if (DeltaTime >= RenderInterval) + { + _renderProcedure(); + } + + CycleEnd = GL::GetTime(); + + DeltaTime = DeltaTime + CycleEnd - CycleStart; + } + + return; + } + + sfn InputProcedure() + { + + } + + sfn RenderProcedure() -> void + { + GL::EnableVertexAttributeArray(VertexAttributeIndex); + + GL::SetPolygonMode(GL::EFace::Front_and_Back, GL::EMode::Fill); + + GL::DefaultSpace::WorldSpace = GL::Rotate(GL::DefaultSpace::WorldSpace, 0.0035f, Vector3(0.0f, 0.5f, 0.0f)); + + GL::DefaultSpace::Screenspace = GL::DefaultSpace::WorldCamera.Perspective * GL::DefaultSpace::WorldCamera.ViewPort * GL::DefaultSpace::WorldSpace; + + GL::UseProgramShader(GL::SimpleShader_Transformed); + + GL::SetUniformVariable_MatrixVariableArray(GL::ScreenSpaceVarID, 1, GL::EBool::False, Address(GL::DefaultSpace::Screenspace[0][0])); + + GL::BindVertexArray(VertexArrayObj); + + GL::DrawArrays(GL::EPrimitives::Triangles, 0, TriangleRaw::VertexCount()); + + GL::DisableVertexAttributeArray(VertexAttributeIndex); + } + + sfn PrepWorkspace() + { + + } + + + // Runtime Execution: Loop must be specified here to use. + + sfn Execute() -> ExitCode + { + /*PrepWorkspace();*/ + + //Cycler(Address(InputProcedure), Address(RenderProcedure)); + + CreateWindow_TimedRender(); + + GL::TerminateGLFW(); + + return ExitCode::Success; + } +} + + + +int main(void) +{ + return int(Execution::Execute()); +} + diff --git a/ShaderFromTut.hpp b/ShaderFromTut.hpp new file mode 100644 index 0000000..308ff0d --- /dev/null +++ b/ShaderFromTut.hpp @@ -0,0 +1,203 @@ + + +#ifndef SHADER_H +#define SHADER_H + +//#include +#include +#include +#include "DGL.hpp" + +#include +#include +#include +#include + +class Shader +{ +public: + unsigned int ID; + // constructor generates the shader on the fly + // ------------------------------------------------------------------------ + Shader(const char* vertexPath, const char* fragmentPath, const char* geometryPath = nullptr) + { + // 1. retrieve the vertex/fragment source code from filePath + std::string vertexCode; + std::string fragmentCode; + std::string geometryCode; + std::ifstream vShaderFile; + std::ifstream fShaderFile; + std::ifstream gShaderFile; + // ensure ifstream objects can throw exceptions: + vShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit); + fShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit); + gShaderFile.exceptions (std::ifstream::failbit | std::ifstream::badbit); + try + { + // open files + vShaderFile.open(vertexPath); + fShaderFile.open(fragmentPath); + std::stringstream vShaderStream, fShaderStream; + // read file's buffer contents into streams + vShaderStream << vShaderFile.rdbuf(); + fShaderStream << fShaderFile.rdbuf(); + // close file handlers + vShaderFile.close(); + fShaderFile.close(); + // convert stream into string + vertexCode = vShaderStream.str(); + fragmentCode = fShaderStream.str(); + // if geometry shader path is present, also load a geometry shader + if (geometryPath != nullptr) + { + gShaderFile.open(geometryPath); + std::stringstream gShaderStream; + gShaderStream << gShaderFile.rdbuf(); + gShaderFile.close(); + geometryCode = gShaderStream.str(); + } + } + catch (std::ifstream::failure e) + { + std::cout << "ERROR::SHADER::FILE_NOT_SUCCESFULLY_READ" << std::endl; + } + const char* vShaderCode = vertexCode.c_str(); + const char* fShaderCode = fragmentCode.c_str(); + // 2. compile shaders + unsigned int vertex, fragment; + // vertex shader + + + vertex = glCreateShader(GL_VERTEX_SHADER); + glShaderSource(vertex, 1, &vShaderCode, NULL); + glCompileShader(vertex); + checkCompileErrors(vertex, "VERTEX"); + // fragment Shader + fragment = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(fragment, 1, &fShaderCode, NULL); + glCompileShader(fragment); + checkCompileErrors(fragment, "FRAGMENT"); + // if geometry shader is given, compile geometry shader + unsigned int geometry; + if (geometryPath != nullptr) + { + const char* gShaderCode = geometryCode.c_str(); + geometry = glCreateShader(GL_GEOMETRY_SHADER); + glShaderSource(geometry, 1, &gShaderCode, NULL); + glCompileShader(geometry); + checkCompileErrors(geometry, "GEOMETRY"); + } + + GL::MakeShaderProgram(ID, vertex, fragment); + + // shader Program + /* ID = glCreateProgram(); + glAttachShader(ID, vertex); + glAttachShader(ID, fragment); + if (geometryPath != nullptr) + glAttachShader(ID, geometry); + glLinkProgram(ID);*/ + checkCompileErrors(ID, "PROGRAM"); + // delete the shaders as they're linked into our program now and no longer necessery + glDeleteShader(vertex); + glDeleteShader(fragment); + if (geometryPath != nullptr) + glDeleteShader(geometry); + + } + // activate the shader + // ------------------------------------------------------------------------ + void use() + { + glUseProgram(ID); + } + // utility uniform functions + // ------------------------------------------------------------------------ + void setBool(const std::string& name, bool value) const + { + glUniform1i(glGetUniformLocation(ID, name.c_str()), (int)value); + } + // ------------------------------------------------------------------------ + void setInt(const std::string& name, int value) const + { + glUniform1i(glGetUniformLocation(ID, name.c_str()), value); + } + // ------------------------------------------------------------------------ + void setFloat(const std::string& name, float value) const + { + glUniform1f(glGetUniformLocation(ID, name.c_str()), value); + } + // ------------------------------------------------------------------------ + void setVec2(const std::string& name, const glm::vec2& value) const + { + glUniform2fv(glGetUniformLocation(ID, name.c_str()), 1, &value[0]); + } + void setVec2(const std::string& name, float x, float y) const + { + glUniform2f(glGetUniformLocation(ID, name.c_str()), x, y); + } + // ------------------------------------------------------------------------ + void setVec3(const std::string& name, const glm::vec3& value) const + { + glUniform3fv(glGetUniformLocation(ID, name.c_str()), 1, &value[0]); + } + void setVec3(const std::string& name, float x, float y, float z) const + { + glUniform3f(glGetUniformLocation(ID, name.c_str()), x, y, z); + } + // ------------------------------------------------------------------------ + void setVec4(const std::string& name, const glm::vec4& value) const + { + glUniform4fv(glGetUniformLocation(ID, name.c_str()), 1, &value[0]); + } + void setVec4(const std::string& name, float x, float y, float z, float w) + { + glUniform4f(glGetUniformLocation(ID, name.c_str()), x, y, z, w); + } + // ------------------------------------------------------------------------ + void setMat2(const std::string& name, const glm::mat2& mat) const + { + glUniformMatrix2fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &mat[0][0]); + } + // ------------------------------------------------------------------------ + void setMat3(const std::string& name, const glm::mat3& mat) const + { + glUniformMatrix3fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &mat[0][0]); + } + // ------------------------------------------------------------------------ + void setMat4(const std::string& name, const glm::mat4& mat) const + { + deduce bullshit = glGetUniformLocation(ID, name.c_str()); + + glUniformMatrix4fv(glGetUniformLocation(ID, name.c_str()), 1, GL_FALSE, &mat[0][0]); + } + +private: + // utility function for checking shader compilation/linking errors. + // ------------------------------------------------------------------------ + void checkCompileErrors(GLuint shader, std::string type) + { + GLint success; + GLchar infoLog[1024]; + if (type != "PROGRAM") + { + glGetShaderiv(shader, GL_COMPILE_STATUS, &success); + if (!success) + { + glGetShaderInfoLog(shader, 1024, NULL, infoLog); + std::cout << "ERROR::SHADER_COMPILATION_ERROR of type: " << type << "\n" << infoLog << "\n -- --------------------------------------------------- -- " << std::endl; + } + } + else + { + glGetProgramiv(shader, GL_LINK_STATUS, &success); + if (!success) + { + glGetProgramInfoLog(shader, 1024, NULL, infoLog); + std::cout << "ERROR::PROGRAM_LINKING_ERROR of type: " << type << "\n" << infoLog << "\n -- --------------------------------------------------- -- " << std::endl; + } + } + } +}; +#endif + diff --git a/SimpleFragmentShader.frag b/SimpleFragmentShader.frag new file mode 100644 index 0000000..354c68d --- /dev/null +++ b/SimpleFragmentShader.frag @@ -0,0 +1,12 @@ +#version 330 core + + + +out vec3 color; + + + +void main() +{ + color = vec3(0.345, 0.345, 1); +} \ No newline at end of file diff --git a/SimpleTransform.vert b/SimpleTransform.vert new file mode 100644 index 0000000..b8d2f73 --- /dev/null +++ b/SimpleTransform.vert @@ -0,0 +1,15 @@ +#version 330 core +layout (location = 0) in vec3 aPos; + +// uniform mat4 model; +// uniform mat4 view; +// uniform mat4 projection; + +uniform mat4 modelViewProjection; + +void main() +{ + //gl_Position = projection * view * model * vec4(aPos, 1.0); + + gl_Position = modelViewProjection * vec4(aPos, 1.0); +} \ No newline at end of file diff --git a/SimpleVertexShader.vert b/SimpleVertexShader.vert new file mode 100644 index 0000000..65aca1f --- /dev/null +++ b/SimpleVertexShader.vert @@ -0,0 +1,13 @@ +#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 new file mode 100644 index 0000000..4bbe722 --- /dev/null +++ b/SingleColor.frag @@ -0,0 +1,12 @@ +#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/TriangleRaw.hpp b/TriangleRaw.hpp new file mode 100644 index 0000000..dd6d658 --- /dev/null +++ b/TriangleRaw.hpp @@ -0,0 +1,160 @@ +#pragma once + +#include "DGL.hpp" + +#include "Cpp_Alias.hpp" + + + +using GL::gFloat; +using GL::VertexBuffer; +using GL::EBufferTarget; +using GL::EBufferUsage; +using GL::Buffer; +using GL::ID; +using GL::gInt; +using GL::gSize; + + + +// 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 }, + { 1.0f, -1.0f, 0.0f }, + { 0.0f, 1.0f, 0.0f } +}; + + +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 = +{ + { 0.5f, 0.5f, 0.0f }, + { 0.5f, -0.5f, 0.0f }, + { -0.5f, -0.5f, 0.0f }, + { -0.5f, 0.5f, 0.0f } +}; + +RectangleIndices rectIndices = +{ + { 0, 1, 3 }, + { 1, 2, 3 } +}; + +using GL::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() +{ + GL::GenerateVertexBuffers(Address(VertexArrayObj ), 1); + GL::GenerateBuffers (Address(VertexBufferObj), 1); + GL::GenerateBuffers (Address(ElemBufferObj ), 1); +} + +sfn RAW_SetupTriangleBuffer() +{ + GL::GenerateBuffers(Address(VertexBufferObj), 1); +} + +sfn RAW_BindAndBufferDataToIDs() +{ + GL::BindVertexArray(VertexArrayObj); + + GL::BindBuffer(EBufferTarget::VertexAttributes, VertexBufferObj); + + GL::BufferData(Address(EquilateralTriangleVerticies), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw); + + //GL::BufferData(Address(rectCompress), EBufferTarget::VertexAttributes, EBufferUsage::StaticDraw); + + //GL::BindBuffer(EBufferTarget::VertexIndices, ElemBufferObj); + + //GL::BufferData(Address(rectIndices), EBufferTarget::VertexIndices, EBufferUsage::StaticDraw); +} + +GL::gInt VertexAttributeIndex = 0; // See shader source: (layout = 0). + +using GL::EBool ; +using GL::EDataType; + +constexpr sfn ZeroOffset() -> ptr +{ + return 0; +}