Skip to content
This repository has been archived by the owner on Dec 5, 2020. It is now read-only.

Commit

Permalink
gui: Add imgui, base: add updatePreClear
Browse files Browse the repository at this point in the history
This probably isn't very useful for production games, but may be useful
for debugging, editors, etc. It may also serve well as a placeholder UI
for prototyping.

blackcomb::imgui::Wrapper will allow you to handle imgui's platform
specific tasks in a platform agnostic way. I'm considering how to make
this work with #2; right now I'm thinking of conditionally including
the contents of a platform-specific file depending on your configuration.
includes/blackcomb/imgui/imconfig.h will also have to be updated for this.

nb. imgui retains its own namespace, ImGui, rather than being shoved
into Blackcomb, since it's technically thirdparty. The only part in
the blackcomb namespace is blackcomb::imgui::Wrapper, since that's
Blackcomb specific.
  • Loading branch information
PatchMixolydic committed Jan 10, 2019
1 parent f5919b4 commit ef1a73c
Show file tree
Hide file tree
Showing 21 changed files with 34,925 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ set(GLFW_INC_DIRECTORY "/usr/include" CACHE FILEPATH "GLFW's include directory")

include_directories(${GLFW_INC_DIRECTORY}/GLFW thirdparty/ ${PROJECT_SOURCE_DIR}/include)

