mirror of
https://github.com/Relintai/sfw.git
synced 2024-12-20 21:06:49 +01:00
Backport using the ui in the render test app demo.
This commit is contained in:
parent
268e9417ff
commit
23de62a08d
@ -283,6 +283,10 @@ void GameScene::render() {
|
|||||||
r->camera_2d_projection_set_to_window();
|
r->camera_2d_projection_set_to_window();
|
||||||
r->clear_screen(Color(1, 0, 0));
|
r->clear_screen(Color(1, 0, 0));
|
||||||
r->draw_texture(_render_tex, Rect2(100, 100, render_tex_size.x, render_tex_size.y));
|
r->draw_texture(_render_tex, Rect2(100, 100, render_tex_size.x, render_tex_size.y));
|
||||||
|
} else if (render_type == 14) {
|
||||||
|
render_gui();
|
||||||
|
} else if (render_type == 15) {
|
||||||
|
render_gui_manual();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void GameScene::render_immediate(bool clear_screen) {
|
void GameScene::render_immediate(bool clear_screen) {
|
||||||
@ -393,6 +397,84 @@ void GameScene::render_immediate_3d(bool clear_screen) {
|
|||||||
rotmi += 0.01;
|
rotmi += 0.01;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GameScene::render_gui(bool clear_screen) {
|
||||||
|
Renderer *r = Renderer::get_singleton();
|
||||||
|
|
||||||
|
if (clear_screen) {
|
||||||
|
r->clear_screen(Color());
|
||||||
|
r->camera_2d_projection_set_to_window();
|
||||||
|
|
||||||
|
r->camera_3d_bind();
|
||||||
|
r->camera_3d_projection_set_to_perspective(AppWindow::get_singleton()->get_aspect());
|
||||||
|
}
|
||||||
|
|
||||||
|
GUI::new_frame();
|
||||||
|
GUI::test();
|
||||||
|
GUI::render();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GameScene::render_gui_manual(bool clear_screen) {
|
||||||
|
Renderer *r = Renderer::get_singleton();
|
||||||
|
|
||||||
|
if (clear_screen) {
|
||||||
|
r->clear_screen(Color());
|
||||||
|
r->camera_2d_projection_set_to_window();
|
||||||
|
|
||||||
|
r->camera_3d_bind();
|
||||||
|
r->camera_3d_projection_set_to_perspective(AppWindow::get_singleton()->get_aspect());
|
||||||
|
}
|
||||||
|
|
||||||
|
GUI::new_frame();
|
||||||
|
|
||||||
|
|
||||||
|
ImGuiIO &io = ImGui::GetIO();
|
||||||
|
(void)io;
|
||||||
|
|
||||||
|
// Our state
|
||||||
|
static bool show_demo_window = true;
|
||||||
|
static bool show_another_window = false;
|
||||||
|
static ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
|
||||||
|
|
||||||
|
// 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!).
|
||||||
|
if (show_demo_window) {
|
||||||
|
ImGui::ShowDemoWindow(&show_demo_window);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Show a simple window that we create ourselves. We use a Begin/End pair to create a named window.
|
||||||
|
{
|
||||||
|
static float f = 0.0f;
|
||||||
|
static int counter = 0;
|
||||||
|
|
||||||
|
ImGui::Begin("Hello, world! This is an another demo!"); // Create a window called "Hello, world!" and append into it.
|
||||||
|
|
||||||
|
ImGui::Text("This is some useful text."); // Display some text (you can use a format strings too)
|
||||||
|
ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our window open/close state
|
||||||
|
ImGui::Checkbox("Another Window", &show_another_window);
|
||||||
|
|
||||||
|
ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
|
||||||
|
ImGui::ColorEdit3("clear color", (float *)&clear_color); // Edit 3 floats representing a color
|
||||||
|
|
||||||
|
if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
|
||||||
|
counter++;
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Text("counter = %d", counter);
|
||||||
|
|
||||||
|
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Show another simple window.
|
||||||
|
if (show_another_window) {
|
||||||
|
ImGui::Begin("Another Window", &show_another_window); // Pass a pointer to our bool variable (the window will have a closing button that will clear the bool when clicked)
|
||||||
|
ImGui::Text("Hello from another window!");
|
||||||
|
if (ImGui::Button("Close Me"))
|
||||||
|
show_another_window = false;
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
GUI::render();
|
||||||
|
}
|
||||||
|
|
||||||
void GameScene::toggle_thread() {
|
void GameScene::toggle_thread() {
|
||||||
if (_thread) {
|
if (_thread) {
|
||||||
_thread_running = false;
|
_thread_running = false;
|
||||||
@ -692,6 +774,7 @@ GameScene::GameScene() {
|
|||||||
_mesh_utils_test.instance();
|
_mesh_utils_test.instance();
|
||||||
|
|
||||||
Renderer::initialize();
|
Renderer::initialize();
|
||||||
|
GUI::initialize();
|
||||||
|
|
||||||
_mesh_utils_test_mi = memnew(MeshInstance3D());
|
_mesh_utils_test_mi = memnew(MeshInstance3D());
|
||||||
_mesh_utils_test_mi->material = color_material;
|
_mesh_utils_test_mi->material = color_material;
|
||||||
@ -705,6 +788,7 @@ GameScene::GameScene() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GameScene::~GameScene() {
|
GameScene::~GameScene() {
|
||||||
|
GUI::destroy();
|
||||||
Renderer::destroy();
|
Renderer::destroy();
|
||||||
|
|
||||||
memdelete(tile_map);
|
memdelete(tile_map);
|
||||||
|
@ -11,7 +11,7 @@ class GameScene : public Scene {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
enum RenderTypes {
|
enum RenderTypes {
|
||||||
RENDER_TYPE_MAX = 14
|
RENDER_TYPE_MAX = 16
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual void input_event(const Ref<InputEvent> &event);
|
virtual void input_event(const Ref<InputEvent> &event);
|
||||||
@ -20,6 +20,8 @@ public:
|
|||||||
virtual void render_immediate(bool clear_screen = true);
|
virtual void render_immediate(bool clear_screen = true);
|
||||||
virtual void render_obj();
|
virtual void render_obj();
|
||||||
virtual void render_immediate_3d(bool clear_screen = true);
|
virtual void render_immediate_3d(bool clear_screen = true);
|
||||||
|
virtual void render_gui(bool clear_screen = true);
|
||||||
|
virtual void render_gui_manual(bool clear_screen = true);
|
||||||
|
|
||||||
void toggle_thread();
|
void toggle_thread();
|
||||||
static void test_thread_func(void *d);
|
static void test_thread_func(void *d);
|
||||||
|
@ -802,8 +802,8 @@ GameScene::GameScene() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GameScene::~GameScene() {
|
GameScene::~GameScene() {
|
||||||
Renderer::destroy();
|
|
||||||
GUI::destroy();
|
GUI::destroy();
|
||||||
|
Renderer::destroy();
|
||||||
|
|
||||||
memdelete(tile_map);
|
memdelete(tile_map);
|
||||||
memdelete(camera);
|
memdelete(camera);
|
||||||
|
Loading…
Reference in New Issue
Block a user