Merge pull request #126 from kichikuou/DrawGraph

Add two DrawGraph functions used in Daiteikoku
This commit is contained in:
Nunuhara Cabbage
2023-06-18 07:16:08 -07:00
committed by GitHub
4 changed files with 75 additions and 5 deletions
+2
View File
@@ -146,6 +146,7 @@ void gfx_copy_stretch_blend_amap_alpha(struct texture *dst, int dx, int dy, int
void gfx_copy_rot_zoom(Texture *dst, Texture *src, int sx, int sy, int w, int h, float rotate, float mag);
void gfx_copy_rot_zoom_amap(Texture *dst, Texture *src, int sx, int sy, int w, int h, float rotate, float mag);
void gfx_copy_rot_zoom_use_amap(Texture *dst, Texture *src, int sx, int sy, int w, int h, float rotate, float mag);
void gfx_copy_root_zoom2(Texture *dst, float cx, float cy, Texture *src, float scx, float scy, float rot, float mag);
void gfx_copy_reverse_LR(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h);
void gfx_copy_reverse_amap_LR(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h);
void gfx_copy_rotate_y(Texture *dst, Texture *front, Texture *back, int sx, int sy, int w, int h, float rot, float mag);
@@ -159,6 +160,7 @@ void gfx_copy_amap_height_blur(Texture *dst, int dx, int dy, Texture *src, int s
void gfx_copy_with_alpha_map(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h);
void gfx_fill_with_alpha(Texture *dst, int x, int y, int w, int h, int r, int g, int b, int a);
void gfx_copy_stretch_with_alpha_map(Texture *dst, int dx, int dy, int dw, int dh, Texture *src, int sx, int sy, int sw, int sh);
void gfx_copy_grayscale(Texture *dst, int dx, int dy, Texture *src, int sx, int sy, int w, int h);
void gfx_draw_glyph(Texture *dst, float dx, int dy, Texture *glyph, SDL_Color color, float scale_x, float bold_width);
void gfx_draw_glyph_to_pmap(Texture *dst, float dx, int dy, Texture *glyph, Rectangle glyph_pos, SDL_Color color, float scale_x);
void gfx_draw_glyph_to_amap(Texture *dst, float dx, int dy, Texture *glyph, Rectangle glyph_pos, float scale_x);
+25
View File
@@ -0,0 +1,25 @@
/* Copyright (C) 2023 kichikuou <KichikuouChrome@gmail.com>
*
* 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/>.
*/
uniform sampler2D tex;
in vec2 tex_coord;
out vec4 frag_color;
void main() {
float gray = dot(texture(tex, tex_coord).rgb, vec3(0.299, 0.587, 0.114));
frag_color = vec4(vec3(gray), 1);
}
+37
View File
@@ -64,6 +64,7 @@ static struct copy_shader copy_key_shader;
static struct copy_shader copy_alpha_key_shader;
static struct copy_shader copy_use_amap_under_shader;
static struct copy_shader copy_use_amap_border_shader;
static struct copy_shader copy_grayscale_shader;
static struct copy_shader blend_amap_color_shader;
static struct copy_shader blend_amap_alpha_bright_shader;
static struct copy_shader blend_use_amap_color_shader;
@@ -121,6 +122,9 @@ void gfx_draw_init(void)
// copy shader that only keeps fragments above a certain alpha threshold
load_copy_shader(&copy_use_amap_border_shader, "shaders/render.v.glsl", "shaders/copy_use_amap_border.f.glsl");
// copy shader with grayscale conversion
load_copy_shader(&copy_grayscale_shader, "shaders/render.v.glsl", "shaders/copy_grayscale.f.glsl");
// copy shader that sets source RGB to a constant
load_copy_shader(&blend_amap_color_shader, "shaders/render.v.glsl", "shaders/blend_amap_color.f.glsl");
@@ -770,6 +774,29 @@ void gfx_copy_rot_zoom_use_amap(Texture *dst, Texture *src, int sx, int sy, int
copy_rot_zoom(dst, src, sx, sy, w, h, rotate, mag, &hitbox_shader.s);
}
void gfx_copy_root_zoom2(Texture *dst, float cx, float cy, Texture *src, float scx, float scy, float rot, float mag)
{
gfx_fill_amap(dst, 0, 0, dst->w, dst->h, 0);
// 1. scale src vertices to texture size
// 2. translate so that center point of copy region is at origin
// 3. rotate
// 4. scale
// 4. tranlate to center point of dst texture
// (applied in reverse order)
mat4 mw_transform = GLM_MAT4_IDENTITY_INIT;
glm_translate(mw_transform, (vec3){ cx, cy, 0 });
glm_scale(mw_transform, (vec3){ mag, mag, 0 });
glm_rotate_z(mw_transform, -rot * (M_PI/180.0), mw_transform);
glm_translate(mw_transform, (vec3){ -scx, -scy, 0 });
glm_scale(mw_transform, (vec3){ src->w, src->h, 1 });
mat4 wv_transform = WV_TRANSFORM(dst->w, dst->h);
struct copy_data data = ROTATE_DATA(dst, 0, 0, src->w, src->h);
run_draw_shader(&hitbox_noblend_shader.s, dst, src, mw_transform, wv_transform, &data);
}
static void copy_rotate_y(Texture *dst, Texture *front, Texture *back, int sx, int sy, int w, int h, float rot, float mag, Shader *shader)
{
Texture *src = front;
@@ -1010,6 +1037,16 @@ void gfx_copy_stretch_with_alpha_map(Texture *dst, int dx, int dy, int dw, int d
restore_blend_mode();
}
void gfx_copy_grayscale(Texture *dst, int dx, int dy, 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_grayscale_shader.s, dst, src, &data);
restore_blend_mode();
}
// XXX: Not an actual DrawGraph function; used for rendering text
void gfx_draw_glyph(Texture *dst, float dx, int dy, Texture *glyph, SDL_Color color, float scale_x, float bold_width)
{
+11 -5
View File
@@ -298,7 +298,10 @@ static void DrawGraph_CopyRotZoomUseAMap(int dst, int src, int sx, int sy, int w
gfx_copy_rot_zoom_use_amap(DTEX(dst), STEX(src), sx, sy, w, h, rotate, mag);
}
//void DrawGraph_CopyRotZoom2Bilinear(int dst, float cx, float cy, int src, float scx, float scy, float rot, float mag);
static void DrawGraph_CopyRotZoom2Bilinear(int dst, float cx, float cy, int src, float scx, float scy, float rot, float mag)
{
gfx_copy_root_zoom2(DTEX(dst), cx, cy, STEX(src), scx, scy, rot, mag);
}
static void DrawGraph_CopyRotateY(int write, int dst, int src, int sx, int sy, int w, int h, float rot, float mag)
{
@@ -398,7 +401,10 @@ static void DrawGraph_CopyStretchWithAlphaMap(int dst, int dx, int dy, int dw, i
gfx_copy_stretch_with_alpha_map(DTEX(dst), dx, dy, dw, dh, STEX(src), sx, sy, sw, sh);
}
//void DrawGraph_CopyGrayscale(int nDest, int nDx, int nDy, int nSrc, int nSx, int nSy, int nWidth, int nHeight);
static void DrawGraph_CopyGrayscale(int dst, int dx, int dy, int src, int sx, int sy, int width, int height)
{
gfx_copy_grayscale(DTEX(dst), dx, dy, STEX(src), sx, sy, width, height);
}
HLL_LIBRARY(DrawGraph,
HLL_EXPORT(Copy, DrawGraph_Copy),
@@ -469,7 +475,7 @@ HLL_LIBRARY(DrawGraph,
HLL_EXPORT(CopyRotZoom, DrawGraph_CopyRotZoom),
HLL_EXPORT(CopyRotZoomAMap, DrawGraph_CopyRotZoomAMap),
HLL_EXPORT(CopyRotZoomUseAMap, DrawGraph_CopyRotZoomUseAMap),
//HLL_EXPORT(CopyRotZoom2Bilinear, DrawGraph_CopyRotZoom2Bilinear),
HLL_EXPORT(CopyRotZoom2Bilinear, DrawGraph_CopyRotZoom2Bilinear),
HLL_EXPORT(CopyRotateY, DrawGraph_CopyRotateY),
HLL_EXPORT(CopyRotateYUseAMap, DrawGraph_CopyRotateYUseAMap),
//HLL_EXPORT(CopyRotateYFixL, DrawGraph_CopyRotateYFixL),
@@ -500,6 +506,6 @@ HLL_LIBRARY(DrawGraph,
HLL_EXPORT(FillWithAlpha, DrawGraph_FillWithAlpha),
HLL_EXPORT(CopyStretchWithAlphaMap, DrawGraph_CopyStretchWithAlphaMap),
// NOTE: xsystem4 uses bilinear interpolation by default
HLL_EXPORT(CopyStretchBilinearWithAlphaMap, DrawGraph_CopyStretchWithAlphaMap)
//HLL_EXPORT(CopyGrayscale, DrawGraph_CopyGrayscale),
HLL_EXPORT(CopyStretchBilinearWithAlphaMap, DrawGraph_CopyStretchWithAlphaMap),
HLL_EXPORT(CopyGrayscale, DrawGraph_CopyGrayscale)
);