📜 ⬆️ ⬇️

2D rendering in SDL

image For a long time I did not want to write this article - I thought how to submit the material. But, it can be seen today, stars have successfully formed and there is an article about SDL. Although this is just a draft. In the future, this article will be broken down into several separate ones - there is enough material and code.

For those who are not familiar with this old, but very good cross-platform graphics library, I would advise you to read this post .
You can download the library from the official site , I think it will not be difficult. I will not go into details, since the result will be simply immense, they can be found here .

Today we will write a program from scratch that will fill the screen with three colors.

So let's start:
We will have 3 auxiliary classes and the main part of the program, which will “light” the pixels on the screen with any colors. I repeat once again that only the very basics will be described here, which should be of interest to the reader.
')
First of all, you need to declare a class that will directly load the library and operate with all its functions. Such as (once) the screen lock, work with pixels and the surface on which we will “draw”. The main part of the code located in this class is in the reference files of our library. Although how it works and why the pixels are lit it would still be useful to know, it seems to me, but this is beyond the scope of the article.

SDL_Interface.cpp
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  1. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  2. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  3. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  4. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  5. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  6. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  7. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  8. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  9. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  10. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  11. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  12. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  13. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  14. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  15. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  16. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  17. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  18. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  19. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  20. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  21. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  22. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  23. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  24. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  25. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  26. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  27. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  28. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  29. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  30. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  31. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  32. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  33. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  34. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  35. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  36. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  37. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  38. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  39. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  40. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  41. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  42. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  43. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  44. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  45. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  46. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  47. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  48. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  49. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  50. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  51. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  52. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  53. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  54. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  55. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  56. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  57. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  58. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  59. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  60. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  61. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  62. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  63. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  64. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  65. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  66. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  67. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  68. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  69. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  70. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  71. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  72. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  73. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  74. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  75. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  76. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  77. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  78. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  79. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  80. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  81. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  82. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  83. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  84. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  85. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  86. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  87. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  88. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  89. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  90. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  91. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  92. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  93. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  94. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  95. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  96. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  97. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  98. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  99. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  100. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  101. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  102. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  103. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  104. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
  105. #include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .
#include <SDL.h> #include "Vector_2D.cpp" #include "Color.h" class SDL_Interface{ public : SDL_Interface( int , int , int ); ~SDL_Interface(); void putpixel( int x, int y, const Color&); void putpixel( const Vector_2D&, const Color&); int const h(); /* */ int const w(); /* */ bool const key_wait( int ); void const screen_unlock(); int const screen_lock(); void const screen_update(Sint32, Sint32, Sint32, Sint32); protected : SDL_Surface *screen; SDL_Event event ; }; SDL_Interface::SDL_Interface( int width, int height, int color_depth) { /* SDL */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n" , SDL_GetError()); exit(1); } screen = SDL_SetVideoMode(width, height, color_depth, SDL_SWSURFACE); if ( screen == NULL ) { fprintf(stderr, "Couldn't set video mode: %s\n" , SDL_GetError()); exit(1); } } SDL_Interface::~SDL_Interface(){ SDL_Quit(); } int const SDL_Interface::w(){ return screen->w; } int const SDL_Interface::h(){ return screen->h; } int const SDL_Interface::screen_lock(){ /* */ if ( SDL_MUSTLOCK(screen) ) { if ( SDL_LockSurface(screen) < 0 ) { fprintf(stderr, "Can't lock screen: %s\n" , SDL_GetError()); return 0; } } return 0; } void const SDL_Interface::screen_unlock(){ if ( SDL_MUSTLOCK(screen) ) { SDL_UnlockSurface(screen); } } void const SDL_Interface::screen_update(Sint32 x, Sint32 y, Sint32 w, Sint32 h){ SDL_UpdateRect(screen, x, y, w, h); } bool const SDL_Interface::key_wait( int key_id){ while ( SDL_WaitEvent(& event ) >= 0 ) { Uint8 *keys; keys = SDL_GetKeyState(NULL); if ( keys[key_id] == SDL_PRESSED ) { return true ; } if ( event .type == SDL_QUIT){ exit(0); } } return false ; } void SDL_Interface::putpixel( const Vector_2D& vector_2d, const Color& color) { putpixel(vector_2d.x_coord, vector_2d.y_coord, color); } /* */ void SDL_Interface::putpixel( int x, int y, const Color& color) { Uint32 pixel = SDL_MapRGB(screen->format, color.R, color.G, color.B); SDL_Surface *surface = screen; int bpp = surface->format->BytesPerPixel; Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; switch (bpp) { case 1: *p = pixel; break ; case 2: *(Uint16 *)p = pixel; break ; case 3: if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { p[0] = (pixel >> 16) & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = pixel & 0xff; } else { p[0] = pixel & 0xff; p[1] = (pixel >> 8) & 0xff; p[2] = (pixel >> 16) & 0xff; } break ; case 4: *(Uint32 *)p = pixel; break ; } } * This source code was highlighted with Source Code Highlighter .


