c++/SDL2 : beta


for use it in code:

function use by convertData()

void setPixel(SDL_Surface *surface, int x, int y, SDL_Color col)
{    Uint32 pixel = SDL_MapRGBA(surface->format, col.r, col.g, col.b, col.a);    Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel;    if(surface->format->BytesPerPixel == 3)    {        if(SDL_BYTEORDER == SDL_BIG_ENDIAN)        {            p[0] = (pixel >> 16) & 0xff;            p[1] = (pixel >> 8) & 0xff;            p[2] = pixel & 0xff;        }        else        {            p[0] = pixel & 0xff;            p[1] = (pixel >> 8) & 0xff;            p[2] = (pixel >> 16) & 0xff;        }    }    if(surface->format->BytesPerPixel == 4) *(Uint32 *)p = pixel;
}

function for make SDL_Texture of pixel data (tab = image_name without extension):

SDL_Texture* convertData(vector<vector<SDL_Color>> tab)
{    SDL_Texture *texture;    // ne peut generer que des surface noire    SDL_Surface *mysurface = SDL_CreateRGBSurface(0, tab.size(), tab[0].size(), 32,0,0,0,0);    if(mysurface == nullptr) Test("null");    SDL_LockSurface(mysurface); /*On bloque la surface*/    for(unsigned int i=0;i< tab.size();i++)     {        for(unsigned int j=0;j< tab[0].size();j++)         {            if(tab[i][j].a != 0)                setPixel(mysurface,i,j, {tab[i][j].r,tab[i][j].g,tab[i][j].b,tab[i][j].a});            else setPixel(mysurface,i,j,{1,1,1,0});        }    }    Uint32 colorkey = SDL_MapRGBA( mysurface->format,1,1,1,0);//pixel a suprimer    SDL_SetColorKey(mysurface, SDL_TRUE,colorkey);// supression pixel    SDL_UnlockSurface(mysurface); /*On libère la surface, elle peut être utilisée*/    texture = SDL_CreateTextureFromSurface(renderer,mysurface);    SDL_FreeSurface(mysurface);        return texture;
}

Files

img_compiler_c++/SDL.zip 1 MB
Oct 24, 2020

Get Cimg

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.