voila un code que j´etudi ( je ne les pas ecrt moi meme):
/*************************************************
SDL Tutorial - Example 2
Andrew M. < andrew@textux.com>
- ***********************************************
- /
- include < stdlib.h>
- include < stdio.h>
- include < string.h>
- include < SDL.h>
void setpixel(SDL_Surface *screen, int x, int y, Uint8 r, Uint8 g, Uint8 b)
{
Uint8 *ubuff8;
Uint16 *ubuff16;
Uint32 *ubuff32;
Uint32 color;
char c1, c2, c3;
/* Lock the screen, if needed */
if(SDL_MUSTLOCK(screen)) {
if(SDL_LockSurface(screen) < 0)
return;
}
/* Get the color */
color = SDL_MapRGB( screen->format, r, g, b ) ;
/* How we draw the pixel depends on the bitdepth */
switch(screen->format->BytesPerPixel)
{
case 1:
ubuff8 = ( Uint8*) screen->pixels;
ubuff8 += ( y * screen->pitch) + x;
*ubuff8 = ( Uint8) color;
break;
case 2:
ubuff8 = ( Uint8*) screen->pixels;
ubuff8 += ( y * screen->pitch) + ( x*2);
ubuff16 = ( Uint16*) ubuff8;
*ubuff16 = ( Uint16) color;
break;
case 3:
ubuff8 = ( Uint8*) screen->pixels;
ubuff8 += ( y * screen->pitch) + ( x*3);
if(SDL_BYTEORDER == SDL_LIL_ENDIAN) {
c1 = ( color & 0xFF0000) > > 16;
c2 = ( color & 0x00FF00) > > 8;
c3 = ( color & 0x0000FF);
} else {
c3 = ( color & 0xFF0000) > > 16;
c2 = ( color & 0x00FF00) > > 8;
c1 = ( color & 0x0000FF);
}
ubuff8[0] = c3;
ubuff8[1] = c2;
ubuff8[2] = c1;
break;
case 4:
ubuff8 = ( Uint8*) screen->pixels;
ubuff8 += ( y*screen->pitch) + ( x*4);
ubuff32 = ( Uint32*)ubuff8;
*ubuff32 = color;
break;
default:
fprintf(stderr, " Error: Unknown bitdepth!\n");
}
/* Unlock the screen if needed */
if(SDL_MUSTLOCK(screen)) {
SDL_UnlockSurface(screen);
}
}
void DrawPicture(SDL_Surface* screen) {
/* Draw all the colors... */
int r = 255, g = 0, b = 255;
int x, y;
/* Uncomment the line bellow to see the effects of the ActiveState code */
/* printf("Drawing...\n"); */
for(x = 0; x < screen->w; x++ ) {
for( y = 0; y < screen->h; y++ ) {
setpixel(screen, x, y, x, y, 0);
}
}
SDL_Flip(screen);
}
int main(int argc, char* argv[])
{
/* Declare Variables */
SDL_Surface *screen;
SDL_Event event;
char *titlestring;
char *iconstring;
int exitkey = 0;
int active = 1;
/* Initialize SDL, exit if there is an error. */
if( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
fprintf(stderr, " Could not initialize SDL: %s\n",
SDL_GetError());
return -1;
}
/* When the program is through executing, call SDL_Quit */
atexit(SDL_Quit);
/* Grab a surface on the screen */
screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE|SDL_ANYFORMAT);
if( ! screen ) {
fprintf(stderr, " Couldn´t create a surface: %s\n",
SDL_GetError());
return -1;
}
SDL_WM_SetCaption("Hello World!!!!!!", " MAXIMIZE ME");
SDL_WM_GetCaption(&, &);
if(titlestring) {
printf("Got title string: %s\n", titlestring);
}
if(iconstring) {
printf("Got icon string: %s\n", iconstring);
}
/* Print Some info */
printf("Created SDL Surface: %x\n", screen);
printf("\t BPP \t\t : %d\n", screen->format->BytesPerPixel ) ;
printf("\t XRes \t\t :%d\n", screen->w ) ;
printf("\t YRes \t\t :%d\n", screen->h ) ;
while(!exitkey) {
if(active)
DrawPicture(screen);
while(SDL_PollEvent(&)) {
switch( event.type )
{
case SDL_QUIT:
exitkey = 1;
printf("Got quit event!\n");
break;
case SDL_KEYDOWN:
printf("Key hit - exiting!\n");
exitkey = 1;
break;
case SDL_ACTIVEEVENT:
printf("Activity Change!\n");
if ( event.active.state &
SDL_APPACTIVE ) {
if( event.active.gain )
active = 1;
else
active = 0;
}
break;
}
}
}
return 0;
}
il n´y a pas d´erruer et sa marche mais jaimmerai savoir a quoi serve les printf si on ne les vois pas afficher a l´ecran ? merci 