SDLでの2Dレンダリング

画像 長い間、私はこの記事を書きたくはありませんでした-資料の提出方法を考えました。 しかし、今日では、スターの開発が成功し、SDLに関する記事が完成していることがわかります。 ただし、これは単なるドラフトです。 将来的には、この記事をいくつかの個別の記事に分割します-十分な資料とコードがあります。



この古い、しかし非常に優れたクロスプラットフォームグラフィックライブラリに精通していない人のために、 この投稿を読むことをお勧めします。

ライブラリは公式サイトからダウンロードできますが、難しいことではないと思います。 単に広大であることが判明しているため、詳細は説明しません。詳細については、 こちらを参照してください



今日は、画面を3色で塗りつぶすプログラムをゼロから作成します。



それでは始めましょう:

3つの補助クラスとプログラムの主要部分があり、画面上のピクセルを任意の色で「明るく」します。 ここでも、読者が関心を持つ非常に基本的なことだけを説明します。



まず、ライブラリを直接ロードし、そのすべての機能を操作するクラスを宣言する必要があります。 (一度)画面ロックなど、ピクセルと「描画」する表面を操作します。 このクラスにあるコードの主要部分は、ライブラリのヘルプファイルにあります。 それがどのように機能し、なぜピクセルが点灯するかはわかりますが、それを調べることは依然として有用でしょう、私には思えますが、これは記事の範囲を超えています。



SDL_Interface.cpp

#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 .



  1. #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 .



  2. #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 .



  3. #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 .



  4. #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 .



  5. #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 .



  6. #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 .



  7. #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 .



  8. #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 .



  9. #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 .



  10. #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 .



  11. #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 .



  12. #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 .



  13. #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 .



  14. #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 .



  15. #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 .



  16. #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 .



  17. #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 .



  18. #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 .



  19. #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 .



  20. #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 .



  21. #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 .



  22. #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 .



  23. #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 .



  24. #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 .



  25. #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 .



  26. #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 .



  27. #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 .



  28. #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 .



  29. #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 .



  30. #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 .



  31. #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 .



  32. #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 .



  33. #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 .



  34. #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 .



  35. #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 .



  36. #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 .



  37. #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 .



  38. #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 .



  39. #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 .



  40. #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 .



  41. #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 .



  42. #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 .



  43. #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 .



  44. #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 .



  45. #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 .



  46. #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 .



  47. #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 .



  48. #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 .



  49. #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 .



  50. #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 .



  51. #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 .



  52. #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 .



  53. #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 .



  54. #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 .



  55. #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 .



  56. #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 .



  57. #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 .



  58. #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 .



  59. #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 .



  60. #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 .



  61. #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 .



  62. #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 .



  63. #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 .



  64. #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 .



  65. #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 .



  66. #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 .



  67. #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 .



  68. #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 .



  69. #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 .



  70. #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 .



  71. #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 .



  72. #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 .



  73. #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 .



  74. #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 .



  75. #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 .



  76. #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 .



  77. #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 .



  78. #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 .



  79. #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 .



  80. #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 .



  81. #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 .



  82. #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 .



  83. #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 .



  84. #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 .



  85. #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 .



  86. #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 .



  87. #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 .



  88. #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 .



  89. #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 .



  90. #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 .



  91. #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 .



  92. #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 .



  93. #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 .



  94. #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 .



  95. #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 .



  96. #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 .



  97. #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 .



  98. #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 .



  99. #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 .



  100. #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 .



  101. #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 .



  102. #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 .



  103. #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 .



  104. #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 .



  105. #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 .







色を操作するためのクラスは簡単で非常に小さくなります。もちろん、色を使用した算術演算、独自のカラーパレットを追加できますが、これは行いません。



Color.h





  1. クラス Color {
  2. 公開
  3. 色(Uint8赤、Uint8緑、Uint8青):R(赤)、G(緑)、B(青){};
  4. ダブルR、G、B;
  5. };
*このソースコードは、 ソースコードハイライターで強調表示されました。




