sdl

时间:2019-06-25 10:46:10

标签: c++ c sdl sdl-2

我正在尝试在SDL2中绘制Wu Xiaolin的线算法,由于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值不一样

1 个答案:

答案 0 :(得分:0)

现在我已经找到了问题

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

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