- Código: Seleccionar todo
- #include <iostream>
 #include <SDL/SDL.h>
 using namespace std;
 long long db(int n) {
 if (n > 0) return db(n/2)*10 + n%2;
 return 0;
 }
 void putpixel(SDL_Surface *surface, int x, int y, SDL_Color color) {
 //SDL_LockSurface(surface);
 Uint32 col = SDL_MapRGB(surface->format, color.r, color.g, color.b);
 cerr << "col: " << db(col) << endl;
 Uint8 *buffer;
 buffer = (Uint8*) surface->pixels;
 buffer += surface->pitch*y;
 buffer += surface->format->BytesPerPixel*x;
 memcpy(buffer, &col, surface->format->BytesPerPixel);
 //*buffer = col;
 //SDL_UnlockSurface(surface);
 }
 int main() {
 SDL_Init(SDL_INIT_VIDEO);
 SDL_Surface *screen = SDL_SetVideoMode(640, 400, 16, SDL_HWSURFACE);
 cerr << "Bitspp: " << screen->format->BitsPerPixel*1 << endl;
 SDL_Color color;
 color.r = 255;
 color.g = 0;
 color.b = 0;
 for (int i = 0; i < 15; ++i) {
 putpixel(screen, i, i, color);
 putpixel(screen, i, i+1, color);
 putpixel(screen, i, i+2, color);
 }
 SDL_Event event;
 bool salir;
 while(not salir) {
 while (SDL_PollEvent(&event)) {
 if (event.type == SDL_KEYDOWN) salir = true;
 else SDL_Flip(screen);
 }
 }
 SDL_Quit();
 }
Saludos y gracias de antemano y a RCAF por el manual que me ha ayudado en mis primeros pasos con píxeles.


