SDLでの2Dレンダリング
![画像](http://www.atlasgeo.net/FOTW/images/b/ba!91a.gif)
長い間、私はこの記事を書きたくはありませんでした-資料の提出方法を考えました。 しかし、今日では、スターの開発が成功し、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 .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
-
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
色を操作するためのクラスは簡単で非常に小さくなります。もちろん、色を使用した算術演算、独自のカラーパレットを追加できますが、これは行いません。
Color.h
- クラス Color {
- 公開 :
- 色(Uint8赤、Uint8緑、Uint8青):R(赤)、G(緑)、B(青){};
- ダブルR、G、B;
- };
*このソースコードは、 ソースコードハイライターで強調表示されました。
そして、徐々に、最も興味深いクラスに近づいており、それがポイントを導きます。 ご存知のように、画面上の各ピクセルには2つの座標があるため、それらをクラスのコンストラクターに渡します。 画面上の特定の点をベクトルと呼び、ベクトル間の算術演算を定義することに同意します(これらすべての演算が座標的に実行されることに注意する価値があります)。 これは、ベクトルの幾何学的操作が将来問題を引き起こさないようにするためです。
Vector_2D.cpp
- クラス Vector_2D {
- 公開 :
- Vector_2D( void ):x_coord(0)、y_coord(0){};
- Vector_2D( int X、 int Y);
- Vector_2D 演算子 -( const Vector_2D&) const ;
- Vector_2D 演算子 +( const Vector_2D&) const ;
- Vector_2D 演算子 *( const Vector_2D&) const ;
- int x_coord、y_coord;
- };
- Vector_2D :: Vector_2D( int X、 int Y){
- x_coord = X;
- y_coord = Y;
- }
- Vector_2D Vector_2D :: 演算子 -( const Vector_2D&rhs) const
- {
- Vector_2Dポイント;
- Point.x_coord =(this-> x_coord-rhs.x_coord);
- Point.y_coord =(this-> y_coord-rhs.y_coord);
- 戻り点;
- }
- Vector_2D Vector_2D :: 演算子 +( const Vector_2D&rhs) const
- {
- Vector_2Dポイント;
- Point.x_coord =(this-> x_coord + rhs.x_coord);
- Point.y_coord =(this-> y_coord + rhs.y_coord);
- 戻り点;
- }
- Vector_2D Vector_2D :: 演算子 *( const Vector_2D&rhs) const
- {
- Vector_2Dポイント;
- Point.x_coord =(this-> x_coord * rhs.x_coord);
- Point.y_coord =(this-> y_coord * rhs.y_coord);
- 戻り点;
- }
*このソースコードは、 ソースコードハイライターで強調表示されました。
そして、ここがプログラムの最も重要な部分です。 これは、描画と制御のロジック全体です。
test.cpp
- #include <iostream>
- #include "SDL_Interface.cpp"
- int main( int argc、 char ** argv){
- //画面サイズと色深度で描画する表面を宣言します
- SDL_Interface * mySDL = 新しい SDL_Interface(800、600、32);
- //色を定義します
- 青色(0x00、0x00、0xff);
- 赤色(0xff、0x00、0x00);
- 緑色(0x00、0xff、0x00);
- mySDL-> screen_lock(); //描画を開始する前に画面をロックします
- / *画面を3色で塗りつぶして描画* /
- for ( int x = 0; x <mySDL-> w(); x ++){
- for ( int y = 0; y <mySDL-> h(); y ++){
- if (y <(mySDL-> h())/ 3)
- mySDL-> putpixel(Vector_2D(x、y)、green);
- else if (y <((mySDL-> h())/ 3)* 2)
- mySDL-> putpixel(Vector_2D(x、y)、red);
- 他に
- mySDL-> putpixel(Vector_2D(x、y)、blue);
- }
- }
- mySDL-> screen_unlock();
- mySDL-> screen_update(0,0,0,0);
- if (mySDL-> key_wait(SDLK_ESCAPE))exit(0); // ESCの場合は終了
- 0を返します。
- }
*このソースコードは、 ソースコードハイライターで強調表示されました。
結論として、このライブラリは行動の範囲で私を征服したと言えます。 はい、あなた自身で書かなければならないものの多くは長い間実装されてきましたが、初心者やC ++で自分のゲーム「Life」を遊んだり作成したい人にとってはこれは素晴らしい選択です!
All Articles