Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Working SDL2 and Fog-Framework
- Method 2: Software Renderers
- Also using Fog::Image with SDL2 Surface
- It's Software so probably Slower ?? ?
- */
- SDL_Window *win;
- SDL_Surface *RectSurface;
- SDL_Renderer *RectRenderer;
- win = SDL_CreateWindow("SDL2 & FOG", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_SHOWN);
- FogSurface = SDL_GetWindowSurface(win);
- RectSurface = SDL_CreateRGBSurface(0,width,height,32,0,0,0,0);
- RectRenderer = SDL_CreateSoftwareRenderer(RectSurface);
- void onRender()
- {
- // This is how we Draw Rects to the Renderer ( Setup to Draw to a Surface!! RectSurface!! )
- SDL_SetRenderDrawColor(RectRenderer,255,0,0,255);
- SDL_RenderClear(RectRenderer);
- SDL_SetRenderDrawColor(RectRenderer, 255,255,0,255);
- SDL_RenderFillRect(RectRenderer, &r);
- // next line appears to be unnecessary on the Software Renderer, but I use it anyway
- SDL_RenderPresent(RectRenderer);
- // Lock surface pixels.
- SDL_LockSurface(FogSurface);
- SDL_LockSurface(RectSurface); // The surface is directly connected to the renderer, its results intact
- // Create Fog::Painter instance mapped to the SDL surface data.
- Fog::Painter p;
- // Setup image buffer for painter.
- Fog::ImageBits buf;
- buf.setData(Fog::SizeI(FogSurface->w, FogSurface->h), Fog::IMAGE_FORMAT_XRGB32, FogSurface->pitch, (reinterpret_cast<uint8_t*>(FogSurface->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();
- SDL_UnlockSurface(RectSurface);
- // Unlock surface pixels.
- SDL_UnlockSurface(FogSurface);
- // Flip buffer.
- SDL_UpdateWindowSurface(win);
- }
- void SdlApplication::onPaint(Fog::Painter& p)
- {
- // Just use the Fog-Framework ;-)
- Image image;
- Imagebits mybuf;
- // Get RectSurface data
- mybuf.setData(Fog::SizeI(RectSurface->w, RectSurface->h), Fog::IMAGE_FORMAT_XRGB32, RectSurface->pitch, (reinterpret_cast<uint8_t*>(RectSurface->pixels)));
- // adopt that data into a Fog::Image
- image.adopt(mybuf);
- p.setSource(Argb32(0xFFFFFFFF));
- p.fillAll();
- PointI pos(0,0);
- p.blitImage(pos,image);
- }
Advertisement
Add Comment
Please, Sign In to add comment