the rest of the missing stuff

This commit is contained in:
Tim Nebel 2023-07-02 22:34:30 +02:00
commit db93d81ffd
51 changed files with 10107 additions and 0 deletions

26
deps/vgcore/CMakeLists.txt vendored Normal file
View file

@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.23)
project(VGCore VERSION 0.1.1)
set (CMAKE_CXX_STANDARD 20)
find_package(OpenGL REQUIRED)
find_package(GLEW REQUIRED)
find_package(Boost REQUIRED COMPONENTS filesystem)
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
add_subdirectory(deps/glm)
add_subdirectory(deps/glfw)
add_subdirectory(deps/imgui)
add_subdirectory(deps/assimp)
if(NOT GCoreDemo)
add_subdirectory(demo)
endif()
add_library(GCore STATIC "src/Graphics.cpp" "src/Window.cpp" src/MessageBox.cpp src/Mesh.cpp src/Widget.cpp src/Viewport.cpp src/ViewportWidget.cpp src/Shader.cpp src/Texture.cpp src/Sprite.cpp src/FileSelectDialog.cpp src/Outliner.cpp src/EditorPopup.cpp)
target_link_libraries(GCore OpenGL::GL glfw GLEW::GLEW ImGUI glm::glm Boost::filesystem assimp)
target_include_directories(GCore PUBLIC include deps/IconFontCppHeaders)

9
deps/vgcore/demo/CMakeLists.txt vendored Normal file
View file

@ -0,0 +1,9 @@
project(GCoreDemo)
set (CMAKE_CXX_STANDARD 20)
add_executable(GCoreDemo "src/main.cpp" "src/Demo.cpp" "src/DemoViewport.cpp" "src/fps.cpp")
target_include_directories(GCoreDemo PUBLIC include)
target_link_libraries(GCoreDemo GCore)

8
deps/vgcore/demo/include/Demo.h vendored Normal file
View file

@ -0,0 +1,8 @@
#include"virintox/gcore/Window.h"
class Demo : public Graphics::Window{
public:
Demo();
void Update() override;
inline static Demo* THIS;
};

View file

@ -0,0 +1,9 @@
#pragma once
#include<virintox/gcore/ViewportWidget.h>
class DemoViewport : public Graphics::ViewportWidget{
public:
DemoViewport();
void Draw() override;
~DemoViewport() = default;
};

6
deps/vgcore/demo/include/fps.h vendored Normal file
View file

@ -0,0 +1,6 @@
#include<virintox/gcore/Widget.h>
class fps : Graphics::Widget{
fps();
void Draw() override;
};

40
deps/vgcore/demo/src/Demo.cpp vendored Normal file
View file

@ -0,0 +1,40 @@
#include"virintox/gcore/Graphics.h"
#include"Demo.h"
#include"virintox/gcore/Window.h"
#include"virintox/gcore/FileSelectDialog.h"
#include<DemoViewport.h>
#include "imgui.h"
#include"iostream"
Demo::Demo() : Graphics::Window("GCoreDemo"){
THIS = this;
addWidget<DemoViewport>();
AddMenu("File");
AddMenu("Widgets");
AddMenuItem("File", "Open", [](){
auto fsdiag = static_cast<Graphics::FileSelectDialog*>(THIS->WidgetByName.find("Select File")->second);
fsdiag->fileSelectMode = Graphics::FileSelectMode::Open;
fsdiag->Active = true;
});
AddMenuItem("File", "Quit", [](){
Graphics::Quit();
});
AddMenuItem("Widgets", "Demo Viewport", [](){
THIS->WidgetByName.find("test")->second->Active ^= 1;
});
addWidget<Graphics::FileSelectDialog>(new Graphics::FileSelectDialog(std::vector<std::string>{".txt"},[](boost::filesystem::path file){std::cout << file;}));
}
void Demo::Update(){
}

16
deps/vgcore/demo/src/DemoViewport.cpp vendored Normal file
View file

@ -0,0 +1,16 @@
#include "virintox/gcore/ViewportWidget.h"
#include "virintox/gcore/Widget.h"
#include<DemoViewport.h>
#include<virintox/gcore/Texture.h>
#include<iostream>
Graphics::Texture img;
DemoViewport::DemoViewport() : Graphics::ViewportWidget("test", true) {
img = Graphics::Texture("/home/tv/Pictures/aa.png");
}
void DemoViewport::Draw(){
img.DrawC(glm::vec2(0,0),1);
ChangeView(0,0,1);
}

11
deps/vgcore/demo/src/fps.cpp vendored Normal file
View file

@ -0,0 +1,11 @@
#include "fps.h"
#include "boost/chrono.hpp"
float last;
fps::fps() : Graphics::Widget("fps", true){}
void fps::Draw(){
}

9
deps/vgcore/demo/src/main.cpp vendored Normal file
View file

@ -0,0 +1,9 @@
#include "virintox/gcore/Graphics.h"
#include "Demo.h"
int main(){
Graphics::Init();
Graphics::setWindow<Demo>();
Graphics::BeginLoop();
Graphics::Terminate();
}

@ -0,0 +1 @@
Subproject commit 90da8021ec7c7792c454c3f43516595754a91765

1
deps/vgcore/deps/assimp vendored Submodule

@ -0,0 +1 @@
Subproject commit 5770faac102bddcc26665dc81cf27c5328c1a6ab

1
deps/vgcore/deps/glfw vendored Submodule

@ -0,0 +1 @@
Subproject commit 3fa2360720eeba1964df3c0ecf4b5df8648a8e52

1
deps/vgcore/deps/glm vendored Submodule

@ -0,0 +1 @@
Subproject commit 5c46b9c07008ae65cb81ab79cd677ecc1934b903

8
deps/vgcore/deps/imgui/CMakeLists.txt vendored Normal file
View file

@ -0,0 +1,8 @@
project(ImGUI)
find_package(GLEW REQUIRED)
add_library(ImGUI STATIC imgui/imgui.cpp imgui/imgui_demo.cpp imgui/imgui_draw.cpp imgui/imgui_tables.cpp imgui/imgui_widgets.cpp imgui/backends/imgui_impl_glfw.cpp imgui/backends/imgui_impl_opengl3.cpp imgui/misc/cpp/imgui_stdlib.cpp)
target_link_libraries(ImGUI glfw GLEW::GLEW)
target_include_directories(ImGUI PUBLIC imgui)

1
deps/vgcore/deps/imgui/imgui vendored Submodule

@ -0,0 +1 @@
Subproject commit 2fa36a2283b6b5a3a0b65d373de0d490116b4b15

2
deps/vgcore/include/virintox/GCore.h vendored Normal file
View file

@ -0,0 +1,2 @@
#include<Graphics.h>

View file

@ -0,0 +1,22 @@
#pragma once
#include <cstring>
#include<functional>
#include<virintox/gcore/Widget.h>
namespace Graphics{
class NameEditor : public Widget{
public:
NameEditor(std::function<void(std::string)> func,std::string name = "Name Editor");
char NewName[256];
void PreDraw() override;
void Draw() override;
inline void Activate(const std::string &current){
strcpy(NewName, current.c_str());
Active = true;
}
std::function<void(std::string)> SetFunc;
};
}

View file

@ -0,0 +1,12 @@
#pragma once
#include<exception>
#include<string>
namespace Graphics::Exceptions{
class SegmentationFault : std::exception{
public:
const char* what() const noexcept override;
private:
const char* where;
};
}

View file

@ -0,0 +1,41 @@
#ifndef PNS_FILESELECTDIALOG_H
#define PNS_FILESELECTDIALOG_H
#include<virintox/gcore/Widget.h>
#include<functional>
#include<boost/filesystem.hpp>
namespace Graphics{
enum FileSelectMode{
Open,
Save
};
class FileSelectDialog : public Widget{
public:
FileSelectDialog(std::string name,std::vector<std::string> FileType, std::function<void(boost::filesystem::path)> OnOpenCloseFunc);
FileSelectDialog(std::string name,std::vector<std::string> FileType, std::function<void(boost::filesystem::path)> OnOpenFunc, std::function<void(boost::filesystem::path)> OnSaveFunc);
FileSelectDialog(std::vector<std::string> FileType, std::function<void(boost::filesystem::path)> OnOpenCloseFunc);
FileSelectDialog(std::vector<std::string> FileType, std::function<void(boost::filesystem::path)> OnOpenFunc, std::function<void(boost::filesystem::path)> OnSaveFunc);
void Draw() override;
std::vector<std::string> Path;
std::vector<std::string> Extension;
boost::filesystem::path GetPath();
std::string Filter;
char Filename[256] = "";
FileSelectMode fileSelectMode;
~FileSelectDialog() override;
protected:
int SelectedFile;
std::function<void(boost::filesystem::path)> OnOpen;
std::function<void(boost::filesystem::path)> OnSave;
};
}
#endif //PNS_FILESELECTDIALOG_H

