diff options
Diffstat (limited to 'Client/Source/GUI/UISquare.cpp')
-rw-r--r-- | Client/Source/GUI/UISquare.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Client/Source/GUI/UISquare.cpp b/Client/Source/GUI/UISquare.cpp new file mode 100644 index 0000000..f5c3702 --- /dev/null +++ b/Client/Source/GUI/UISquare.cpp @@ -0,0 +1,53 @@ +#include "../Math/Math.h" +#include "../Graphics/GfxDevice.h" + +#include "UISquare.h" + +struct UISquareLayout +{ + Vector2f position; +}; + +static CustomVertexLayout layout; + +InitializeStaticVariables([]() { + VertexAttributeDescriptor POSITION = VertexAttributeDescriptor(0, 2, VertexAttrFormat_Float, sizeof(UISquareLayout)); + + layout.attributes.push_back(POSITION); +}); + +void UISquare::Draw() +{ + const int nVerts = 4; + const int nIndices = 6; + + float pos[] = { + m_Left, m_Bottom, // left-bottom + m_Right, m_Bottom, // right-bottom + m_Right, m_Top, // right-top + m_Left, m_Top, // top-left + }; + + int indices[] = { + 0, 1, 3, // right-top + 1, 2, 3, // left-bottom + }; + + uint8* vb; + uint16* ib; + + g_SharedVBO.GetChunk(sizeof(UISquareLayout), sizeof(uint16), 4, 6, Primitive_Triangle, (void**)&vb, (void**)&ib); + + UISquareLayout* dst = (UISquareLayout*)vb; + + for (int i = 0; i < nVerts; ++i) + { + dst[i].position.Set(pos[2 * i], pos[2 * i + 1]); + } + + for (int i = 0; i < nIndices; ++i) + ib[i] = indices[i]; + + g_SharedVBO.ReleaseChunk(4, 6); + g_SharedVBO.DrawChunk(layout); +} |