Advertisement
Guest User

Untitled

a guest
Nov 21st, 2012
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. /*
  2.     ===============
  3.      Filled Circle
  4.     ===============
  5.        
  6. */
  7.  
  8. #include <SDL/SDL.h>
  9. #include <SDL/SDL_image.h>
  10. #include <math.h>
  11. #include <iostream>
  12. using namespace std;
  13.  
  14. SDL_Surface *Screen = SDL_SetVideoMode(640,480,32,SDL_SWSURFACE);
  15.  
  16.  SDL_Surface* PixelSurface = SDL_CreateRGBSurface(SDL_HWSURFACE, 640, 480,
  17.   Screen->format->BitsPerPixel,
  18.   Screen->format->Rmask,
  19.   Screen->format->Gmask,
  20.   Screen->format->Bmask,
  21.   Screen->format->Amask
  22.     );
  23.  
  24. void inline SDL_Draw()
  25. {
  26.     int
  27.     mouse_x = 0,
  28.     mouse_y = 0,
  29.     centerx = 100,
  30.     centery = 100,
  31.     radius = 50;
  32.  
  33.     int x, y,
  34.     color = 0x00ff00;
  35.    
  36.     float
  37.     two_pi = 360.283f,
  38.     angle_inc = 1.0f/radius;
  39.        
  40.     for(float angle = 0.0f; angle<=two_pi; angle+=angle_inc)
  41.     {
  42.         unsigned int *ptr = static_cast <unsigned int *> (PixelSurface->pixels);
  43.        
  44.         x = centerx+radius*cos(angle);
  45.  
  46.         y = centery+radius*sin(angle);
  47.        
  48.         //set the centerx and y to the radius and = it color
  49.  
  50.         int offset = y * (PixelSurface->pitch/sizeof(unsigned int));
  51.        
  52.         ptr[offset + x] = color;
  53.         ptr[centerx * radius] = color;
  54.    
  55.     }
  56.  
  57.     SDL_BlitSurface(PixelSurface,NULL,Screen,NULL);
  58. }
  59.  
  60. int main(int argc, char *Argv[])
  61. {
  62.     bool
  63.     done = false;
  64.  
  65.     SDL_Event event;
  66.    
  67.     SDL_WM_SetCaption("Test","Test");
  68.  
  69.     while(!done)
  70.     {
  71.         SDL_Draw();
  72.    
  73.         while(SDL_PollEvent(&event))
  74.         {
  75.  
  76.             switch(event.type)
  77.             {
  78.                 case SDL_QUIT:
  79.                 return 0;
  80.                 break;
  81.             }
  82.         }
  83.  
  84.         SDL_Flip(Screen);
  85.         SDL_FillRect(PixelSurface,NULL,0x000000);
  86.     }
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement