在 sdl 中绘制不同的 alpha 值

drawing with varies alpha values in sdl

我正在尝试在 SDL2 中绘制 Xiaolin Wu 的线算法,由于 alpha 通道问题我什么也没得到,我在表面上绘制它,然后从表面创建纹理

我试过了 int SDL_SetTextureBlendMode(SDL_Texture* texture, SDL_BlendMode blendMode) 具有所有可能的混合模式

上色:(我认为这里没有错误)

void LINE_PlotPoint(SDL_Surface * surface,int x,int y, double alpha)
{
    Uint32 *pixels = (Uint32 *)surface->pixels;
    Uint32 pixel=SYS_GetForegroundColor();

    Uint8 a= alpha*255;

    pixel&=~amask;
    pixel |= a;

    pixels[ ( y * surface->w ) + x ] =pixel;
}

这个任务的主循环是:

if(event.type==SDL_MOUSEMOTION)
{
    SDL_GetMouseState(&i,&j);
    i-=grect.x;
    j-=grect.y;
    TOOL_DrawLine(tempSurface,x,y,i,j,1);//Xiaolin Wu's line algorithm

    if(tempTexture)
    {
        SDL_DestroyTexture(tempTexture);
    }

    tempTexture=TOOL_CreateLineTexture(tempSurface,&srect,&drect);//create texture from surface and calculating rect(src & dest)
    if(tempTexture==NULL)
    {
        puts("error");
    }
    SDL_SetTextureBlendMode(tempTexture,SDL_BLENDMODE_BLEND);


    SDL_FillRect(tempSurface,NULL,NULL);//delete pixel from surface (no need for it)

    }

我之前尝试过使用 alpha 通道 =255 并且它工作正常,但是随着不同的 alpha 值没有出现任何东西

现在我找到问题了

只是我忘了将 alpha 值移动到正确的位置

pixel&=~amask;
pixel |= a << ashift;