View file

@ -0,0 +1,35 @@
#ifndef PNS_GRAPHICS_H
#define PNS_GRAPHICS_H
#include<string>
#include<array>
#include<GL/glew.h>
#include<GLFW/glfw3.h>
#include<virintox/gcore/Window.h>
namespace Graphics{
void Init();
void BeginLoop();
void Terminate();
void EnableVsync();
inline float MWheel;
inline std::unique_ptr<Window> window;
inline bool Running;
template<class T>
inline T* setWindow(){
T* _window = new T();
window = std::unique_ptr<Window>(_window);
return _window;
}
inline void Quit(){
Running = false;
}
}
#endif

View file

@ -0,0 +1,26 @@
#ifndef PNS_ITREESERIALIZABLE_H
#define PNS_ITREESERIALIZABLE_H
#include<string>
#include<vector>
enum ObjectType{
Folder,
Item
};
class ITreeSerializable{
public:
virtual void SetParent(ITreeSerializable*) = 0;
virtual std::string GetName() = 0;
virtual void SetName(std::string) = 0;
virtual void Release(ITreeSerializable*) = 0;
virtual void Attach(ITreeSerializable*) = 0;
virtual std::vector<ITreeSerializable*> GetSubItems() = 0;
virtual ObjectType GetObjectType() = 0;
bool CurrentlySelected;
};
#endif //PNS_ITREESERIALIZABLE_H

View file

@ -0,0 +1,32 @@
#pragma once
#include "glm/ext/vector_float3.hpp"
#include<glm/mat3x2.hpp>
#include<glm/mat3x3.hpp>
#include<glm/vec3.hpp>
#include<glm/vec2.hpp>
#include<vector>
#include<virintox/gcore/Texture.h>
#include<GL/glew.h>
#include<virintox/gcore/Shader.h>
namespace Graphics{
class Mesh{
public:
explicit Mesh(boost::filesystem::path PathToModel,Shader &ShaderToUse);
explicit Mesh(const std::vector<glm::mat3x2> &Polygons, const std::vector<glm::mat3x2> &TexCoords, Shader &Shader = GetDefaultShader2D());
Mesh(const std::vector<glm::vec2> &Points,const std::vector<GLuint> &Indices,const std::vector<glm::vec2> &TexCoords, Shader &Shader = GetDefaultShader2D());
explicit Mesh(const std::vector<glm::mat3x3> &Polygons, const std::vector<glm::mat3x2> &TexCoords, Shader &Shader = GetDefaultShader3D());
Mesh(const std::vector<glm::vec3> &Points,const std::vector<GLuint> &Indices, const std::vector<glm::vec2> &TexCoords, Shader &Shader = GetDefaultShader3D());
void Draw(const Texture &Tex,const glm::vec2 &Pos) const;
void Draw(const Texture &Tex,const glm::vec3 &Pos, const glm::vec3 &Scale = glm::vec3(1,1,1), const glm::vec3 &Rot = glm::vec3(0,0,0)) const;
private:
Shader &shader;
GLuint VBO,VAO,EBO;
GLuint VCount;
};
}

View file

@ -0,0 +1,36 @@
#pragma once
#include "Widget.h"
#include <exception>
namespace Graphics{
enum ErrorSeverity{
Fault,
Error,
Warning,
Info
};
class MSGBoxException : public std::exception{
public:
inline MSGBoxException(std::string What,ErrorSeverity severity): whattext(What),Severity(severity){};
const char * what() const noexcept override;
std::string whattext;
ErrorSeverity Severity;
};
class MessageBox : public Widget{
public:
MessageBox(std::string Text, ErrorSeverity Severity = Info);
void Draw() override;
void PostDraw() override;
bool Deactivate = false;
private:
std::string text;
ErrorSeverity severity;
public:
~MessageBox() override;
};
}

View file

@ -0,0 +1,9 @@
#pragma once
//Not ready for production
namespace Graphics{
class Model{
};
}

View file

@ -0,0 +1,44 @@
#ifndef PNS_OUTLINER_H
#define PNS_OUTLINER_H
#include<memory>
#include<virintox/gcore/Widget.h>
#include<cstring>
#include<virintox/gcore/ITreeSerializable.h>
namespace Graphics {
class NameEditorOld : public Widget{
public:
NameEditorOld();
char NewName[256];
void PreDraw() override;
void Draw() override;
inline void Activate(ITreeSerializable* Node){
memset(NewName,0,256);
EditingNode = Node;
Active = true;
}
ITreeSerializable* EditingNode;
};
class Outliner : public Widget{
public:
Outliner();
void Draw() override;
void DrawNode(ITreeSerializable* Node);
inline void SetMainItem(ITreeSerializable* Item){
LastSelectedNode = nullptr;
MainItem = Item;
}
ITreeSerializable* MainItem;
ITreeSerializable* LastSelectedNode;
NameEditorOld NameEdit;
void PostDraw() override;
};
}
#endif //PNS_OUTLINER_H

View file

@ -0,0 +1,20 @@
#ifndef PNS_SHADER_H
#define PNS_SHADER_H
#include <GL/glew.h>
namespace Graphics{
class Shader{
public:
static void SetupDefaults();
inline Shader(){ init = false; };
Shader(const GLchar* Vertex, const GLchar* Fragment);
void Use();
GLuint ShaderId;
bool init;
};
Shader &GetDefaultShader2D();
Shader &GetDefaultShader3D();
}
#endif //PNS_SHADER_H

View file

@ -0,0 +1,23 @@
#ifndef PNS_SPRITE_H
#define PNS_SPRITE_H
#include<GL/glew.h>
#include"Texture.h"
#include<glm/vec2.hpp>
#include<glm/mat3x2.hpp>
namespace Graphics{
class Sprite{
public:
Sprite();
Sprite(const glm::vec2 &Pos,float scale, Texture* Tex);
Sprite(const glm::mat3x2 &Veticies,const glm::mat3x2 &TexCoords, Texture* Tex);
void Update(const glm::vec2 &Pos,float scale) const;
void Update(const glm::mat3x2 &Veticies,const glm::mat3x2 &TexCoords) const;
void Draw();
Texture* TexPtr;
protected:
GLuint VBO,VAO,EBO;
int VCount;
};
}
#endif //PNS_SPRITE_H

View file

@ -0,0 +1,30 @@
#ifndef PNS_TEXTURE_H
#define PNS_TEXTURE_H
#include<GL/glew.h>
#include<boost/filesystem.hpp>
#include<glm/mat3x2.hpp>
#include<glm/vec2.hpp>
namespace Graphics {
class Texture {
public:
Texture() = default;
Texture(boost::filesystem::path PngFile,bool Normalize = false);
~Texture();
glm::vec2 size;
inline operator int() const{
return TexID;
}
void SetActive() const;
void Draw(glm::vec2 pos, float scale = 1);
void DrawC(glm::vec2 pos, float scale = 1);
void DrawTri(glm::tmat3x2<float> Tri, glm::tmat3x2<float> TexCoords);
protected:
unsigned int TexID;
};
}
#endif //PNS_TEXTURE_H

View file

@ -0,0 +1,49 @@
#ifndef PNS_VIEWPORT_H
#define PNS_VIEWPORT_H
#include<GL/glew.h>
#include<glm/vec2.hpp>
#include"Widget.h"
enum InputType{
MouseDownR,
MouseDownL,
MouseUpR,
MouseUpL,
MouseHoldR,
MouseHoldL,
MouseHover,
MWheel
};
struct InputEvent{
float x;
float y;
InputType EventType;
float MWheel;
};
namespace Graphics {
class Viewport{
public:
Viewport();
unsigned int Framebuffer;
unsigned int FramebufferTex;
unsigned int FramebufferDepthTex;
unsigned int FramebufferMatIdTex;
unsigned int FramebufferWorldPosTex;
void ChangeView(const glm::vec2 &pos,float scale) const;
void ChangeView(float x,float y, float scale) const;
virtual void Draw() = 0;
virtual void HandleInput(InputEvent);
protected:
void RecreateFramebuffer();
int frameheight,framewidth;
int lastframeheight,lastframewidth;
};
}
#endif //PNS_VIEWPORT_H

