CONNEXION
  • RetourJeux
    • Sorties
    • Hit Parade
    • Les + populaires
    • Les + attendus
    • Soluces
    • Tous les Jeux
    • Gaming
  • RetourActu Gaming
    • News
    • Astuces
    • Tests
    • Previews
    • Toute l'actu gaming
  • RetourBons plans
    • Bons plans
    • Bons plans Smartphone
    • Bons plans Hardware
    • Bons plans Image et Son
    • Bons plans Amazon
    • Bons plans Cdiscount
    • Bons plans Decathlon
    • Bons plans Fnac
    • Tous les Bons plans
  • RetourJVTech
    • Actus High-Tech
    • Intelligence Artificielle
    • Smartphones
    • Mobilité urbaine
    • Hardware
    • Image et son
    • Tutoriels
    • Tests produits High-Tech
    • Guides d'achat High-Tech
    • JVTech
  • RetourCulture
    • Actus Culture
    • Culture
  • RetourVidéos
    • A la une
    • Gaming Live
    • Vidéos Tests
    • Vidéos Previews
    • Gameplay
    • Trailers
    • Chroniques
    • Replay Web TV
    • Toutes les vidéos
  • RetourForums
    • Hardware PC
    • PS5
    • Switch 2
    • Xbox Series
    • Switch
    • Pokemon pocket
    • FC 25 Ultimate Team
    • League of Legends
    • Tous les Forums
  • PC
  • PS5
  • Xbox Series
  • Switch 2
  • PS4
  • One
  • Switch
  • iOS
  • Android
  • MMO
  • RPG
  • FPS
En ce moment Genshin Impact Valhalla Breath of the wild Animal Crossing GTA 5 Red dead 2
Liste des sujets

Question SDL (sur printf)

lord_kalipsy
lord_kalipsy
Niveau 10
25 octobre 2003 à 05:40:46

voila un code que j´etudi ( je ne les pas ecrt moi meme):

/*************************************************

    • *

SDL Tutorial - Example 2
Andrew M. < andrew@textux.com>

    • ***********************************************
    • /
  1. include < stdlib.h>
  2. include < stdio.h>
  3. include < string.h>
  1. 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 :)

JeanYvesYves
JeanYvesYves
Niveau 10
25 octobre 2003 à 16:15:44

c´est parce que SDL est portable, et que le mec qui a fait ce programme l´a fait sous Linux
et sous Linux, tu as toujours une console comme sortie STDOUT --> tu vois les printf dans une autre fenetre.

lord_kalipsy
lord_kalipsy
Niveau 10
25 octobre 2003 à 16:59:18

ha ok . .. mais y a t´il une maniere pour que je puissent les voir ? puis-je etudier ses tutoriels meme sur windows ?

JeanYvesYves
JeanYvesYves
Niveau 10
25 octobre 2003 à 17:28:13

void debug(char* s)
{
FILE* F=fopen("debu.txt","a);
fprintf(F,s);
fclose(F);
}

des que tu feras :

debug("plouf");

ça y écrira dans un fichier....

fantometteninja
fantometteninja
Niveau 6
26 octobre 2003 à 14:41:42

sous windows la sdl redirige par defaut stdout vers stdout.txt et stderr vers stderr.txt ( si mes souvenirs sont bons, ca fait un petit moment que je ne suis pas retourne sous windows).
apres libre a vous de recompiler la sdl pour changer cela...

lord_kalipsy
lord_kalipsy
Niveau 10
26 octobre 2003 à 18:33:32

merci a vous deux :D maIs JYY je cmprend pas de quoi tu parle ( et oui encore un NOOB ; ) ) fantometteninja maric je vien de remarker :)

JeanYvesYves
JeanYvesYves
Niveau 10
26 octobre 2003 à 18:35:48

Arf ! je ne savais pas que STDOUT était automatiquement redirigé vers un fichier :)

ce que j´ai marqué, c´est pour le faire manuellement :
avec la fonction que je te proposais ça redirigeait vers le fichier " debug.txt"

Sous forums
  • Aide à l'achat Mac
  • Internet
  • Macintosh
  • Création de sites web
  • Création de Jeux
  • Linux
  • Programmation
  • Steam Deck
  • Hardware
La vidéo du moment