diff --git a/sfw/game_scene.cpp b/sfw/game_scene.cpp index 2ac11bc..e2c917f 100644 --- a/sfw/game_scene.cpp +++ b/sfw/game_scene.cpp @@ -476,7 +476,7 @@ void GameScene::socket_thread_func(void *data) { int a = self->_server_socket->accept(client_socket); if (a != -1) { - printf("New connection! %d\n", a); + ERR_PRINT("New connection! " + itos(a)); client_sockets.push_back(client_socket); client_socket = new Socket(); diff --git a/tools/merger/test_app/game_scene.cpp b/tools/merger/test_app/game_scene.cpp index e3da781..f6b4a6d 100644 --- a/tools/merger/test_app/game_scene.cpp +++ b/tools/merger/test_app/game_scene.cpp @@ -1,6 +1,6 @@ #include "game_scene.h" -#include +#include "sfw.h" void GameScene::input_event(const Ref &event) { //ERR_PRINT(event->as_text()); @@ -256,13 +256,42 @@ void GameScene::render() { _mesh_utils_test_mi->render(); } else if (render_type == 12) { render_immediate_3d(); + } else if (render_type == 13) { + Renderer *r = Renderer::get_singleton(); + r->set_face_culling(Renderer::FACE_CULLING_BACK); + + Vector2i render_tex_size = _render_tex->get_size(); + + _frame_buffer->bind(); + _frame_buffer->set_as_viewport(); + + r->camera_2d_projection_set_to_size(render_tex_size); + r->clear_screen(Color()); + + r->camera_3d_bind(); + r->camera_3d_projection_set_to_perspective(_frame_buffer->get_aspect()); + + render_immediate_3d(false); + + render_immediate(false); + + _render_tex->update(); + _frame_buffer->unbind(); + + _frame_buffer->reset_as_viewport(); + + r->camera_2d_projection_set_to_window(); + r->clear_screen(Color(1, 0, 0)); + r->draw_texture(_render_tex, Rect2(100, 100, render_tex_size.x, render_tex_size.y)); } } -void GameScene::render_immediate() { +void GameScene::render_immediate(bool clear_screen) { Renderer *r = Renderer::get_singleton(); - r->clear_screen(Color()); - r->camera_2d_projection_set_to_window(); + if (clear_screen) { + r->clear_screen(Color()); + r->camera_2d_projection_set_to_window(); + } r->draw_point(Vector2(15, 15)); r->draw_point(Vector2(18, 18), Color(1, 1, 0)); @@ -338,14 +367,16 @@ void GameScene::render_obj() { //TextRenderer::get_singleton()->font_print("test"); } -void GameScene::render_immediate_3d() { +void GameScene::render_immediate_3d(bool clear_screen) { Renderer *r = Renderer::get_singleton(); - r->clear_screen(Color()); - r->camera_2d_projection_set_to_window(); + 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()); + r->camera_3d_bind(); + r->camera_3d_projection_set_to_perspective(AppWindow::get_singleton()->get_aspect()); + } static float rotmi = 0; @@ -433,7 +464,7 @@ void GameScene::socket_thread_func(void *data) { int a = self->_server_socket->accept(client_socket); if (a != -1) { - printf("New connection! %d\n", a); + ERR_PRINT("New connection! " + itos(a)); client_sockets.push_back(client_socket); client_socket = new Socket(); @@ -665,6 +696,12 @@ GameScene::GameScene() { _mesh_utils_test_mi = memnew(MeshInstance3D()); _mesh_utils_test_mi->material = color_material; _mesh_utils_test_mi->mesh = _mesh_utils_test; + + _frame_buffer.instance(); + _frame_buffer->create(960, 540); + + _render_tex.instance(); + _render_tex->set_frame_buffer(_frame_buffer); } GameScene::~GameScene() { diff --git a/tools/merger/test_app/game_scene.h b/tools/merger/test_app/game_scene.h index 30437bf..aa008ec 100644 --- a/tools/merger/test_app/game_scene.h +++ b/tools/merger/test_app/game_scene.h @@ -11,15 +11,15 @@ class GameScene : public Scene { public: enum RenderTypes { - RENDER_TYPE_MAX = 13 + RENDER_TYPE_MAX = 14 }; virtual void input_event(const Ref &event); virtual void update(float delta); virtual void render(); - virtual void render_immediate(); + virtual void render_immediate(bool clear_screen = true); virtual void render_obj(); - virtual void render_immediate_3d(); + virtual void render_immediate_3d(bool clear_screen = true); void toggle_thread(); static void test_thread_func(void *d); @@ -70,6 +70,9 @@ public: Ref _mesh_utils_test; MeshInstance3D *_mesh_utils_test_mi; + Ref _frame_buffer; + Ref _render_tex; + //ColoredMaterial *cmaterial; };