View file

@ -0,0 +1,14 @@
#ifndef PNS_VIEWPORTWIDGET_H
#define PNS_VIEWPORTWIDGET_H
#include"Viewport.h"
#include"Widget.h"
namespace Graphics{
class ViewportWidget : public Graphics::Viewport , public Graphics::Widget{
public:
ViewportWidget(std::string name,bool active);
void PreDraw() override;
void PostDraw() override;
virtual void DrawOver();
};
}
#endif

View file

@ -0,0 +1,28 @@
#ifndef PNS_WIDGET_H
#define PNS_WIDGET_H
#include<string>
#include<vector>
#include<memory>
#include<GL/glew.h>
#include "WidgetElement.h"
namespace Graphics {
class Widget {
public:
Widget(std::string name, bool active = false);
virtual void Update();
virtual void PreDraw();
virtual void Draw();
virtual void PostDraw();
inline std::string GetName(){
return Name;
}
bool Active;
protected:
std::vector<std::unique_ptr<WidgetElement>> Elements;
std::string Name;
public:
virtual ~Widget() = default;
};
}
#endif //PNS_WIDGET_H

View file

@ -0,0 +1,13 @@
#ifndef PNS_WIDGETELEMENT_H
#define PNS_WIDGETELEMENT_H
namespace Graphics {
class WidgetElement {
public:
virtual void Render() = 0;
virtual ~WidgetElement() = default;
};
}
#endif //PNS_WIDGETELEMENT_H

View file

@ -0,0 +1,72 @@
#ifndef PNS_WINDOW_H
#define PNS_WINDOW_H
#include "MessageBox.h"
#include "Widget.h"
#include<GLFW/glfw3.h>
#include<memory>
#include<string>
#include<vector>
#include<functional>
#include<map>
#include<list>
struct MenuItem{
std::string Name;
std::function<void(void)> Func;
std::string Shortcut;
int ShortcutKey;
};
namespace Graphics{
class Window{
public:
explicit Window(const std::string &name = "Unnamed GCore Window");
virtual void Update();
virtual void DrawBG();
void Draw();
inline GLFWwindow* GetGlfwWindow(){
return window;
};
std::vector<std::unique_ptr<Widget>> Widgets;
std::map<std::string,Widget*> WidgetByName;
virtual void DropCallback(const std::vector<std::string> &paths);
std::list<MessageBox*> msgBoxes;
protected:
std::map<std::string,std::vector<MenuItem>> Menus;
inline void AddMenu(std::string Title){
Menus.insert({Title,std::vector<MenuItem>()});
}
inline void AddMenuItem(std::string Menu,std::string name,std::function<void()> func, std::string shortcut = "",int ShortcutKey = 0){
Menus.find(Menu)->second.push_back(MenuItem{name,func,shortcut, ShortcutKey});
}
template <class T>
inline T* addWidget(){
T* t = new T();
Widgets.push_back(std::unique_ptr<Widget>(t));
WidgetByName.insert({t->GetName(),t});
return t;
};
template <class T>
inline T* addWidget(T* t){
Widgets.push_back(std::unique_ptr<Widget>(t));
WidgetByName.insert({t->GetName(),t});
return t;
};
GLFWwindow* window;
};
}
#endif //PNS_WINDOW_H

File diff suppressed because it is too large Load diff

28
deps/vgcore/src/EditorPopup.cpp vendored Normal file
View file

@ -0,0 +1,28 @@
#include<virintox/gcore/EditorPopup.h>
#include<imgui.h>
namespace Graphics{
NameEditor::NameEditor(std::function<void(std::string)> func,std::string name) : Widget(name) {
SetFunc = func;
}
void NameEditor::PreDraw() {
ImGui::Begin(Name.c_str(),&Active,ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize);
}
void NameEditor::Draw() {
ImGui::Text("Change Name of Node to:");
bool Done = ImGui::InputText("##",NewName,256,ImGuiInputTextFlags_EnterReturnsTrue);
ImVec2 PrevPos = ImGui::GetCursorPos();
Done |= ImGui::Button("Done",ImVec2(140.0f,30.0f));
PrevPos.x += 145.0f;
ImGui::SetCursorPos(PrevPos);
Active &= !ImGui::Button("Cancel",ImVec2(140.0f,30.0f));
if(Done){
SetFunc(std::string(NewName));
Active = false;
}
}
}

0
deps/vgcore/src/Exceptions.cpp vendored Normal file
View file

248
deps/vgcore/src/FileSelectDialog.cpp vendored Normal file
View file

