I'm trying to draw Xiaolin Wu's line algorithm in SDL2, due to alpha channel problem i get nothing , i am drawing it in surface ,then creating texture from surface
i have tried
int SDL_SetTextureBlendMode(SDL_Texture* texture, SDL_BlendMode blendMode)
with all possible blending modes
getting color:(there's no error here i think)
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;
}
the main loop for this task is:
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)
}
i have tried it before with alpha channel =255 and it's work normally,but with varies alpha values no thing apear
Uint8 a= alpha*255;won't it overflowUint8withalpha>1? - kiran Biradar0<=alpha<=1but the values are correct ina,I have checked them ,we have varied values ofabut i can't show them, the problem i think is betweensurface and texture- user8821501tempSurface, texture, and how do you draw? Patching alpha doesn't look right at all, but to know correct way one have to see your pixel format. It is also unclear how it could be correct without alpha if you fill surface with constant colour - wouldn't it be just a solid rectangle? - keltar