Implement DrawGraph.CopyColorReverse

Just a copy operation that inverts colors. Used in Rance VI Sonogo.
This commit is contained in:
Nunuhara Cabbage
2021-04-22 19:20:12 -07:00
parent 1aaa7eec5a
commit f282c69266
4 changed files with 48 additions and 2 deletions
+1
View File
@@ -99,6 +99,7 @@ void gfx_copy(struct texture *dst, int dx, int dy, struct texture *src, int sx,
void gfx_copy_bright(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h, int rate);
void gfx_copy_amap(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h);
void gfx_copy_sprite(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h, SDL_Color color);
void gfx_copy_color_reverse(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h);
void gfx_copy_use_amap_under(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h, int threshold);
void gfx_copy_use_amap_border(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h, int threshold);
void gfx_copy_amap_max(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h);
+27
View File
@@ -0,0 +1,27 @@
/* Copyright (C) 2019 Nunuhara Cabbage <nunuhara@haniwa.technology>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://gnu.org/licenses/>.
*/
#version 140
uniform sampler2D tex;
in vec2 tex_coord;
out vec4 frag_color;
void main() {
vec4 texel = texture(tex, tex_coord);
frag_color = vec4(1.0 - texel.r, 1.0 - texel.g, 1.0 - texel.b, 1);
}
+14
View File
@@ -55,6 +55,7 @@ struct copy_data {
STRETCH_DATA(_dx, _dy, _w, _h, _sx, _sy, _w, _h)
static struct copy_shader copy_shader;
static struct copy_shader copy_color_reverse_shader;
static struct copy_shader copy_key_shader;
static struct copy_shader copy_use_amap_under_shader;
static struct copy_shader copy_use_amap_border_shader;
@@ -90,6 +91,9 @@ void gfx_draw_init(void)
// generic copy shader; discards fragments outside of a given rectangle
load_copy_shader(&copy_shader, "shaders/render.v.glsl", "shaders/copy.f.glsl");
// copy shader which inverts colors
load_copy_shader(&copy_color_reverse_shader, "shaders/render.v.glsl", "shaders/copy_color_reverse.f.glsl");
// copy shader which also discards fragments matching a color key
load_copy_shader(&copy_key_shader, "shaders/render.v.glsl", "shaders/copy_key.f.glsl");
@@ -206,6 +210,16 @@ void gfx_copy_sprite(Texture *dst, int dx, int dy, Texture *src, int sx, int sy,
restore_blend_mode();
}
void gfx_copy_color_reverse(struct texture *dst, int dx, int dy, struct texture *src, int sx, int sy, int w, int h)
{
glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ZERO, GL_ONE);
struct copy_data data = COPY_DATA(dx, dy, sx, sy, w, h);
run_copy_shader(&copy_color_reverse_shader.s, dst, src, &data);
restore_blend_mode();
}
void gfx_copy_use_amap_under(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h, int threshold)
{
glBlendFuncSeparate(GL_ONE, GL_ZERO, GL_ZERO, GL_ONE);
+6 -2
View File
@@ -42,6 +42,11 @@ static void DrawGraph_CopySprite(int dst, int dx, int dy, int src, int sx, int s
gfx_copy_sprite(DTEX(dst), dx, dy, STEX(src), sx, sy, w, h, COLOR(r, g, b, 0));
}
static void DrawGraph_CopyColorReverse(int dst, int dx, int dy, int src, int sx, int sy, int w, int h)
{
gfx_copy_color_reverse(DTEX(dst), dx, dy, STEX(src), sx, sy, w, h);
}
static void DrawGraph_CopyUseAMapUnder(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int alpha)
{
gfx_copy_use_amap_under(DTEX(dst), dx, dy, STEX(src), sx, sy, w, h, alpha);
@@ -166,7 +171,6 @@ static void DrawGraph_SetFontName(struct string *text)
gfx_set_font_name(text->text);
}
//void DrawGraph_CopyColorReverse(int dst, int dx, int dy, int src, int sx, int sy, int w, int h);
//void DrawGraph_BlendSrcBright(int dst, int dx, int dy, int src, int sx, int sy, int w, int h, int alpha, int rate);
//void DrawGraph_BlendAddSatur(int dst, int dx, int dy, int src, int sx, int sy, int w, int h);
//void DrawGraph_BlendAMapSrcOnly(int dst, int dx, int dy, int src, int sx, int sy, int w, int h);
@@ -225,7 +229,7 @@ HLL_LIBRARY(DrawGraph,
HLL_EXPORT(CopyBright, DrawGraph_CopyBright),
HLL_EXPORT(CopyAMap, DrawGraph_CopyAMap),
HLL_EXPORT(CopySprite, DrawGraph_CopySprite),
//HLL_EXPORT(CopyColorReverse, DrawGraph_CopyColorReverse),
HLL_EXPORT(CopyColorReverse, DrawGraph_CopyColorReverse),
HLL_EXPORT(CopyUseAMapUnder, DrawGraph_CopyUseAMapUnder),
HLL_EXPORT(CopyUseAMapBorder, DrawGraph_CopyUseAMapBorder),
HLL_EXPORT(CopyAMapMax, DrawGraph_CopyAMapMax),