@ -0,0 +1,248 @@
#include<virintox/gcore/FileSelectDialog.h>
#include <cstring>
#include<imgui.h>
#include <boost/algorithm/string.hpp>
#include "IconsFontAwesome6.h"
#include<misc/cpp/imgui_stdlib.h>
#ifdef WIN32
#include <windows.h>
#endif
namespace Graphics{
FileSelectDialog::FileSelectDialog(std::vector<std::string> FileType, std::function<void(boost::filesystem::path)> OnOpenCloseFunc)\
: FileSelectDialog("Select File",FileType, OnOpenCloseFunc) {}
FileSelectDialog::FileSelectDialog(std::vector<std::string> FileType, std::function<void(boost::filesystem::path)> OnOpenFunc, std::function<void(boost::filesystem::path)> OnSaveFunc)\
: FileSelectDialog("Select File",FileType, OnOpenFunc, OnSaveFunc) {}
FileSelectDialog::FileSelectDialog(std::string name,std::vector<std::string> FileType, std::function<void(boost::filesystem::path)> OnOpenCloseFunc) : Widget(name, false) {
Path = std::vector<std::string>();
OnOpen = std::move(OnOpenCloseFunc);
OnSave = std::move(OnOpenCloseFunc);
Extension = FileType;
SelectedFile = 0;
#ifdef WIN32
std::vector<std::string> strvec;
boost::algorithm::split(strvec,getenv("USERPROFILE"),boost::is_any_of("\\"));
for(auto str: strvec){
Path.push_back(str);
}
#endif
#ifdef __linux__
std::vector<std::string> strvec;
boost::algorithm::split(strvec,getenv("HOME"),boost::is_any_of("/"));
for(auto str: strvec){
Path.push_back(str);
}
#endif
}
FileSelectDialog::FileSelectDialog(std::string name,std::vector<std::string> FileType, std::function<void(boost::filesystem::path)> OnOpenFunc, std::function<void(boost::filesystem::path)> OnSaveFunc) : Widget(name, false) {
Path = std::vector<std::string>();
OnOpen = std::move(OnOpenFunc);
OnSave = std::move(OnSaveFunc);
Extension = FileType;
SelectedFile = 0;
#ifdef WIN32
std::vector<std::string> strvec;
boost::algorithm::split(strvec,getenv("USERPROFILE"),boost::is_any_of("\\"));
for(auto str: strvec){
Path.push_back(str);
}
#endif
#ifdef unix
std::vector<std::string> strvec;
boost::algorithm::split(strvec,getenv("HOME"),boost::is_any_of("/"));
for(auto str: strvec){
Path.push_back(str);
}
#endif
}
void FileSelectDialog::Draw() {
const int MaxTextHeight = ImGui::CalcTextSize("abcdefghijklmnopqrstivwxyzABCDEFGHIJKLMNOPQRSTUVW").y;
boost::filesystem::path CurrentSelectedFile;
bool CurrentFileIsFolder = false;
{
ImGui::BeginGroupPanel("Path", ImVec2(0.9f, 0.0f));
float yCPos = ImGui::GetCursorPosY();
float xCPos = ImGui::GetCursorPosX();
yCPos -= 8;
ImGui::PushStyleColor(ImGuiCol_Button,ImVec4(0.0,0.0,0.0,0.0));
int num = 1;
for (std::string S: Path) {
ImGui::SetCursorPos(ImVec2(xCPos, yCPos));
if(ImGui::Button((S + "/").c_str()))
while(num != Path.size())
Path.pop_back();
xCPos += ImGui::CalcTextSize((S + "/").c_str()).x + 8;
num++;
}
ImGui::PopStyleColor();
ImGui::EndGroupPanel();
}
ImGui::SameLine();
ImGui::SetCursorPosX(ImGui::GetWindowWidth()-ImGui::CalcTextSize(ICON_FA_MAGNIFYING_GLASS).x - 15);
if(ImGui::Button(ICON_FA_MAGNIFYING_GLASS))
ImGui::OpenPopup((std::string("Search##") + GetName().c_str()).c_str());
if(ImGui::BeginPopup((std::string("Search##") + GetName().c_str()).c_str())){
ImGui::Text("Search:");
ImGui::InputText((std::string("##SearchInput") + GetName().c_str()).c_str(),&Filter);
ImGui::EndPopup();
}
int yPrev = ImGui::GetCursorPosY();
#ifdef WIN32
ImGui::BeginGroupPanel("Drives", ImVec2(0.0f, 0.0f));
DWORD DriveBitBuf = GetLogicalDrives();
char DriveLetter = 'A';
while(DriveBitBuf != 0)
{
if(DriveBitBuf & 1){
if(ImGui::Button(std::string(":/").insert(0,1,DriveLetter).c_str())){
Path.clear();
Path.push_back(( std::string(1, DriveLetter) + ":/"));
}
}
if(DriveLetter == 'Y')
break;
DriveBitBuf = DriveBitBuf >> 1;
DriveLetter++;
}
ImGui::EndGroupPanel();
ImGui::SetCursorPosY(yPrev);
ImGui::SetCursorPosX(ImGui::CalcTextSize(" Drives").x+30);
#endif
ImGui::BeginGroupPanel("Files");
ImGui::BeginChild("Files",ImVec2(-1.0,ImGui::GetContentRegionMax().y-ImGui::GetCursorPosY()-35));
boost::filesystem::directory_iterator end_iter;
int num = 0;
for (boost::filesystem::directory_iterator itr(GetPath()); itr != end_iter; ++itr) {
std::string Text = itr->path().filename().string();
boost::algorithm::to_lower(Text);
boost::algorithm::to_lower(Filter);
if(!boost::algorithm::contains(Text,Filter))
continue;
bool isfile = true;
if (boost::filesystem::is_regular_file(itr->path())) {
bool IsValidFiletype = false;
for(std::string ext : Extension)
if(itr->path().extension() == ext)
IsValidFiletype = true;
if(!IsValidFiletype)
continue;
ImGui::Text(ICON_FA_FILE " ");
ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0, 1.0, 1.0, 1.0));
}
else if (boost::filesystem::is_directory(itr->path()))
{
ImGui::Text(ICON_FA_FOLDER);
ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0, 0.5, 0.0, 1.0));
if(num == SelectedFile)
CurrentFileIsFolder = true;
isfile = false;
}
else
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0, 0.0, 0.0, 1.0));
if(ImGui::Selectable(itr->path().filename().string().c_str(),num == SelectedFile)) {
strcpy(Filename,itr->path().filename().string().c_str());
SelectedFile = num;
}
if(num == SelectedFile)
CurrentSelectedFile = itr->path();
if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(0)){
Filter = "";
if(!isfile)
Path.push_back(itr->path().filename().string());
else {
if(fileSelectMode == Open)
OnOpen(itr->path());
else
OnSave(itr->path());
Active = false;
}
}
ImGui::PopStyleColor();
num++;
}
ImGui::EndChild();
ImGui::EndGroupPanel();
yPrev = ImGui::GetCursorPosY();
if(fileSelectMode == Open) {
ImGui::SetCursorPosX(ImGui::GetContentRegionMax().x - ImGui::CalcTextSize("Open").x - 10);
if (ImGui::Button("Open")) {
if (CurrentFileIsFolder) {
Path.push_back(CurrentSelectedFile.filename().string());
} else {
OnOpen(CurrentSelectedFile);
Active = false;
}
}
}
else{
bool Done = ImGui::InputText("File Name",Filename,256,ImGuiInputTextFlags_EnterReturnsTrue);
ImGui::SetCursorPosY(yPrev);
ImGui::SetCursorPosX(ImGui::GetContentRegionMax().x - ImGui::CalcTextSize("Open").x - 10);
Done |= ImGui::Button("Save");
if (Done) {
OnSave(GetPath() / std::string(Filename));
Active = false;
}
}
ImGui::SetCursorPosY(yPrev);
ImGui::SetCursorPosX(ImGui::GetContentRegionMax().x - ImGui::CalcTextSize("Open").x - ImGui::CalcTextSize("Close").x - 30);
if(ImGui::Button("Close")){
Active = false;
}
}
boost::filesystem::path FileSelectDialog::GetPath() {
boost::filesystem::path path = boost::filesystem::path();
for(std::string S: Path){
path.append(S + "/");
}
return path;
}
FileSelectDialog::~FileSelectDialog() {
}
}

54
deps/vgcore/src/Graphics.cpp vendored Normal file
View file

@ -0,0 +1,54 @@
#include<virintox/gcore/Graphics.h>
#include<virintox/gcore/Window.h>
#include<virintox/gcore/Shader.h>
#include<GLFW/glfw3.h>
#include<imgui.h>
#include<backends/imgui_impl_opengl3.h>
#include<backends/imgui_impl_glfw.h>
#include<stdexcept>
#include<iostream>
void ErrorCallback(GLenum source, GLenum type, GLuint id,
GLenum severity, GLsizei length, const GLchar* message, const void* userParam){
std::cout << "an opengl error occured";
}
void Graphics::Init() {
Running = true;
if (!glfwInit())
{
throw std::runtime_error("Could not Initialize glfw");
}
MWheel = 1.0f;
}
void Graphics::BeginLoop() {
while(Running){
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
window->Update();
window->Draw();
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
glfwMakeContextCurrent(window->GetGlfwWindow());
}
}
void Graphics::Terminate() {
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
glfwTerminate();
}
void Graphics::EnableVsync() {
glfwSwapInterval(1);
}

163
deps/vgcore/src/Mesh.cpp vendored Normal file
View file

