1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| #include <SDL.h>
SDL_Window *mWindow;
SDL_Surface *mMainSurface;
const int Win_W = 1024 ;
const int Win_H = 768;
typedef struct {
Uint8 r;
Uint8 g;
Uint8 b;
Uint8 a;
} pixel;
void put_pixel(SDL_Surface* surf, int x,int y,pixel* p)
{
Uint32* p_screen = (Uint32*)surf->pixels;
p_screen += y*surf->w+x;
*p_screen = SDL_MapRGBA(surf->format,p->r,p->g,p->b,p->a);
}
int main( int argc, char* args[] )
{
pixel mpixel;
mpixel.r = (Uint8)0xff;
mpixel.g = (Uint8)0xff;
mpixel.b = (Uint8)0xff;
mpixel.a = (Uint8)128;
if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )
{
return -1;
}
else
{
mWindow = SDL_CreateWindow( "test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, Win_W, Win_H, SDL_WINDOW_SHOWN );
if( mWindow == NULL )
{
return -2;
}
else
{
mMainSurface = SDL_GetWindowSurface( mWindow );
while (1)
{
SDL_LockSurface(mMainSurface);
for(int ix = 0; ix < Win_W; ix++)
for(int iy = 0; iy < Win_H; iy++)
put_pixel(mMainSurface, ix, iy, &mpixel);
SDL_UnlockSurface(mMainSurface);
SDL_UpdateWindowSurface( mWindow );
}
}
}
return 0;
} |
Partager