#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
* This source code was highlighted with Source Code Highlighter .
- class Color {
- public :
- Color (Uint8 red, Uint8 green, Uint8 blue): R (red), G (green), B (blue) {};
- double R, G, B;
- };
* This source code was highlighted with Source Code Highlighter .
- class Vector_2D {
- public :
- Vector_2D ( void ): x_coord (0), y_coord (0) {};
- Vector_2D ( int X, int Y);
- Vector_2D operator - ( const Vector_2D &) const ;
- Vector_2D operator + ( const Vector_2D &) const ;
- Vector_2D operator * ( const Vector_2D &) const ;
- int x_coord, y_coord;
- };
- Vector_2D :: Vector_2D ( int X, int Y) {
- x_coord = X;
- y_coord = Y;
- }
- Vector_2D Vector_2D :: operator - ( const Vector_2D & rhs) const
- {
- Vector_2D Point;
- Point.x_coord = ( this -> x_coord - rhs.x_coord);
- Point.y_coord = ( this -> y_coord - rhs.y_coord);
- return point;
- }
- Vector_2D Vector_2D :: operator + ( const Vector_2D & rhs) const
- {
- Vector_2D Point;
- Point.x_coord = ( this -> x_coord + rhs.x_coord);
- Point.y_coord = ( this -> y_coord + rhs.y_coord);
- return point;
- }
- Vector_2D Vector_2D :: operator * ( const Vector_2D & rhs) const
- {
- Vector_2D Point;
- Point.x_coord = ( this -> x_coord * rhs.x_coord);
- Point.y_coord = ( this -> y_coord * rhs.y_coord);
- return point;
- }
* This source code was highlighted with Source Code Highlighter .
- #include <iostream>
- #include "SDL_Interface.cpp"
- int main ( int argc, char ** argv) {
- // Declare the surface on which we will draw with the screen size and color depth
- SDL_Interface * mySDL = new SDL_Interface (800, 600, 32);
- // Determine the colors
- Color blue (0x00, 0x00, 0xff);
- Color red (0xff, 0x00, 0x00);
- Color green (0x00, 0xff, 0x00);
- mySDL-> screen_lock (); // Lock Screen Before Drawing
- / * We draw by flooding the screen in three colors * /
- for ( int x = 0; x <mySDL-> w (); x ++) {
- for ( int y = 0; y <mySDL-> h (); y ++) {
- if (y <(mySDL-> h ()) / 3)
- mySDL-> putpixel (Vector_2D (x, y), green);
- else if (y <((mySDL-> h ()) / 3) * 2)
- mySDL-> putpixel (Vector_2D (x, y), red);
- else
- mySDL-> putpixel (Vector_2D (x, y), blue);
- }
- }
- mySDL-> screen_unlock ();
- mySDL-> screen_update (0,0,0,0);
- if (mySDL-> key_wait (SDLK_ESCAPE)) exit (0); // Exit if ESC
- return 0;
- }
Source: https://habr.com/ru/post/100842/
All Articles