@ -0,0 +1,163 @@
#include<virintox/gcore/Mesh.h>
#include<glm/mat4x4.hpp>
#include<assimp/Importer.hpp>
#include "assimp/postprocess.h"
#include "glm/ext/matrix_transform.hpp"
#include <assimp/scene.h>
#include <virintox/gcore/Graphics.h>
namespace Graphics{
//Mesh::Mesh(boost::filesystem::path PathToModel, Shader &ShaderToUse): shader(ShaderToUse){
//}
Mesh::Mesh(const std::vector<glm::vec2> &Points,const std::vector<GLuint> &Indices, const std::vector<glm::vec2> &TexCoords, Shader &ShaderToUse) : shader(ShaderToUse){
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glGenBuffers(1, &EBO);
glCullFace(GL_BACK);
VCount = Indices.size();
std::vector<float> VertexData{};
for(int x = 0; x < Points.size() || x < TexCoords.size(); x++){
VertexData.push_back(Points[x].x);
VertexData.push_back(Points[x].y);
VertexData.push_back(TexCoords[x].x);
VertexData.push_back(TexCoords[x].y);
}
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, VertexData.size() * sizeof(float), VertexData.data(), GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, Indices.size() * sizeof(int), Indices.data(), GL_STATIC_DRAW);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));
glEnableVertexAttribArray(1);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
Mesh::Mesh(const std::vector<glm::vec3> &Points, const std::vector<GLuint> &Indices,
const std::vector<glm::vec2> &TexCoords, Shader &Shader) : shader(Shader) {
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glGenBuffers(1, &EBO);
glCullFace(GL_BACK);
VCount = Indices.size();
assert(Indices.size() % 3 == 0 && "Indices must always come in pairs of three since a face consists of 3 points!");
std::vector<float> VertexData{};
for(int x = 0; x < Points.size() || x < TexCoords.size(); x++){
VertexData.push_back(Points[x].x);
VertexData.push_back(Points[x].y);
VertexData.push_back(Points[x].z);
VertexData.push_back(TexCoords[x].x);
VertexData.push_back(TexCoords[x].y);
}
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, VertexData.size() * sizeof(float), VertexData.data(), GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, Indices.size() * sizeof(unsigned int), Indices.data(), GL_STATIC_DRAW);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(1);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
void Mesh::Draw(const Texture &Tex,const glm::vec3 &Pos, const glm::vec3 &Scale, const glm::vec3 &Rot) const{
glm::mat4 translationMatrix = glm::translate(glm::mat4(1),glm::vec3(Pos.x,-Pos.y,Pos.z));
glm::mat4 translationNoYInvertMatrix = glm::translate(glm::mat4(1),glm::vec3(Pos.x,Pos.y,Pos.z));
glm::mat4 rotationMatrixZ = glm::rotate(glm::mat4(1),glm::radians(Rot.z), glm::vec3(0,0,1));
glm::mat4 rotationMatrixY = glm::rotate(rotationMatrixZ,glm::radians(Rot.y), glm::vec3(0,1,0));
glm::mat4 rotationMatrix = glm::rotate(rotationMatrixY,glm::radians(Rot.x), glm::vec3(1,0,0));
glm::mat4 scaleMatrix = glm::scale(glm::mat4(1),Scale);
glm::mat4 matrix = translationMatrix * rotationMatrix * scaleMatrix;
glm::mat4 noYInvertMatrix = translationNoYInvertMatrix * rotationMatrix * scaleMatrix;
GLuint MatrixID = glGetUniformLocation(shader.ShaderId, "TransformationMatrix");
glUniformMatrix4fv(MatrixID,1,GL_FALSE,&matrix[0][0]);
GLuint MatrixNoYInvID = glGetUniformLocation(shader.ShaderId, "TransformationMatrixNoYInv");
glUniformMatrix4fv(MatrixNoYInvID,1,GL_FALSE,&noYInvertMatrix[0][0]);
glBindVertexArray(VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
shader.Use();
Tex.SetActive();
const GLenum buffers[] = {GL_NONE, GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2};
glDrawBuffers(4, buffers);
glDrawElements(
GL_TRIANGLES, // mode
VCount, // count
GL_UNSIGNED_INT, // type
(void*)0 // element array buffer offset
);
}
void Mesh::Draw(const Texture &Tex,const glm::vec2 &Pos) const{
glm::mat4x4 matrix{{1,0,0,Pos.x},
{0,1,0,Pos.y},
{0,0,1,0},
{0,0,0,1}};
GLuint MatrixID = glGetUniformLocation(shader.ShaderId, "TransformationMatrix");
glUniformMatrix4fv(MatrixID,1,GL_FALSE,&matrix[0][0]);
glBindVertexArray(VAO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
shader.Use();
Tex.SetActive();
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
const GLenum buffers[] = {GL_NONE, GL_COLOR_ATTACHMENT0, GL_COLOR_ATTACHMENT1, GL_COLOR_ATTACHMENT2};
glDrawBuffers(4, buffers);
glDrawElements(
GL_TRIANGLES, // mode
VCount, // count
GL_UNSIGNED_INT, // type
(void*)0 // element array buffer offset
);
}
}

49
deps/vgcore/src/MessageBox.cpp vendored Normal file
View file

@ -0,0 +1,49 @@
#include<virintox/gcore/Graphics.h>
#include<virintox/gcore/MessageBox.h>
#include <imgui.h>
#include <string>
unsigned int errorcount = 0;
namespace Graphics{
const char * MSGBoxException::what() const noexcept {
return whattext.c_str();
}
MessageBox::MessageBox(std::string Text, ErrorSeverity Severity): Widget(std::to_string(errorcount)), text(Text),severity(Severity){
errorcount++;
}
void MessageBox::Draw(){
switch(severity){
case Fault:
ImGui::Text("Fault:");
break;
case Error:
ImGui::Text("Error:");
break;
case Warning:
ImGui::Text("Warning:");
break;
case Info:
ImGui::Text("Info:");
break;
}
ImGui::Text(text.c_str());
if(ImGui::Button("Close"))
Deactivate = true;
}
void MessageBox::PostDraw(){
Widget::PostDraw();
if(Deactivate)
delete this;
}
MessageBox::~MessageBox(){
window->msgBoxes.remove(this);
}
}

106
deps/vgcore/src/Outliner.cpp vendored Normal file
View file

@ -0,0 +1,106 @@
#include<virintox/gcore/Outliner.h>
#include<imgui.h>
#include<iostream>
namespace Graphics {
Outliner::Outliner() : Widget("Outliner",true){
// NameEdit = NameEditor();
}
void Outliner::Draw() {
if(MainItem == nullptr)
return;
DrawNode(MainItem);
}
void Outliner::DrawNode(ITreeSerializable* Node) {
if(Node->GetObjectType() == Folder) {
if (ImGui::TreeNodeEx(Node->GetName().c_str(), ImGuiTreeNodeFlags_SpanFullWidth)) {
if(ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Left) || ImGui::IsMouseClicked(ImGuiMouseButton_Middle)) {
if(LastSelectedNode != nullptr)
LastSelectedNode->CurrentlySelected = false;
LastSelectedNode = Node;
Node->CurrentlySelected = true;
}
if(ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Right) ) {
NameEdit.Activate(Node);
}
for (auto item: Node->GetSubItems())
DrawNode(item);
ImGui::TreePop();
return;
}
if(ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Left) || ImGui::IsMouseClicked(ImGuiMouseButton_Middle)) {
if(LastSelectedNode != nullptr)
LastSelectedNode->CurrentlySelected = false;
LastSelectedNode = Node;
Node->CurrentlySelected = true;
}
if(ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
NameEdit.Activate(Node);
}
return;
}
if(ImGui::TreeNodeEx(Node->GetName().c_str(), ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_Bullet | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_SpanFullWidth)) {
if(ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Left) || ImGui::IsMouseClicked(ImGuiMouseButton_Middle)) {
if(LastSelectedNode != nullptr)
LastSelectedNode->CurrentlySelected = false;
LastSelectedNode = Node;
Node->CurrentlySelected = true;
}
if(ImGui::IsItemHovered() && ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
NameEdit.Activate(Node);
}
return;
}
}
void Outliner::PostDraw() {
Widget::PostDraw();
if(NameEdit.Active) {
NameEdit.PreDraw();
NameEdit.Draw();
NameEdit.PostDraw();
}
}
NameEditorOld::NameEditorOld() : Widget("Outliner Name Editor") {
std::cout << "Initializing Name Editor";
return;
}
void NameEditorOld::PreDraw() {
ImGui::Begin(Name.c_str(),&Active,ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize);
}
void NameEditorOld::Draw() {
ImGui::Text("Change Name of Node to:");
bool Done = ImGui::InputText("##",NewName,256,ImGuiInputTextFlags_EnterReturnsTrue);
ImVec2 PrevPos = ImGui::GetCursorPos();
Done |= ImGui::Button("Done",ImVec2(140.0f,30.0f));
PrevPos.x += 145.0f;
ImGui::SetCursorPos(PrevPos);
Active &= !ImGui::Button("Cancel",ImVec2(140.0f,30.0f));
if(Done){
EditingNode->SetName(std::string(NewName));
Active = false;
}
}
}

173
deps/vgcore/src/Shader.cpp vendored Normal file
View file

