bazz

SDl2 FogFramework SoftwareConnect, ScreenSurface

Mar 23rd, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. /* Working SDL2 and Fog-Framework
  2. Method 1: No Renderer, just Screen Surface
  3.  
  4. It's Software so probably Slower ?? ?
  5. */
  6.  
  7. SDL_Window *win;
  8. SDL_Surface *_screen;
  9.  
  10. win = SDL_CreateWindow("SDL2 & FOG", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_SHOWN);
  11. _screen = SDL_GetWindowSurface(win);
  12.  
  13. ///.....
  14. ///Then in your Render()
  15.  
  16. void SdlApplication::onRender()
  17. {
  18.     // Lock surface pixels.
  19.     SDL_LockSurface(_screen);
  20.    
  21.     // Create Fog::Painter instance mapped to the SDL surface data.
  22.     Fog::Painter p;
  23.    
  24.     // Setup image buffer for painter.
  25.     Fog::ImageBits buf;
  26.    
  27.     // This lets Fog work with the Screen Surface
  28.     buf.setData(Fog::SizeI(_screen->w, _screen->h), Fog::IMAGE_FORMAT_XRGB32, _screen->pitch, (reinterpret_cast<uint8_t*>(_screen->pixels)));
  29.    
  30.     // Call our paint handler.
  31.     if (p.begin(buf) == Fog::ERR_OK) onPaint(p);
  32.    
  33.     // Never forget to call p.end(). Painting can be asynchronous and
  34.     // SDL_UnlockSurface() can invalidate the surface->pixels pointer.
  35.     p.end();
  36.    
  37.     // Unlock surface pixels.
  38.     SDL_UnlockSurface(_screen);
  39.    
  40.     // SDL Update that window!
  41.     SDL_UpdateWindowSurface(win);
  42. }
  43.  
  44. // This is where your Fog Code goes
  45. void SdlApplication::onPaint(Fog::Painter& p)
  46. {
  47.     p.setSource(Argb32(0xFFFFFFFF));
  48.     p.fillAll();
  49. }
Advertisement
Add Comment
Please, Sign In to add comment