そして、徐々に、最も興味深いクラスに近づいており、それがポイントを導きます。 ご存知のように、画面上の各ピクセルには2つの座標があるため、それらをクラスのコンストラクターに渡します。 画面上の特定の点をベクトルと呼び、ベクトル間の算術演算を定義することに同意します(これらすべての演算が座標的に実行されることに注意する価値があります)。 これは、ベクトルの幾何学的操作が将来問題を引き起こさないようにするためです。



Vector_2D.cpp





  1. クラス Vector_2D {
  2. 公開
  3. Vector_2D( void ):x_coord(0)、y_coord(0){};
  4. Vector_2D( int X、 int Y);
  5. Vector_2D 演算子 -( const Vector_2D&) const ;
  6. Vector_2D 演算子 +( const Vector_2D&) const ;
  7. Vector_2D 演算子 *( const Vector_2D&) const ;
  8. int x_coord、y_coord;
  9. };
  10. Vector_2D :: Vector_2D( int X、 int Y){
  11. x_coord = X;
  12. y_coord = Y;
  13. }
  14. Vector_2D Vector_2D :: 演算子 -( const Vector_2D&rhs) const
  15. {
  16. Vector_2Dポイント;
  17. Point.x_coord =(this-> x_coord-rhs.x_coord);
  18. Point.y_coord =(this-> y_coord-rhs.y_coord);
  19. 戻り点;
  20. }
  21. Vector_2D Vector_2D :: 演算子 +( const Vector_2D&rhs) const
  22. {
  23. Vector_2Dポイント;
  24. Point.x_coord =(this-> x_coord + rhs.x_coord);
  25. Point.y_coord =(this-> y_coord + rhs.y_coord);
  26. 戻り点;
  27. }
  28. Vector_2D Vector_2D :: 演算子 *( const Vector_2D&rhs) const
  29. {
  30. Vector_2Dポイント;
  31. Point.x_coord =(this-> x_coord * rhs.x_coord);
  32. Point.y_coord =(this-> y_coord * rhs.y_coord);
  33. 戻り点;
  34. }
*このソースコードは、 ソースコードハイライターで強調表示されました。




そして、ここがプログラムの最も重要な部分です。 これは、描画と制御のロジック全体です。

test.cpp





  1. #include <iostream>
  2. #include "SDL_Interface.cpp"
  3. int main( int argc、 char ** argv){
  4. //画面サイズと色深度で描画する表面を宣言します
  5. SDL_Interface * mySDL = 新しい SDL_Interface(800、600、32);
  6. //色を定義します
  7. 青色(0x00、0x00、0xff);
  8. 赤色(0xff、0x00、0x00);
  9. 緑色(0x00、0xff、0x00);
  10. mySDL-> screen_lock(); //描画を開始する前に画面をロックします
  11. / *画面を3色で塗りつぶして描画* /
  12. forint x = 0; x <mySDL-> w(); x ++){
  13. forint y = 0; y <mySDL-> h(); y ++){
  14. if (y <(mySDL-> h())/ 3)
  15. mySDL-> putpixel(Vector_2D(x、y)、green);
  16. else if (y <((mySDL-> h())/ 3)* 2)
  17. mySDL-> putpixel(Vector_2D(x、y)、red);
  18. 他に
  19. mySDL-> putpixel(Vector_2D(x、y)、blue);
  20. }
  21. }
  22. mySDL-> screen_unlock();
  23. mySDL-> screen_update(0,0,0,0);
  24. if (mySDL-> key_wait(SDLK_ESCAPE))exit(0); // ESCの場合は終了
  25. 0を返します。
  26. }
*このソースコードは、 ソースコードハイライターで強調表示されました。




結論として、このライブラリは行動の範囲で私を征服したと言えます。 はい、あなた自身で書かなければならないものの多くは長い間実装されてきましたが、初心者やC ++で自分のゲーム「Life」を遊んだり作成したい人にとってはこれは素晴らしい選択です!



All Articles