@ -0,0 +1,173 @@
#include<virintox/gcore/Shader.h>
#include<boost/dll.hpp>
#include<iostream>
#include<mutex>
namespace Graphics{
bool initd = false;
const GLchar *VertShaderSrc2D = "#version 460\n"
"layout (location = 0) in vec2 aPos;"
"layout (location = 1) in vec2 aTexCoord;\n"
"uniform mat4 ProjectionMatrix;\n"
"uniform mat4 TransformationMatrix;\n"
"out vec2 TexCoord;\n"
"void main(){\n"
"gl_Position = ProjectionMatrix * (vec4(aPos.x,aPos.y,1.0,1.0) * TransformationMatrix);"
"TexCoord = aTexCoord;\n"
"}\n";
const GLchar *FragShaderSrc2D = "#version 460\n"
"in vec2 TexCoord;\n"
"out vec4 FragColor;\n"
"uniform sampler2D tex;\n"
"void main(){\n"
"FragColor = texture(tex,TexCoord);//vec4(1.0f,1.0f,1.0f,1.0f);\n"
"}\n";
const GLchar *VertShaderSrc3D = "#version 460\n"
"layout (location = 0) in vec2 aPos;"
"layout (location = 1) in vec2 aTexCoord;\n"
"uniform mat4 ProjectionMatrix;\n"
"out vec2 TexCoord;\n"
"void main(){\n"
"gl_Position = ProjectionMatrix * vec4(aPos.x,-aPos.y,1.0,1.0);"
"TexCoord = aTexCoord;\n"
"}\n";
const GLchar *FragShaderSrc3D = "#version 460\n"
"in vec2 TexCoord;\n"
"out vec4 FragColor;\n"
"uniform sampler2D tex;\n"
"void main(){\n"
"FragColor = texture(tex,TexCoord);//vec4(1.0f,1.0f,1.0f,1.0f);\n"
"}\n";
Shader::Shader(const GLchar* VertexSrc, const GLchar* FragmentSrc){
GLuint VShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(VShader, 1, &VertexSrc, 0);
glCompileShader(VShader);
GLint isCompiled = 0;
glGetShaderiv(VShader, GL_COMPILE_STATUS, &isCompiled);
if(isCompiled == GL_FALSE)
{
GLint maxLength = 0;
glGetShaderiv(VShader, GL_INFO_LOG_LENGTH, &maxLength);
// The maxLength includes the NULL character
std::vector<GLchar> infoLog(maxLength);
glGetShaderInfoLog(VShader, maxLength, &maxLength, &infoLog[0]);
// We don't need the shader anymore.
glDeleteShader(VShader);
// Use the infoLog as you see fit.
for(GLchar c: infoLog)
std::cout << c;
std::cout << std::endl;
throw 1;
// In this simple program, we'll just leave
return;
}
// Create an empty fragment shader handle
GLuint FShader = glCreateShader(GL_FRAGMENT_SHADER);
// Send the fragment shader source code to GL
// Note that std::string's .c_str is NULL character terminated.
glShaderSource(FShader, 1, &FragmentSrc, 0);
// Compile the fragment shader
glCompileShader(FShader);
glGetShaderiv(FShader, GL_COMPILE_STATUS, &isCompiled);
if (isCompiled == GL_FALSE)
{
GLint maxLength = 0;
glGetShaderiv(FShader, GL_INFO_LOG_LENGTH, &maxLength);
// The maxLength includes the NULL character
std::vector<GLchar> infoLog(maxLength);
glGetShaderInfoLog(FShader, maxLength, &maxLength, &infoLog[0]);
for(GLchar c: infoLog)
std::cout << c;
std::cout << std::endl;
throw 1;
// We don't need the shader anymore.
glDeleteShader(FShader);
// Either of them. Don't leak shaders.
glDeleteShader(VShader);
// Use the infoLog as you see fit.
// In this simple program, we'll just leave
return;
}
ShaderId = glCreateProgram();
glAttachShader(ShaderId,VShader);
glAttachShader(ShaderId,FShader);
glLinkProgram(ShaderId);
GLint isLinked = 0;
glGetProgramiv(ShaderId, GL_LINK_STATUS, (int *)&isLinked);
if (isLinked == GL_FALSE)
{
GLint maxLength = 0;
glGetProgramiv(ShaderId, GL_INFO_LOG_LENGTH, &maxLength);
// The maxLength includes the NULL character
std::vector<GLchar> infoLog(maxLength);
glGetProgramInfoLog(ShaderId, maxLength, &maxLength, &infoLog[0]);
for(GLchar c: infoLog)
std::cout << c;
std::cout << std::endl;
throw 1;
// We don't need the program anymore.
glDeleteProgram(ShaderId);
// Don't leak shaders either.
glDeleteShader(VShader);
glDeleteShader(FShader);
// Use the infoLog as you see fit.
// In this simple program, we'll just leave
return;
}
GLuint texture = glGetUniformLocation(Shader::ShaderId, "tex");
glUniform1i(texture,0);
glDetachShader(ShaderId, VShader);
glDetachShader(ShaderId, FShader);
std::cout << "successfully compiled shader\n";
}
void Shader::Use() {
glUseProgram(ShaderId);
}
Shader &GetDefaultShader2D(){
static Shader DefaultShader2D = Shader(VertShaderSrc2D, FragShaderSrc2D);
return DefaultShader2D;
}
Shader &GetDefaultShader3D(){
static Shader DefaultShader3D = Shader(VertShaderSrc3D, FragShaderSrc3D);
return DefaultShader3D;
}
}

161
deps/vgcore/src/Sprite.cpp vendored Normal file
View file

@ -0,0 +1,161 @@
#include<virintox/gcore/Sprite.h>
#include<virintox/gcore/Shader.h>
Graphics::Sprite::Sprite(){}
Graphics::Sprite::Sprite(const glm::vec2 &Pos, float scale, Texture* Tex) {
TexPtr = Tex;
VCount = 6;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glGenBuffers(1, &EBO);
std::vector<float> vertices{
Pos.x ,Pos.y,
0.0f ,0.0f,
Pos.x + TexPtr->size.x * scale,Pos.y,
1.0f ,0.0f,
Pos.x ,Pos.y + TexPtr->size.y * scale,
0.0f ,1.0f,
Pos.x + TexPtr->size.x * scale,Pos.y,
1.0f ,0.0f,
Pos.x + TexPtr->size.x * scale,Pos.y + TexPtr->size.y * scale,
1.0f ,1.0f,
Pos.x ,Pos.y + TexPtr->size.y * scale,
0.0f ,1.0f
};
unsigned int indices[] = {
0,1,2,
3,4,5
};
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), &vertices[0], GL_DYNAMIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_DYNAMIC_DRAW);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));
glEnableVertexAttribArray(1);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
Graphics::Sprite::Sprite(const glm::mat3x2 &Veticies, const glm::mat3x2 &TexCoords, Texture* Tex) {
TexPtr = Tex;
VCount = 3;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glGenBuffers(1, &EBO);
std::vector<float> vertices{
Veticies[0].x,Veticies[0].y,TexCoords[0].x / TexPtr->size.x,TexCoords[0].y / TexPtr->size.y,
Veticies[1].x,Veticies[1].y,TexCoords[1].x / TexPtr->size.x,TexCoords[1].y / TexPtr->size.y,
Veticies[2].x,Veticies[2].y,TexCoords[2].x / TexPtr->size.x,TexCoords[2].y / TexPtr->size.y
};
unsigned int indices[] = {
0,1,2
};
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), &vertices[0], GL_DYNAMIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_DYNAMIC_DRAW);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));
glEnableVertexAttribArray(1);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
void Graphics::Sprite::Draw() {
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Graphics::GetDefaultShader2D().Use();
TexPtr->SetActive();
glDrawElements(GL_TRIANGLES, VCount, GL_UNSIGNED_INT, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
void Graphics::Sprite::Update(const glm::vec2 &Pos, float scale) const{
std::vector<float> vertices{
Pos.x ,Pos.y,
0.0f ,0.0f,
Pos.x + TexPtr->size.x * scale,Pos.y,
1.0f ,0.0f,
Pos.x ,Pos.y + TexPtr->size.y * scale,
0.0f ,1.0f,
Pos.x + TexPtr->size.x * scale,Pos.y,
1.0f ,0.0f,
Pos.x + TexPtr->size.x * scale,Pos.y + TexPtr->size.y * scale,
1.0f ,1.0f,
Pos.x ,Pos.y + TexPtr->size.y * scale,
0.0f ,1.0f
};
unsigned int indices[] = {
0,1,2,
3,4,5
};
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), &vertices[0], GL_DYNAMIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_DYNAMIC_DRAW);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}
void Graphics::Sprite::Update(const glm::mat3x2 &Veticies, const glm::mat3x2 &TexCoords) const{
std::vector<float> vertices{
Veticies[0].x,Veticies[0].y,TexCoords[0].x / TexPtr->size.x,TexCoords[0].y / TexPtr->size.y,
Veticies[1].x,Veticies[1].y,TexCoords[1].x / TexPtr->size.x,TexCoords[1].y / TexPtr->size.y,
Veticies[2].x,Veticies[2].y,TexCoords[2].x / TexPtr->size.x,TexCoords[2].y / TexPtr->size.y
};
unsigned int indices[] = {
0,1,2
};
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), &vertices[0], GL_DYNAMIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_DYNAMIC_DRAW);
glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
}

123
deps/vgcore/src/Texture.cpp vendored Normal file
View file

