Sokol: Help! blend state operation for simple transparent png

Created on 12 Oct 2019  路  2Comments  路  Source: floooh/sokol

I give up! could someone be so kind and tell me how to set up sg pipeline to achieve a simple blending of transparent png as a texture quad ?

Jus like a simple glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) in opengl
https://learnopengl.com/img/advanced/blending_discard.png

Most helpful comment

This should do the trick (note the ".blend.enabled" flag:

sg_pipeline pip = sg_make_pipeline(&(sg_pipeline_desc){
    .layout = ...,
    .shader = ...,
    .blend = {
        .enabled = true,
        .src_factor_rgb = SG_BLENDFACTOR_SRC_ALPHA,
        .dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA
    },   
});

sokol_gfx.h uses separate blend state for RGB and Alpha (similar to OpenGL's glBlendFuncSeparate), so it may also be required to set the .src_factor_alpha and .dst_factor_alpha members in sg_pipeline_desc, but usually this isn't needed when rendering to the default framebuffer.

All 2 comments

This should do the trick (note the ".blend.enabled" flag:

sg_pipeline pip = sg_make_pipeline(&(sg_pipeline_desc){
    .layout = ...,
    .shader = ...,
    .blend = {
        .enabled = true,
        .src_factor_rgb = SG_BLENDFACTOR_SRC_ALPHA,
        .dst_factor_rgb = SG_BLENDFACTOR_ONE_MINUS_SRC_ALPHA
    },   
});

sokol_gfx.h uses separate blend state for RGB and Alpha (similar to OpenGL's glBlendFuncSeparate), so it may also be required to set the .src_factor_alpha and .dst_factor_alpha members in sg_pipeline_desc, but usually this isn't needed when rendering to the default framebuffer.

That did the trick :) Thank's Floooh, you're awesome!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ilar81 picture ilar81  路  7Comments

floooh picture floooh  路  7Comments

floooh picture floooh  路  3Comments

siavashserver picture siavashserver  路  6Comments

floooh picture floooh  路  3Comments