Skip to content

Drawing lines with alpha doesn't work #383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
smcameron opened this issue Mar 10, 2025 · 0 comments
Open

Drawing lines with alpha doesn't work #383

smcameron opened this issue Mar 10, 2025 · 0 comments

Comments

@smcameron
Copy link
Owner

smcameron commented Mar 10, 2025

You can attempt:

sng_set_foreground_alpha(RED, 0.5);
sng_current_draw_line(x1, y1, x2, y2);

But it will be drawn with full opacity.

The alpha value appears to be plumbed nearly all the way through, apart from this, in graph_dev_opengl.c:

void graph_dev_draw_line(float x1, float y1, float x2, float y2)
{
        make_room_in_vertex_buffer_2d(2);

        add_vertex_2d(x1, y1, sgc.hue, 255, GL_LINES);
        add_vertex_2d(x2, y2, sgc.hue, 255, GL_LINES);
}

I quickly attempted the patch below, but it didn't work. There might be a good reason (performance?) why it's not implemented.

$ stg show enable-drawing-lines-with-alpha
commit f46a48cd8bbe9952bb01f3179bbc5f2f796b3943
Author: Stephen M. Cameron <[email protected]>
Date:   Mon Mar 10 14:27:12 2025 -0400

    Enable drawing lines with alpha
    
    Signed-off-by: Stephen M. Cameron <[email protected]>

diff --git a/graph_dev_opengl.c b/graph_dev_opengl.c
index 64f63751..3ce82a4f 100644
--- a/graph_dev_opengl.c
+++ b/graph_dev_opengl.c
@@ -1204,6 +1204,8 @@ static void draw_vertex_buffer_2d(void)
                GLint start = 0;
                GLbyte mode = sgc.vertex_type_2d[0];
 
+               glEnable(GL_BLEND);
+               BLEND_FUNC(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
                for (i = 0; i < sgc.nvertex_2d; i++) {
                        if (mode != sgc.vertex_type_2d[i]) {
                                GLsizei count;
@@ -1235,6 +1237,7 @@ static void draw_vertex_buffer_2d(void)
                        glDrawArrays(mode, start, count);
                        /* printf("glDrawArrays 2 mode=%d start=%d count=%d\n", mode, start, i - start); */
                }
+               glDisable(GL_BLEND);
 
                sgc.nvertex_2d = 0;
 
@@ -3006,8 +3009,9 @@ void graph_dev_draw_line(float x1, float y1, float x2, float y2)
 {
        make_room_in_vertex_buffer_2d(2);
 
-       add_vertex_2d(x1, y1, sgc.hue, 255, GL_LINES);
-       add_vertex_2d(x2, y2, sgc.hue, 255, GL_LINES);
+       unsigned char alpha = (unsigned char) (sgc.alpha * 255.0);
+       add_vertex_2d(x1, y1, sgc.hue, alpha, GL_LINES);
+       add_vertex_2d(x2, y2, sgc.hue, alpha, GL_LINES);
 }
 
 void graph_dev_draw_rectangle(int filled, float x, float y, float width, float height)

I was trying to make the pull down menus fade away instead of just disappearing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant