Aslai

Untitled

Jul 19th, 2011
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "gm.h"
  4.  
  5. using namespace gm;
  6.  
  7. struct px
  8. {
  9. int r,g,b,a;
  10. inline px()
  11. {
  12. r = 0; g = 0; b = 0; a = 0;
  13. }
  14. inline void mult( int v )
  15. {
  16. r *= v; g *= v; b *= v; a *= v;
  17. }
  18. inline void div( int v )
  19. {
  20. r /= v; g /= v; b /= v; a /= v;
  21. }
  22.  
  23. inline void add( px v )
  24. {
  25. r += v.r; g += v.g; b += v.b; a += v.a;
  26. }
  27. inline void set( unsigned long in )
  28. {
  29. r = (in >> 24 )&0xFF; g = (in >> 16 )&0xFF; b = (in >> 8 )&0xFF ; a = (in)&0xFF ;
  30. }
  31. inline unsigned long get( )
  32. {
  33. return (( r & 0xFF ) << 24) + (( g & 0xFF ) << 16) +(( b & 0xFF ) << 8) +(( a & 0xFF ));
  34. }
  35.  
  36.  
  37. };
  38.  
  39. int main()
  40. {
  41. initGM( 640, 480, 32 );
  42. SDL_Surface* playerImage = sprite_add( "face.bmp" );
  43. int playerX = 200;
  44. int playerY = 200;
  45. px* array = (px*) malloc( 640 * 480 * sizeof( px ) );
  46. SDL_Surface* nsurf = surface_create( 640, 480 );
  47.  
  48.  
  49. startGMLoop{
  50. for( int j = 1; j < 478; j ++ )
  51. {
  52. for( int i = 1; i < 638; i ++)
  53. {
  54. array[i+j*640].set(((unsigned long*) playerImage->pixels)[i+j*640]);
  55. }
  56. }
  57.  
  58. for( int j = 1; j < 478; j ++ )
  59. {
  60. for( int i = 1; i < 638; i ++)
  61. {
  62. array[i+j*640 - 640 - 1].mult( -1 );
  63. array[i+j*640 - 640 ].mult( -1 );
  64. array[i+j*640 - 640 + 1].mult( -1 );
  65. array[i+j*640 - 1 ].mult( -1 );
  66. array[i+j*640 ].mult( 8 );
  67. array[i+j*640 + 1 ].mult( -1 );
  68. array[i+j*640 + 640 - 1].mult( -1 );
  69. array[i+j*640 + 640 ].mult( -1 );
  70. array[i+j*640 + 640 + 1].mult( -1 );
  71. px newpx;
  72. newpx.add( array[i+j*640 - 640 - 1] );
  73. newpx.add( array[i+j*640 - 640 ] );
  74. newpx.add( array[i+j*640 - 640 + 1] );
  75. newpx.add( array[i+j*640 - 1] );
  76. newpx.add( array[i+j*640 ] );
  77. newpx.add( array[i+j*640 + 1] );
  78. newpx.add( array[i+j*640 + 640 - 1] );
  79. newpx.add( array[i+j*640 + 640 ] );
  80. newpx.add( array[i+j*640 + 640 + 1] );
  81. newpx.div( 16 );
  82. ((unsigned long*) nsurf->pixels )[i+j*640] = newpx.get();
  83.  
  84. }
  85. }
  86.  
  87. draw_surface( nsurf, 0, 0 );
  88.  
  89.  
  90. endGMLoop();}
  91. }
Advertisement
Add Comment
Please, Sign In to add comment