I have a project in which i need to draw pixels on the screen with SDL. A bit of code has been supplied to me:
int render_screen(SDL_Surface* screen)
{
pixel pixel_white;
pixel_white.r = (Uint8)0xff;
pixel_white.g = (Uint8)0xff;
pixel_white.b = (Uint8)0xff;
pixel_white.alpha = (Uint8)128;
SDL_LockSurface(screen);
/*do your rendering here*/
/*----------------------*/
SDL_UnlockSurface(screen);
/*flip buffers*/
SDL_Flip(screen);
clear_screen(screen);
return 0;
}
Also this function:
void put_pixel(SDL_Surface* screen,int x,int y,pixel* p)
{
Uint32* p_screen = (Uint32*)screen->pixels;
p_screen += y*screen->w+x;
*p_screen = SDL_MapRGBA(screen->format,p->r,p->g,p->b,p->alpha);
}
There is a number of things in this code that i don't really understand. First, i assume the idea is that i should call the function put_pixel from within the render_screen function, but with what arguments? The put_pixel(SDL_Surface* screen,int x,int y,pixel* p) line seems complicated. If x and y is the function draw arguments, why are they then declared in the function indata? I should have to call put_pixel with the command put_pixel(something,x,y,something2). If i use say x=56 and y= 567, aren't they resetted to 0 when declared in the parentesis? And what should i put in something and something2 to make it work?