mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-10-07 22:38:11 +03:00
Remove flip_y field from texture
It was introduced to flip texture image rendered by DrawDungeon when presenting on the screen. In GALZOO this approach does not work because dungeon texture is also used as the source image of gfx functions. After this, DrawDungeon directly generates vertically flipped image, by tweaking the projection matrix.
This commit is contained in:
@@ -38,7 +38,6 @@ typedef struct texture {
|
||||
mat4 world_transform;
|
||||
int w, h;
|
||||
bool has_alpha;
|
||||
bool flip_y;
|
||||
int alpha_mod;
|
||||
enum draw_method draw_method;
|
||||
} Texture;
|
||||
|
||||
@@ -50,11 +50,8 @@ struct dungeon_context *dungeon_context_create(int surface)
|
||||
if (!sp)
|
||||
VM_ERROR("DrawDungeon.Init: invalid surface %d", surface);
|
||||
|
||||
// Dungeon scene will be rendered to this texture. Unlike other textures,
|
||||
// its (0,0) is at the bottom-left, so it needs to be flipped vertically
|
||||
// when displayed on the screen.
|
||||
// Dungeon scene will be rendered to this texture.
|
||||
struct texture *texture = sprite_get_texture(sp);
|
||||
texture->flip_y = true;
|
||||
|
||||
glGenRenderbuffers(1, &ctx->depth_buffer);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, ctx->depth_buffer);
|
||||
@@ -80,10 +77,6 @@ void dungeon_context_free(struct dungeon_context *ctx)
|
||||
glDeleteRenderbuffers(1, &ctx->depth_buffer);
|
||||
dungeon_map_free(ctx->map);
|
||||
|
||||
struct sact_sprite *sp = sact_get_sprite(ctx->surface);
|
||||
if (sp)
|
||||
sprite_get_texture(sp)->flip_y = false;
|
||||
|
||||
free(ctx);
|
||||
}
|
||||
|
||||
@@ -226,6 +219,13 @@ void dungeon_render(struct dungeon_context *ctx)
|
||||
model_view_matrix(&ctx->camera, view_transform);
|
||||
glm_perspective(M_PI / 3.0, (float)texture->w / texture->h, 0.5, 100.0, proj_transform);
|
||||
|
||||
// Tweak the projection transform so that the rendering result is vertically
|
||||
// flipped. If we render the scene normally, the resulting image will be
|
||||
// bottom-up (the first pixel is at the bottom-left), but we want a top-down
|
||||
// image (the first pixel is at the top-left).
|
||||
proj_transform[1][1] *= -1;
|
||||
glFrontFace(GL_CW);
|
||||
|
||||
int dgn_x = round(ctx->camera.pos[0] / 2.0);
|
||||
int dgn_y = round(ctx->camera.pos[1] / 2.0);
|
||||
int dgn_z = round(ctx->camera.pos[2] / -2.0);
|
||||
@@ -233,6 +233,7 @@ void dungeon_render(struct dungeon_context *ctx)
|
||||
struct dgn_cell **cells = dgn_get_visible_cells(ctx->dgn, dgn_x, dgn_y, dgn_z, &nr_cells);
|
||||
dungeon_renderer_render(ctx->renderer, cells, nr_cells, view_transform, proj_transform);
|
||||
|
||||
glFrontFace(GL_CCW);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
|
||||
|
||||
-10
@@ -234,7 +234,6 @@ static void main_surface_init(int w, int h)
|
||||
main_surface.w = w;
|
||||
main_surface.h = h;
|
||||
main_surface.has_alpha = true;
|
||||
main_surface.flip_y = false;
|
||||
main_surface.alpha_mod = 255;
|
||||
main_surface.draw_method = DRAW_METHOD_NORMAL;
|
||||
|
||||
@@ -371,10 +370,6 @@ void gfx_render_texture(struct texture *t, Rectangle *r)
|
||||
|
||||
t->world_transform[3][0] = r ? r->x : 0;
|
||||
t->world_transform[3][1] = r ? r->y : 0;
|
||||
if (t->flip_y) {
|
||||
t->world_transform[3][1] += t->world_transform[1][1];
|
||||
t->world_transform[1][1] *= -1;
|
||||
}
|
||||
|
||||
struct gfx_render_job job = {
|
||||
.shader = &default_shader.s,
|
||||
@@ -385,10 +380,6 @@ void gfx_render_texture(struct texture *t, Rectangle *r)
|
||||
};
|
||||
gfx_render(&job);
|
||||
|
||||
if (t->flip_y) {
|
||||
t->world_transform[1][1] *= -1;
|
||||
t->world_transform[3][1] -= t->world_transform[1][1];
|
||||
}
|
||||
if (t->draw_method != DRAW_METHOD_NORMAL || t->alpha_mod != 255)
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
|
||||
}
|
||||
@@ -412,7 +403,6 @@ static void init_texture(struct texture *t, int w, int h)
|
||||
t->h = h;
|
||||
|
||||
t->has_alpha = true;
|
||||
t->flip_y = false;
|
||||
t->alpha_mod = 255;
|
||||
t->draw_method = DRAW_METHOD_NORMAL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user