mirror of
https://github.com/nunuhara/xsystem4.git
synced 2026-10-01 03:18:09 +03:00
Merge pull request #53 from kichikuou/fillangle
Implement FillAngle HLL
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
/* Copyright (C) 2022 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 vec2 center;
|
||||
uniform float start_angle;
|
||||
uniform float angle;
|
||||
uniform vec4 color;
|
||||
|
||||
const float PI = 3.14159265358979323846;
|
||||
|
||||
in vec2 tex_coord;
|
||||
out vec4 frag_color;
|
||||
|
||||
void main() {
|
||||
vec2 p = tex_coord - center;
|
||||
float a = atan(p.y, p.x);
|
||||
a = mod(a - start_angle, 2 * PI);
|
||||
if (a > angle)
|
||||
discard;
|
||||
frag_color = color;
|
||||
}
|
||||
@@ -316,6 +316,7 @@ extern struct static_library lib_DrawSimpleText;
|
||||
extern struct static_library lib_File;
|
||||
extern struct static_library lib_File2;
|
||||
extern struct static_library lib_FileOperation;
|
||||
extern struct static_library lib_FillAngle;
|
||||
extern struct static_library lib_GoatGUIEngine;
|
||||
extern struct static_library lib_Gpx2Plus;
|
||||
extern struct static_library lib_GUIEngine;
|
||||
@@ -380,6 +381,7 @@ static struct static_library *static_libraries[] = {
|
||||
&lib_File,
|
||||
&lib_File2,
|
||||
&lib_FileOperation,
|
||||
&lib_FillAngle,
|
||||
&lib_GoatGUIEngine,
|
||||
&lib_Gpx2Plus,
|
||||
&lib_GUIEngine,
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/* Copyright (C) 2022 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/>.
|
||||
*/
|
||||
|
||||
#include <cglm/cglm.h>
|
||||
|
||||
#include "gfx/gfx.h"
|
||||
#include "hll.h"
|
||||
#include "sact.h"
|
||||
|
||||
struct fill_angele_shader {
|
||||
struct shader s;
|
||||
GLint center;
|
||||
GLint start_angle;
|
||||
GLint angle;
|
||||
GLint color;
|
||||
};
|
||||
static struct fill_angele_shader shader;
|
||||
|
||||
static void load_shader(void)
|
||||
{
|
||||
gfx_load_shader(&shader.s, "shaders/render.v.glsl", "shaders/fill_angle.f.glsl");
|
||||
shader.center = glGetUniformLocation(shader.s.program, "center");
|
||||
shader.start_angle = glGetUniformLocation(shader.s.program, "start_angle");
|
||||
shader.angle = glGetUniformLocation(shader.s.program, "angle");
|
||||
shader.color = glGetUniformLocation(shader.s.program, "color");
|
||||
}
|
||||
|
||||
static bool FillAngle_FillAngleAMAP(int sprite, int center_x, int center_y, int start_angle, int angle, int alpha)
|
||||
{
|
||||
struct sact_sprite *sp = sact_try_get_sprite(sprite);
|
||||
if (!sp)
|
||||
return false;
|
||||
struct texture *dst = sprite_get_texture(sp);
|
||||
float w = dst->w;
|
||||
float h = dst->h;
|
||||
|
||||
if (!shader.s.program)
|
||||
load_shader();
|
||||
glUseProgram(shader.s.program);
|
||||
glUniform2f(shader.center, center_x / w, center_y / h);
|
||||
glUniform1f(shader.start_angle, glm_rad(start_angle));
|
||||
glUniform1f(shader.angle, glm_rad(angle));
|
||||
glUniform4f(shader.color, 0, 0, 0, alpha / 255.0);
|
||||
glUseProgram(0);
|
||||
|
||||
mat4 mw_transform = MAT4(
|
||||
w, 0, 0, 0,
|
||||
0, h, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1);
|
||||
mat4 wv_transform = WV_TRANSFORM(dst->w, dst->h);
|
||||
GLuint fbo = gfx_set_framebuffer(GL_DRAW_FRAMEBUFFER, dst, 0, 0, dst->w, dst->h);
|
||||
|
||||
struct gfx_render_job job = {
|
||||
.shader = &shader.s,
|
||||
.texture = 0,
|
||||
.world_transform = mw_transform[0],
|
||||
.view_transform = wv_transform[0],
|
||||
.data = NULL
|
||||
};
|
||||
glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_ONE, GL_ZERO);
|
||||
gfx_render(&job);
|
||||
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);
|
||||
|
||||
gfx_reset_framebuffer(GL_DRAW_FRAMEBUFFER, fbo);
|
||||
return true;
|
||||
}
|
||||
|
||||
HLL_LIBRARY(FillAngle,
|
||||
HLL_EXPORT(FillAngleAMAP, FillAngle_FillAngleAMAP)
|
||||
);
|
||||
@@ -80,6 +80,7 @@ xsystem4 = [version_h,
|
||||
'hll/File.c',
|
||||
'hll/File2.c',
|
||||
'hll/FileOperation.c',
|
||||
'hll/FillAngle.c',
|
||||
'hll/GoatGUIEngine.c',
|
||||
'hll/Gpx2Plus.c',
|
||||
'hll/GUIEngine.c',
|
||||
|
||||
Reference in New Issue
Block a user