PDA

Voir la version complète : Ecran bleu.... pas blanc....


Oragon
26/09/2005, 21h38
Excusez moi, je n'arrive pas à voir ou est mon erreur ici.

j'ai bien verifié, je suis en 32bytes per pixels (surface->format->BytesPerPixel==4) et voici ma fonction pour afficher un pixel à l'écran :

void pxl(Uint16 x, Uint16 y, Uint16 color)
{
extern SDL_Surface *screen;

if(SDL_MUSTLOCK(screen)==1){SDL_LockSurface(screen);}

Uint32 *bufp;
bufp = (Uint32 *)screen->pixels + y*screen->pitch/4 + x;
*bufp = color;

if(SDL_MUSTLOCK(screen)==1){SDL_UnlockSurface(screen);}
}


ensuite je définit la variable color ainsi :
color=SDL_MapRGB(screen, 255, 255, 255);
donc je devrais avoir du blanc.

alors pourquoi l'apel :
pxl(100, 100, color);

m'affiche du bleu clair ?

j'ai pas trouvé mon erreur, quelqun pourrait-il me dire svp ? merchi ^^

Corkus
26/09/2005, 23h53
Moi personnellement je fais plutot comme ce qui est écrit dans la doc de SDL


int bpp = fenetre->format->BytesPerPixel;

Uint8 *p = (Uint8 *)fenetre->pixels
+ y * fenetre->pitch + x * bpp;

*(Uint32 *)p = color;

Oragon
28/09/2005, 18h05
Bien, hormis le fait que la tienne est plus généralisée alors que la mienne ne concerne que le 32bpp, je ne vois pas la différence.
Je tire mon code d'un exemple pris sur d'un tutoriel écrit par Sam Lantinga, Chef Programmeur chez Loki Entertainment Software.

voici le code total (plus généralisé en fait) :

#include <SDL_endian.h> /* Used for the endian-dependent 24 bpp mode */

void DrawPixel(SDL_Surface *screen, int x, int y,
Uint8 R, Uint8 G,
Uint8 B)
{
Uint32 color = SDL_MapRGB(screen->format, R, G, B);

if ( SDL_MUSTLOCK(screen) ) {
if ( SDL_LockSurface(screen) < 0 ) {
return;
}
}
switch (screen->format->BytesPerPixel) {
case 1: { /*On gère le mode 8bpp */
Uint8 *bufp;

bufp = (Uint8 *)screen->pixels + y*screen->pitch + x;
*bufp = color;
}
break;

case 2: { /* Certainement 15 ou 16 bpp */
Uint16 *bufp;

bufp = (Uint16 *)screen->pixels + y*screen->pitch/2 + x;
*bufp = color;
}
break;

case 3: { /* 24 bpp lent et généralement pas utilisé */
Uint8 *bufp;

bufp = (Uint8 *)screen->pixels + y*screen->pitch + x * 3;
if(SDL_BYTEORDER == SDL_LIL_ENDIAN) {
bufp[0] = color;
bufp[1] = color >> 8;
bufp[2] = color >> 16;
} else {
bufp[2] = color;
bufp[1] = color >> 8;
bufp[0] = color >> 16;
}
}
break;

case 4: { /* Probablement 32 bpp alors */
Uint32 *bufp;

bufp = (Uint32 *)screen->pixels + y*screen->pitch/4 + x;
*bufp = color;
}
break;
}
if ( SDL_MUSTLOCK(screen) ) {
SDL_UnlockSurface(screen);
}
SDL_UpdateRect(screen, x, y, 1, 1);
}

dans mon cas je m'interresse au 4° case :
Uint32 *bufp;

bufp = (Uint32 *)screen->pixels + y*screen->pitch/4 + x;
*bufp = color;


(note j'ai testé cet exemple en entier et il focntionne parfatement, donc ça vient de mon code).

Gravce à une capture d'écran et paint j'ai pu remarquer qle bleu qui apparait est du code R0 G255 B255. j'ai demandé à mon programme de tracer en R255 G0 B0 et l'ecran reste noir donc le rouge est absent, ce qui explique la couelur bleu vert au lieu du blanc).

Oragon
28/09/2005, 18h24
Ah non ! j'ai compris !
Suis-je bête !

Voici la définition de ma fonction :
void pxl(Uint16 x, Uint16 y, Uint16 color)

J'ai fais une erreur en déclarant color en Uint16 plutot qu'en Uint32. Conséquence, un octet en moins ==> une couleur en moins ^^.

Dsl pour mon topic qui n'a pas fait avancer la science ! mdr.