bazz

SDL2 Fogframework TextureConnect

Mar 23rd, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1. /* Working SDL2 and Fog-Framework
  2. Method 3: Textures
  3.  
  4. This method seems best if you want to do all rendering in Fog
  5. Is it Software?? LoL
  6. */
  7.  
  8. SDL_Window *win;
  9.     //SDL_Surface *_screen;
  10.     SDL_Renderer *renderer,*RectRenderer;
  11.     SDL_Surface *RectScreen;
  12.     SDL_Texture *FogTexture;
  13.  
  14.  
  15.     win = SDL_CreateWindow(APPTITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_SHOWN);
  16.     // Main Screen renderer
  17.     renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
  18.     // "Main" Texture for Fog
  19.     // This texture needs a "context" so I just give it renderer... Not sure if that's GREAT PRACTICE!!
  20.     FogTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height);
  21.    
  22. void SdlApplication::Render()
  23. {
  24.  
  25.     // Used for our Texture -> Fog Mapping
  26.     unsigned char *pixels;
  27.     int pitch;
  28.    
  29.     // LOCK TEXTURE
  30.     SDL_LockTexture(FogTexture, NULL, (void **)&pixels, &pitch);
  31.    
  32.    
  33.     // Create Fog::Painter instance mapped to the SDL surface data.
  34.     Fog::Painter p;
  35.    
  36.     // Setup image buffer for painter.
  37.     Fog::ImageBits buf;
  38.    
  39.     // Convert Texture buffer -> Fog Buffer
  40.     buf.setData(Fog::SizeI(720,450), Fog::IMAGE_FORMAT_XRGB32, pitch, (reinterpret_cast<uint8_t*>(pixels)));
  41.    
  42.     // Call our paint handler.
  43.     if (p.begin(buf) == Fog::ERR_OK) onPaint(p);
  44.    
  45.     // Never forget to call p.end(). Painting can be asynchronous and
  46.     // SDL_UnlockSurface() can invalidate the surface->pixels pointer.
  47.     p.end();
  48.    
  49.     // Unlock surface pixels.
  50.     SDL_UnlockTexture(FogTexture);
  51.    
  52.     // You may want to do some Pre-Fog rendering here
  53.     //SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
  54.     //SDL_RenderClear(renderer);
  55.    
  56.     // IMPORTANT PART HERE - this actually renders Fog-work to the Renderer -> Screen
  57.     SDL_RenderCopy(renderer, FogTexture, NULL, NULL);
  58.    
  59.     // final push to screen
  60.     SDL_RenderPresent(renderer);
  61. }
  62.  
  63. void SdlApplication::onPaint(Fog::Painter& p)
  64. {
  65.     // Fog Paint in here :)
  66. }
Advertisement
Add Comment
Please, Sign In to add comment