Updated the amalgamated GameScene. Also small tweaks.

This commit is contained in:
Relintai 2024-01-19 22:10:05 +01:00
parent 4d25ba99a6
commit c28f3c7fe0
3 changed files with 54 additions and 14 deletions

View File

@ -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();

View File

@ -1,6 +1,6 @@
#include "game_scene.h"
#include <cstdio>
#include "sfw.h"
void GameScene::input_event(const Ref<InputEvent> &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();
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();
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());
}
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() {

View File

@ -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<InputEvent> &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> _mesh_utils_test;
MeshInstance3D *_mesh_utils_test_mi;
Ref<FrameBuffer> _frame_buffer;
Ref<RenderTexture> _render_tex;
//ColoredMaterial *cmaterial;
};