@ -0,0 +1,123 @@
#include "virintox/gcore/Mesh.h"
#include<virintox/gcore/Texture.h>
#include<virintox/gcore/Shader.h>
#define STB_IMAGE_IMPLEMENTATION
#include<virintox/gcore/stb_image.h>
#include<iostream>
namespace Graphics {
Texture::Texture(boost::filesystem::path PngFile,bool Normalized) {
glGenTextures(1, &TexID);
glBindTexture(GL_TEXTURE_2D, TexID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glPixelStoref(GL_UNPACK_ALIGNMENT,1);
glPixelStoref(GL_PACK_ALIGNMENT,1);
int width, height, nrChannels;
unsigned char *data = stbi_load(PngFile.string().c_str(), &width, &height, &nrChannels, 0);
if (data)
{
if(nrChannels == 4)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
if(nrChannels == 3)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
}
else
{
std::cout << "Failed to load texture" << std::endl;
}
stbi_image_free(data);
if(!Normalized)
size = glm::vec2(width,height);
else
size = glm::vec2(1.0,1.0);
glBindBuffer(GL_ARRAY_BUFFER,0);
glBindVertexArray(0);
}
Texture::~Texture() {
}
void Texture::Draw(glm::vec2 pos, float scale) {
static Mesh quadmesh = [](){
glm::vec2 P1(0,0);
glm::vec2 P2(1, 0);
glm::vec2 P3(0,1);
glm::vec2 P4(1,1);
glm::vec2 TP1(0, 0);
glm::vec2 TP2(1, 0);
glm::vec2 TP3(0, 1);
glm::vec2 TP4(1,1);
return Mesh({P1,P2,P3,P2,P4,P3},{1,2,3,4,5,6},{TP1,TP2,TP3,TP2,TP4,TP3});
}();
quadmesh.Draw(*this, pos);
}
void Texture::DrawC(glm::vec2 pos, float scale) {
Draw(pos - size * (scale / 2), scale);
}
void Texture::DrawTri(glm::tmat3x2<float> Tri, glm::tmat3x2<float> TexCoords) {
GetDefaultShader2D().Use();
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
std::vector<float> vertices{
Tri[0].x,Tri[0].y,TexCoords[0].x / size.x,TexCoords[0].y / size.y,
Tri[1].x,Tri[1].y,TexCoords[1].x / size.x,TexCoords[1].y / size.y,
Tri[2].x,Tri[2].y,TexCoords[2].x / size.x,TexCoords[2].y / size.y
};
unsigned int indices[] = {
0,1,2
};
unsigned int VBO, VAO, EBO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glGenBuffers(1, &EBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), &vertices[0], GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
// position attribute
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
// color attribute
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)(2 * sizeof(float)));
glEnableVertexAttribArray(1);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, TexID);
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glDeleteVertexArrays(1, &VAO);
glDeleteBuffers(1, &VBO);
glDeleteBuffers(1, &EBO);
}
void Texture::SetActive() const{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, TexID);
}
}

80
deps/vgcore/src/Viewport.cpp vendored Normal file
View file