add_library(blackcomb thirdparty/glad.c src/base/Window.cpp include/blackcomb/base/Window.h src/renderer/Shader.cpp include/blackcomb/renderer/Shader.h src/renderer/Mesh.cpp include/blackcomb/renderer/Mesh.h src/renderer/Texture.cpp include/blackcomb/renderer/Texture.h include/blackcomb/misc/BlackcombException.h src/misc/BlackcombException.cpp src/renderer/Model.cpp include/blackcomb/renderer/Model.h src/entities/BaseEntity.cpp include/blackcomb/entities/BaseEntity.h src/entities/RenderableEntity.cpp include/blackcomb/entities/RenderableEntity.h src/entities/Camera.cpp include/blackcomb/entities/Camera.h src/entities/FreeMoveCamera.cpp include/blackcomb/entities/FreeMoveCamera.h src/input/MouseWatcher.cpp include/blackcomb/input/MouseWatcher.h src/misc/BlackcombUtils.cpp include/blackcomb/misc/BlackcombUtils.h src/renderer/TextureAtlas.cpp include/blackcomb/renderer/TextureAtlas.h include/blackcomb/misc/Coords.h src/misc/Coords.cpp src/misc/RNG.cpp include/blackcomb/misc/RNG.h src/base/AppBase.cpp include/blackcomb/base/AppBase.h)
add_library(blackcomb thirdparty/glad.c src/base/Window.cpp include/blackcomb/base/Window.h src/renderer/Shader.cpp include/blackcomb/renderer/Shader.h src/renderer/Mesh.cpp include/blackcomb/renderer/Mesh.h src/renderer/Texture.cpp include/blackcomb/renderer/Texture.h include/blackcomb/misc/BlackcombException.h src/misc/BlackcombException.cpp src/renderer/Model.cpp include/blackcomb/renderer/Model.h src/entities/BaseEntity.cpp include/blackcomb/entities/BaseEntity.h src/entities/RenderableEntity.cpp include/blackcomb/entities/RenderableEntity.h src/entities/Camera.cpp include/blackcomb/entities/Camera.h src/entities/FreeMoveCamera.cpp include/blackcomb/entities/FreeMoveCamera.h src/input/MouseWatcher.cpp include/blackcomb/input/MouseWatcher.h src/misc/BlackcombUtils.cpp include/blackcomb/misc/BlackcombUtils.h src/renderer/TextureAtlas.cpp include/blackcomb/renderer/TextureAtlas.h include/blackcomb/misc/Coords.h src/misc/Coords.cpp src/misc/RNG.cpp include/blackcomb/misc/RNG.h src/base/AppBase.cpp include/blackcomb/base/AppBase.h
src/imgui/imgui.cpp src/imgui/imgui_draw.cpp src/imgui/imgui_widgets.cpp src/imgui/imgui_impl_glfw.cpp src/imgui/imgui_impl_opengl3.cpp src/imgui/imgui_demo.cpp
src/imgui/Wrapper.cpp include/blackcomb/imgui/Wrapper.h)
2 changes: 2 additions & 0 deletions include/blackcomb/base/AppBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ namespace blackcomb::base {
~AppBase();
base::Window& getWindow();
virtual void run();
virtual void updatePreClear();
virtual void update();
virtual void processInput();
virtual void destroy();
float deltaTime = 0.0f;
float lastFrame = static_cast<float>(glfwGetTime());
private:
Expand Down
21 changes: 21 additions & 0 deletions include/blackcomb/imgui/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014-2019 Omar Cornut

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 22 additions & 0 deletions include/blackcomb/imgui/Wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef IMGUITEST_IMGUIWRAPPER_H
#define IMGUITEST_IMGUIWRAPPER_H

#include <blackcomb/imgui/imgui.h>
#include <blackcomb/imgui/imgui_impl_glfw.h>
#include <blackcomb/imgui/imgui_impl_opengl3.h>

namespace blackcomb::imgui {
/**
* A conveniece wrapper for Dear IMGUI's initialization and destruction.
*/
class Wrapper {
public:
static void initialize(GLFWwindow* windowPtr, const char* glslVersion = nullptr, bool installCallbacks = true);
static void beginFrame();
static void render();
static void destroy();
};
}


#endif //IMGUITEST_IMGUIWRAPPER_H
76 changes: 76 additions & 0 deletions include/blackcomb/imgui/imconfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
//-----------------------------------------------------------------------------
// COMPILE-TIME OPTIONS FOR DEAR IMGUI
// Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure.
// You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions.
//-----------------------------------------------------------------------------
// A) You may edit imconfig.h (and not overwrite it when updating imgui, or maintain a patch/branch with your modifications to imconfig.h)
// B) or add configuration directives in your own file and compile with #define IMGUI_USER_CONFIG "myfilename.h"
// If you do so you need to make sure that configuration settings are defined consistently _everywhere_ dear imgui is used, which include
// the imgui*.cpp files but also _any_ of your code that uses imgui. This is because some compile-time options have an affect on data structures.
// Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts.
// Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using.
//-----------------------------------------------------------------------------

#pragma once

//---- Define assertion handler. Defaults to calling assert().
//#define IM_ASSERT(_EXPR) MyAssert(_EXPR)
//#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts

//---- Define attributes of all API symbols declarations, e.g. for DLL under Windows.
//#define IMGUI_API __declspec( dllexport )
//#define IMGUI_API __declspec( dllimport )

//---- Don't define obsolete functions/enums names. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names.
//#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS

//---- Don't implement demo windows functionality (ShowDemoWindow()/ShowStyleEditor()/ShowUserGuide() methods will be empty)
//---- It is very strongly recommended to NOT disable the demo windows during development. Please read the comments in imgui_demo.cpp.
//#define IMGUI_DISABLE_DEMO_WINDOWS

//---- Don't implement some functions to reduce linkage requirements.
//#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc.
//#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] Don't implement default IME handler. Won't use and link with ImmGetContext/ImmSetCompositionWindow.
//#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function.
//#define IMGUI_DISABLE_FORMAT_STRING_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself if you don't want to link with vsnprintf.
//#define IMGUI_DISABLE_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 wrapper so you can implement them yourself. Declare your prototypes in imconfig.h.
//#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions().

//---- Include imgui_user.h at the end of imgui.h as a convenience
//#define IMGUI_INCLUDE_IMGUI_USER_H

//---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another)
//#define IMGUI_USE_BGRA_PACKED_COLOR

//---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version
// By default the embedded implementations are declared static and not available outside of imgui cpp files.
//#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h"
//#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h"
//#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION
//#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION

//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
/*
#define IM_VEC2_CLASS_EXTRA \
ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \
operator MyVec2() const { return MyVec2(x,y); }
#define IM_VEC4_CLASS_EXTRA \
ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \
operator MyVec4() const { return MyVec4(x,y,z,w); }
*/

//---- Use 32-bit vertex indices (default is 16-bit) to allow meshes with more than 64K vertices. Render function needs to support it.
//#define ImDrawIdx unsigned int

// Use GLAD as the default loader
#define IMGUI_IMPL_OPENGL_LOADER_GLAD

//---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files.
/*
namespace ImGui
{
void MyFunction(const char* name, const MyMatrix44& v);
}
*/
Loading

1 comment on commit ef1a73c

@PatchMixolydic
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit also adds AppBase::destroy, for all your destructor needs.

Please sign in to comment.