art_dupond je suis neuneu... oui oui !! | ben screen est de type SDL_Surface je mets tout le code au cas ou...
source de l'exemple : http://cone3d.gamedev.net/cgi-bin/ [...] xsdl/index
le résultat :
Code :
- #include <SDL/SDL.h>
- #include <stdio.h>
- #include <stdlib.h>
- void DrawPixel(SDL_Surface *screen, int x, int y, Uint8 R, Uint8 G, Uint8 B);
- void Slock(SDL_Surface *screen);
- void Sulock(SDL_Surface *screen);
- void DrawScene(SDL_Surface *screen);
- int main(int argc, char **argv) {
- if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)<0) {
- printf("initialisation caca! Erreur : %s\n", SDL_GetError());
- return 1;
- }
- Uint32 init = SDL_WasInit(SDL_INIT_AUDIO);
- Uint8 sound;
- if(init & SDL_INIT_AUDIO)
- sound = 1;
- else
- sound = 0;
- atexit(SDL_Quit);
-
- SDL_Surface * screen;
- screen = SDL_SetVideoMode(640,480,32,SDL_HWSURFACE|SDL_DOUBLEBUF);
- if(screen == NULL) {
- printf("pas réussi à mettre 640x480x32. Erreur : %s\n", SDL_GetError());
- return 1;
- }
- int done = 0;
-
- while(done == 0)
- {
- SDL_Event event;
- while(SDL_PollEvent(&event))
- {
- if(event.type == SDL_QUIT)
- done = 1;
- if(event.type == SDL_KEYDOWN) {
- if(event.key.keysym.sym = SDLK_ESCAPE) {
- done = 1;
- }
- }
-
- DrawScene(screen);
- }
- }
-
- return 0;
- }
- void DrawScene(SDL_Surface *screen) {
- int x;
- int y;
- Slock(screen);
- for(x=0;x<640;x++) {
- for(y=0;y<480;y++) {
- DrawPixel(screen,x,y,y/2,y/2,x/3);
- }
- }
- Sulock(screen);
- SDL_Flip(screen); // met ce qui est dans le buffer sur l'écran
- }
- void DrawPixel(SDL_Surface *screen, int x, int y, Uint8 R, Uint8 G, Uint8 B) {
- Uint32 color = SDL_MapRGB(screen->format, R, G, B);
- switch (screen->format->BytesPerPixel) {
- case 1: {// si 8 bpp
- Uint8 *bufp;
- bufp = (Uint8 *)screen->pixels + y*screen->pitch + x;
- *bufp = color;
- }
- break;
- case 2: {// 15 ou 16 bpp
- Uint16 *bufp;
- bufp = (Uint16 *)screen->pixels + y*screen->pitch/2 + x;
- *bufp = color;
- }
- break;
- case 3: { // slow 24 bpp mode
- 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: {
- Uint32 *bufp;
- bufp = (Uint32 *)screen->pixels + y*screen->pitch/4 +x;
- *bufp = color;
- }
- break;
- }
- }
- void Slock(SDL_Surface *screen) { // vérifiage de savoir si on doit lock screen
- if(SDL_MUSTLOCK(screen))
- if(SDL_LockSurface(screen)<0)
- return;
- }
- void Sulock(SDL_Surface *screen) {
- if(SDL_MUSTLOCK(screen))
- SDL_UnlockSurface(screen);
- }
|
Message édité par art_dupond le 30-10-2003 à 11:00:02 ---------------
oui oui
|