The class for working with color will be trivial and very small, of course you can add arithmetic operations with colors to it, your own color palettes, but we will not do that.

Color.h
  1. class Color {
  2. public :
  3. Color (Uint8 red, Uint8 green, Uint8 blue): R (red), G (green), B (blue) {};
  4. double R, G, B;
  5. };
* This source code was highlighted with Source Code Highlighter .


And so, gradually, we get to the most interesting class, which will lead our points. As we know, each pixel on the screen has two coordinates, that’s what we will pass to the class constructor. We agree to call a specific point of the screen a vector, and we define arithmetic operations between vectors (it is worth noting that all these operations are performed along the coordinate axis). This is done so that in the future geometric operations on vectors do not cause problems.

Vector_2D.cpp
  1. class Vector_2D {
  2. public :
  3. Vector_2D ( void ): x_coord (0), y_coord (0) {};
  4. Vector_2D ( int X, int Y);
  5. Vector_2D operator - ( const Vector_2D &) const ;
  6. Vector_2D operator + ( const Vector_2D &) const ;
  7. Vector_2D operator * ( const Vector_2D &) const ;
  8. int x_coord, y_coord;
  9. };
  10. Vector_2D :: Vector_2D ( int X, int Y) {
  11. x_coord = X;
  12. y_coord = Y;
  13. }
  14. Vector_2D Vector_2D :: operator - ( const Vector_2D & rhs) const
  15. {
  16. Vector_2D Point;
  17. Point.x_coord = ( this -> x_coord - rhs.x_coord);
  18. Point.y_coord = ( this -> y_coord - rhs.y_coord);
  19. return point;
  20. }
  21. Vector_2D Vector_2D :: operator + ( const Vector_2D & rhs) const
  22. {
  23. Vector_2D Point;
  24. Point.x_coord = ( this -> x_coord + rhs.x_coord);
  25. Point.y_coord = ( this -> y_coord + rhs.y_coord);
  26. return point;
  27. }
  28. Vector_2D Vector_2D :: operator * ( const Vector_2D & rhs) const
  29. {
  30. Vector_2D Point;
  31. Point.x_coord = ( this -> x_coord * rhs.x_coord);
  32. Point.y_coord = ( this -> y_coord * rhs.y_coord);
  33. return point;
  34. }
* This source code was highlighted with Source Code Highlighter .


And here is the most important part of our program. Here lies the whole logic of drawing and control.
test.cpp
  1. #include <iostream>
  2. #include "SDL_Interface.cpp"
  3. int main ( int argc, char ** argv) {
  4. // Declare the surface on which we will draw with the screen size and color depth
  5. SDL_Interface * mySDL = new SDL_Interface (800, 600, 32);
  6. // Determine the colors
  7. Color blue (0x00, 0x00, 0xff);
  8. Color red (0xff, 0x00, 0x00);
  9. Color green (0x00, 0xff, 0x00);
  10. mySDL-> screen_lock (); // Lock Screen Before Drawing
  11. / * We draw by flooding the screen in three colors * /
  12. for ( int x = 0; x <mySDL-> w (); x ++) {
  13. for ( int y = 0; y <mySDL-> h (); y ++) {
  14. if (y <(mySDL-> h ()) / 3)
  15. mySDL-> putpixel (Vector_2D (x, y), green);
  16. else if (y <((mySDL-> h ()) / 3) * 2)
  17. mySDL-> putpixel (Vector_2D (x, y), red);
  18. else
  19. mySDL-> putpixel (Vector_2D (x, y), blue);
  20. }
  21. }
  22. mySDL-> screen_unlock ();
  23. mySDL-> screen_update (0,0,0,0);
  24. if (mySDL-> key_wait (SDLK_ESCAPE)) exit (0); // Exit if ESC
  25. return 0;
  26. }
* This source code was highlighted with Source Code Highlighter .


In conclusion, I’ll say that this library won me over with room for action. Yes, much of what you have to write yourself has long been implemented, but for beginners and for those who just want to play or create their own game “Life” in c ++ it will be a great choice!

Source: https://habr.com/ru/post/100842/


All Articles