@ -0,0 +1,80 @@
#define GLEW_STATIC
#include<GL/glew.h>
#include<virintox/gcore/Viewport.h>
#include<virintox/gcore/Shader.h>
#include<imgui.h>
#include<glm/gtc/matrix_transform.hpp>
#include<glm/gtx/string_cast.hpp>
#include<iostream>
Graphics::Viewport::Viewport(){
framewidth = 0;
frameheight = 0;
glGenFramebuffers(1, &Framebuffer);
glGenTextures(1, &FramebufferTex);
glGenTextures(1, &FramebufferDepthTex);
glGenTextures(1, &FramebufferMatIdTex);
glGenTextures(1, &FramebufferWorldPosTex);
RecreateFramebuffer();
}
void Graphics::Viewport::HandleInput(InputEvent) {/* Not a pure virtual */}
void Graphics::Viewport::RecreateFramebuffer() {
/*glDeleteFramebuffers(1,&Framebuffer);
glDeleteTextures(1,&Framebuffer);
glDeleteTextures(1,&FramebufferDepthTex);
glDeleteTextures(1,&FramebufferMatIdTex);
glDeleteTextures(1,&FramebufferWorldPosTex);
glGenFramebuffers(1, &Framebuffer);
glGenTextures(1, &FramebufferTex);
glGenTextures(1, &FramebufferDepthTex);
glGenTextures(1, &FramebufferMatIdTex);
glGenTextures(1, &FramebufferWorldPosTex);*/
glBindFramebuffer(GL_FRAMEBUFFER, Framebuffer);
glBindTexture(GL_TEXTURE_2D, FramebufferTex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, framewidth, frameheight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, FramebufferTex, 0);
glBindTexture(GL_TEXTURE_2D, FramebufferMatIdTex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32UI , framewidth, frameheight, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, FramebufferMatIdTex, 0);
glBindTexture(GL_TEXTURE_2D, FramebufferWorldPosTex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, framewidth, frameheight, 0, GL_RGBA, GL_FLOAT, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, FramebufferWorldPosTex, 0);
glBindTexture(GL_TEXTURE_2D, FramebufferDepthTex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH24_STENCIL8, framewidth, frameheight, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, FramebufferDepthTex, 0);
glBindTexture(GL_TEXTURE_2D,0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
lastframeheight = frameheight;
lastframewidth = framewidth;
}
void Graphics::Viewport::ChangeView(const glm::vec2 &pos, float scale) const{
auto matrix = glm::ortho(pos.x,pos.x+framewidth*scale,pos.y+frameheight*scale,pos.y);
GLuint MatrixID = glGetUniformLocation(GetDefaultShader2D().ShaderId, "ProjectionMatrix");
glUniformMatrix4fv(MatrixID,1,GL_FALSE,&matrix[0][0]);
}
void Graphics::Viewport::ChangeView(float x,float y, float scale) const{
auto matrix = glm::ortho(x,x+framewidth*scale,y,y+frameheight*scale);
GLuint MatrixID = glGetUniformLocation(GetDefaultShader2D().ShaderId, "ProjectionMatrix");
glUniformMatrix4fv(MatrixID,1,GL_FALSE,&matrix[0][0]);
}

122
deps/vgcore/src/ViewportWidget.cpp vendored Normal file
View file

@ -0,0 +1,122 @@
#include<GL/glew.h>
#include<virintox/gcore/ViewportWidget.h>
#include<virintox/gcore/Shader.h>
#include<virintox/gcore/Viewport.h>
#include<imgui.h>
#include<glm/gtc/matrix_transform.hpp>
#include<glm/gtx/string_cast.hpp>
#include<iostream>
namespace Graphics{
ViewportWidget::ViewportWidget(std::string name,bool active) : Widget(name,active) , Viewport(){
}
void ViewportWidget::PreDraw() {
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding,ImVec2(0,0));
ImGui::Begin(Name.c_str(),&Active,ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse);
ImVec2 windsize = ImGui::GetWindowSize();
framewidth = windsize.x;
frameheight = windsize.y - 23;
if((framewidth != lastframewidth) || (frameheight != lastframeheight))
RecreateFramebuffer();
glBindFramebuffer(GL_FRAMEBUFFER,Framebuffer);
glViewport(0,0,framewidth,frameheight);
glClearColor(.2,.2,.2,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void ViewportWidget::PostDraw() {
auto preimgcpos = ImGui::GetCursorPos();
ImVec2 windsize = ImGui::GetWindowSize();
windsize.y -= 23;
//glFinish();
ImGui::SetCursorPos(ImVec2(0,23));
ImGui::Image(reinterpret_cast<ImTextureID>(FramebufferTex),windsize);
if(ImGui::IsItemHovered()){
std::vector<InputEvent> Events;
ImGui::SetCursorPos(ImVec2(0,23));
ImVec2 ScreenPos = ImGui::GetMousePos();
ImVec2 PosRel = ImGui::GetCursorScreenPos();
float X = ScreenPos.x - PosRel.x;
float Y = ScreenPos.y - PosRel.y;
X /= windsize.x;
Y /= windsize.y;
InputEvent Event = InputEvent {X,Y,MouseHover};
Events.push_back(Event);
ImGuiIO& IO = ImGui::GetIO();
if(ImGui::IsMouseClicked(ImGuiMouseButton_Right)){
InputEvent NEvent = Event;
NEvent.EventType = MouseDownR;
Events.push_back(NEvent);
}
if(ImGui::IsMouseClicked(ImGuiMouseButton_Left)){
InputEvent NEvent = Event;
NEvent.EventType = MouseDownL;
Events.push_back(NEvent);
}
if(ImGui::IsMouseReleased(ImGuiMouseButton_Right)){
InputEvent NEvent = Event;
NEvent.EventType = MouseUpR;
Events.push_back(NEvent);
}
if(ImGui::IsMouseReleased(ImGuiMouseButton_Left)){
InputEvent NEvent = Event;
NEvent.EventType = MouseUpL;
Events.push_back(NEvent);
}
if (ImGui::IsMouseDragging(ImGuiMouseButton_Right)) {
InputEvent NEvent = Event;
NEvent.EventType = MouseHoldR;
Events.push_back(NEvent);
}
if (ImGui::IsMouseDragging(ImGuiMouseButton_Left)){
InputEvent NEvent = Event;
NEvent.EventType = MouseHoldL;
Events.push_back(NEvent);
}
if(IO.MouseWheel != 0){
InputEvent NEvent = Event;
NEvent.EventType = MWheel;
NEvent.MWheel = IO.MouseWheel;
Events.push_back(NEvent);
}
for(InputEvent e: Events) {
HandleInput(e);
}
}
glBindFramebuffer(GL_FRAMEBUFFER,0);
ImGui::PopStyleVar();
ImGui::SetCursorPos(preimgcpos);
DrawOver();
ImGui::End();
}
void ViewportWidget::DrawOver() {}
}

28
deps/vgcore/src/Widget.cpp vendored Normal file
View file

@ -0,0 +1,28 @@
#include<virintox/gcore/Graphics.h>
#include<virintox/gcore/Widget.h>
#include<imgui.h>
namespace Graphics{
Widget::Widget(std::string name, bool active) {
Name = name;
Active = active;
Elements = std::vector<std::unique_ptr<WidgetElement>>();
}
void Widget::Update() {
}
void Widget::PreDraw() {
ImGui::Begin(Name.c_str(),&Active);
}
void Widget::Draw() {
}
void Widget::PostDraw() {
ImGui::End();
}
}

168
deps/vgcore/src/Window.cpp vendored Normal file
View file

@ -0,0 +1,168 @@
#include<GL/glew.h>
#include<virintox/gcore/Window.h>
#include<virintox/gcore/MessageBox.h>
#include<virintox/gcore/Graphics.h>
#include<virintox/gcore/Shader.h>
#include <exception>
#include<imgui.h>
#include<backends/imgui_impl_glfw.h>
#include<backends/imgui_impl_opengl3.h>
#include<stdexcept>
#include<iostream>
#include "IconsFontAwesome6.h"
void ScrollCallback(GLFWwindow* window, double xoffset, double yoffset){
Graphics::MWheel -= yoffset * Graphics::MWheel / 2;
}
void drop_callback(GLFWwindow* window, int count, const char** paths)
{
std::vector<std::string> Files = std::vector<std::string>();
for (int x = 0; x < count; x++)
Files.push_back(std::string(paths[x]));
Graphics::window->DropCallback(Files);
}
namespace Graphics {
Window::Window(const std::string &name) {
Widgets = std::vector<std::unique_ptr<Widget>>();
glfwWindowHint( GLFW_CONTEXT_VERSION_MAJOR, 4 );
glfwWindowHint( GLFW_CONTEXT_VERSION_MINOR, 6 );
glfwWindowHint( GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE );
glfwWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );
window = glfwCreateWindow(900,900,name.c_str(),NULL,NULL);
glfwMakeContextCurrent(window);
glfwSetScrollCallback(window,ScrollCallback);
glfwSetDropCallback(window, drop_callback);
glewExperimental = true;
if(GLEW_OK != glewInit())
throw std::runtime_error("Could not Initialize glew");
glfwSwapInterval(0);
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO &io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
//io.ConfigWindowsMoveFromTitleBarOnly = true;
io.WantCaptureKeyboard = false;
io.WantCaptureMouse = false;
io.WantCaptureMouseUnlessPopupClose = false;
io.Fonts->AddFontFromFileTTF("Roboto-Regular.ttf",16);
float baseFontSize = 16.0f;
float iconFontSize = baseFontSize * 2.0f / 3.0f;
static const ImWchar icons_ranges[] = { ICON_MIN_FA, ICON_MAX_16_FA, 0 };
ImFontConfig icons_config;
icons_config.MergeMode = true;
icons_config.PixelSnapH = true;
icons_config.GlyphMinAdvanceX = iconFontSize;
io.Fonts->AddFontFromFileTTF( FONT_ICON_FILE_NAME_FAS, iconFontSize, &icons_config, icons_ranges );
ImGuiStyle &style = ImGui::GetStyle();
style.FrameRounding = 4;
style.WindowRounding = 12;
style.ChildBorderSize = 1.0f;
style.WindowTitleAlign = ImVec2(0.5f,0.5f);
ImGui_ImplGlfw_InitForOpenGL(window, true);
ImGui_ImplOpenGL3_Init();
ImGui::StyleColorsDark();
}
void Window::Update() {
}
void Window::Draw() {
if(glfwWindowShouldClose(window)) {
glfwSetWindowShouldClose(window,GLFW_FALSE);
ImGui::OpenPopup("Are you sure?##QuitModal");
}
DrawBG();
ImGui::DockSpaceOverViewport(ImGui::GetMainViewport(),ImGuiDockNodeFlags_PassthruCentralNode);
ImGui::BeginMainMenuBar();
for(auto &M: Menus) {
if(ImGui::BeginMenu(M.first.c_str())) {
for (auto &I: M.second) {
bool pressed = false;
ImGui::MenuItem(I.Name.c_str(),I.Shortcut.c_str() ,&pressed);
if(pressed || (glfwGetKey(window,GLFW_KEY_LEFT_CONTROL) && glfwGetKey(window,I.ShortcutKey)))
I.Func();
}
ImGui::EndMenu();
}
}
ImGui::EndMainMenuBar();
for(auto& widget: Widgets) {
if(widget->Active) {
#ifdef NDEBUG
try{
#endif
widget->PreDraw();
widget->Draw();
widget->PostDraw();
#ifdef NDEBUG
} catch(const MSGBoxException& msgexc){
std::cout << msgexc.what() << std::endl;
msgBoxes.push_back(new MessageBox(msgexc.whattext,msgexc.Severity));
ImGui::End();
} catch(const std::exception& exc){
std::cout << exc.what() << std::endl;
msgBoxes.push_back(new MessageBox(exc.what(),Fault));
ImGui::End();
} catch(...){
std::cout << "Something happend .-." << std::endl;
msgBoxes.push_back(new MessageBox("An unknown error occured",Fault));
ImGui::End();
}
#endif
}
}
for(auto box :msgBoxes){
bool brk;
box->PreDraw();
box->Draw();
brk = box->Deactivate;
box->PostDraw();
if(brk) break;
}
if(ImGui::BeginPopupModal("Are you sure?##QuitModal",NULL,ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize)){
ImGui::Text("Are you sure that you wish to quit?");
ImGui::SetCursorPosX(ImGui::CalcTextSize("Are you sure that you wish to quit?").x - ImGui::CalcTextSize(" Yes No ").x);
if(ImGui::Button("Yes"))
Graphics::Quit();
ImGui::SameLine();
if(ImGui::Button("No"))
ImGui::CloseCurrentPopup();
ImGui::EndPopup();
}
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
glfwSwapBuffers(window);
glfwPollEvents();
}
void Window::DropCallback(const std::vector<std::string> &paths) {return;}
void Window::DrawBG() {
glClearColor(.2,.2,.2,1);
glClear(GL_COLOR_BUFFER_BIT);
}
}

BIN
res/blank.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 720 B

12
res/untitled.mtl Normal file
View file

@ -0,0 +1,12 @@
# Blender 3.5.1 MTL File: 'None'
# www.blender.org
newmtl Material
Ns 250.000000
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.800000 0.800000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2

40
res/untitled.obj Normal file
View file

@ -0,0 +1,40 @@
# Blender 3.5.1
# www.blender.org
mtllib untitled.mtl
o Cube
v 1.000000 1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 1.000000
v -1.000000 -1.000000 1.000000
vn -0.0000 1.0000 -0.0000
vn -0.0000 -0.0000 1.0000
vn -1.0000 -0.0000 -0.0000
vn -0.0000 -1.0000 -0.0000
vn 1.0000 -0.0000 -0.0000
vn -0.0000 -0.0000 -1.0000
vt 0.625000 0.500000
vt 0.375000 0.500000
vt 0.625000 0.750000
vt 0.375000 0.750000
vt 0.875000 0.500000
vt 0.625000 0.250000
vt 0.125000 0.500000
vt 0.375000 0.250000
vt 0.875000 0.750000
vt 0.625000 1.000000
vt 0.625000 0.000000
vt 0.375000 1.000000
vt 0.375000 0.000000
vt 0.125000 0.750000
s 0
usemtl Material
f 1/1/1 5/5/1 7/9/1 3/3/1
f 4/4/2 3/3/2 7/10/2 8/12/2
f 8/13/3 7/11/3 5/6/3 6/8/3
f 6/7/4 2/2/4 4/4/4 8/14/4
f 2/2/5 1/1/5 3/3/5 4/4/5
f 6/8/6 5/6/6 1/1/6 2/2/6