Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Working SDL2 and Fog-Framework
- Method 3: Textures
- This method seems best if you want to do all rendering in Fog
- Is it Software?? LoL
- */
- SDL_Window *win;
- //SDL_Surface *_screen;
- SDL_Renderer *renderer,*RectRenderer;
- SDL_Surface *RectScreen;
- SDL_Texture *FogTexture;
- win = SDL_CreateWindow(APPTITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_SHOWN);
- // Main Screen renderer
- renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
- // "Main" Texture for Fog
- // This texture needs a "context" so I just give it renderer... Not sure if that's GREAT PRACTICE!!
- FogTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height);
- void SdlApplication::Render()
- {
- // Used for our Texture -> Fog Mapping
- unsigned char *pixels;
- int pitch;
- // LOCK TEXTURE
- SDL_LockTexture(FogTexture, NULL, (void **)&pixels, &pitch);
- // Create Fog::Painter instance mapped to the SDL surface data.
- Fog::Painter p;
- // Setup image buffer for painter.
- Fog::ImageBits buf;
- // Convert Texture buffer -> Fog Buffer
- buf.setData(Fog::SizeI(720,450), Fog::IMAGE_FORMAT_XRGB32, pitch, (reinterpret_cast<uint8_t*>(pixels)));
- // Call our paint handler.
- if (p.begin(buf) == Fog::ERR_OK) onPaint(p);
- // Never forget to call p.end(). Painting can be asynchronous and
- // SDL_UnlockSurface() can invalidate the surface->pixels pointer.
- p.end();
- // Unlock surface pixels.
- SDL_UnlockTexture(FogTexture);
- // You may want to do some Pre-Fog rendering here
- //SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
- //SDL_RenderClear(renderer);
- // IMPORTANT PART HERE - this actually renders Fog-work to the Renderer -> Screen
- SDL_RenderCopy(renderer, FogTexture, NULL, NULL);
- // final push to screen
- SDL_RenderPresent(renderer);
- }
- void SdlApplication::onPaint(Fog::Painter& p)
- {
- // Fog Paint in here :)
- }
Advertisement
Add Comment
Please, Sign In to add comment