Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "gm.h"
- using namespace gm;
- struct px
- {
- int r,g,b,a;
- inline px()
- {
- r = 0; g = 0; b = 0; a = 0;
- }
- inline void mult( int v )
- {
- r *= v; g *= v; b *= v; a *= v;
- }
- inline void div( int v )
- {
- r /= v; g /= v; b /= v; a /= v;
- }
- inline void add( px v )
- {
- r += v.r; g += v.g; b += v.b; a += v.a;
- }
- inline void set( unsigned long in )
- {
- r = (in >> 24 )&0xFF; g = (in >> 16 )&0xFF; b = (in >> 8 )&0xFF ; a = (in)&0xFF ;
- }
- inline unsigned long get( )
- {
- return (( r & 0xFF ) << 24) + (( g & 0xFF ) << 16) +(( b & 0xFF ) << 8) +(( a & 0xFF ));
- }
- };
- int main()
- {
- initGM( 640, 480, 32 );
- SDL_Surface* playerImage = sprite_add( "face.bmp" );
- int playerX = 200;
- int playerY = 200;
- px* array = (px*) malloc( 640 * 480 * sizeof( px ) );
- SDL_Surface* nsurf = surface_create( 640, 480 );
- startGMLoop{
- for( int j = 1; j < 478; j ++ )
- {
- for( int i = 1; i < 638; i ++)
- {
- array[i+j*640].set(((unsigned long*) playerImage->pixels)[i+j*640]);
- }
- }
- for( int j = 1; j < 478; j ++ )
- {
- for( int i = 1; i < 638; i ++)
- {
- array[i+j*640 - 640 - 1].mult( -1 );
- array[i+j*640 - 640 ].mult( -1 );
- array[i+j*640 - 640 + 1].mult( -1 );
- array[i+j*640 - 1 ].mult( -1 );
- array[i+j*640 ].mult( 8 );
- array[i+j*640 + 1 ].mult( -1 );
- array[i+j*640 + 640 - 1].mult( -1 );
- array[i+j*640 + 640 ].mult( -1 );
- array[i+j*640 + 640 + 1].mult( -1 );
- px newpx;
- newpx.add( array[i+j*640 - 640 - 1] );
- newpx.add( array[i+j*640 - 640 ] );
- newpx.add( array[i+j*640 - 640 + 1] );
- newpx.add( array[i+j*640 - 1] );
- newpx.add( array[i+j*640 ] );
- newpx.add( array[i+j*640 + 1] );
- newpx.add( array[i+j*640 + 640 - 1] );
- newpx.add( array[i+j*640 + 640 ] );
- newpx.add( array[i+j*640 + 640 + 1] );
- newpx.div( 16 );
- ((unsigned long*) nsurf->pixels )[i+j*640] = newpx.get();
- }
- }
- draw_surface( nsurf, 0, 0 );
- endGMLoop();}
- }
Advertisement
Add Comment
Please, Sign In to add comment