SDL: How to flush the "Surface Buffer" - sdl

I want to draw a surface and then pause my program for 1 second. Unfortunately the surface is not drawn onto the screen until after the delay. When does SDL actually draw onto the screen? How can I force it to draw all the surfaces "in the queue" right now?
Here is some skeleton code to illustrate the problem
SDL_BlitSurface(NewSurface, NULL,Display, &destRect); //Draw the new surface
SDL_Flip(display); //I have tried flipping all the surfaces
SDL_Delay(1000); //Or Sleep(1000) neither work
... //Surface is drawn sometime later but I cannot figure out when.

Related

Cairo: Cropping a PDF Surface?

Let's say I make a surface like this:
cairo_surface_t* surface = cairo_pdf_surface_create("pdffile.pdf", 40000, 40000);
cairo_t* cr = cairo_create(surface);
That's a big surface! The reason for doing so is that I don't know the size of my drawing until I've plotted it (it's a complicated graph, generated on the fly). After I've plotted it, it seems pretty trivial to crop the surface. So how do I do it?
Draw to a recording surface instead of a PDF surface. The recording surfaces can then be painted to a smaller PDF surface. Also, cairo supports unbounded recording surfaces, so this would even work when your drawing is wider/higher than 40k pixel.

Painting app using FBO in OpenGL

I am working on an application in C++ and OpenGL (using Cinder library).
It is simply getting mouse input, and in the draw method draws circles on the mouse position to the FBO. After that the FBO is drawn to the screen. The FBO isn't cleared everytime, so the previous circles are still in it. The problem is that when I draw new circle to the FBO, it isn't drawn on top of it, but instead under the previous content of the FBO. The FBO is created only with width and height parameters and no other settings. It's also cleared in the setup().

SDL blitting surface on surface

Me and my friends are working on a game project, and we seem to have hit a wall. We have a system, which takes the SDL RGB surface from a namespace in different header file. We blit it to the screen, (SDL_SetVideoMode), then we blit one more from another namespace header file and we blit the second on the same screen. It overwrites the screen and we can't see the first one surface..
Any ideas how to blit two surfaces to screen one on another?
It seems your draw order is messed up.
Remember, SDL has no Z-order so to achieve the illusion of one object on another, you must draw the one to be below first. Just like if you were painting a picture in real life.
It looks like your surface loses transparency, when blitted into another surface. The pixels in srcrect loses transparency, And therefore you cannot see behind the surface. Sadly I can't understand why it happens. Good luck with it btw.

OpenGL Coplanar Surfaces

In my OpenGL problem set, I have drawn a particular polygon and with the mouse selection, I want to draw a square from the place I have selected. The square drawn gets updated rapidly with my change in mouse motion and finally should be affixed to the end point where I release the mouse button.
In my mouse motion routine, I tried doing the glClear(GL_COLOR_BUFFER_BIT); and called a drawSquare function that I have written. The glClear ensures that I have only a unique square drawn and not a blotch of previous images appearing. However, this clearing also clears my initial polygon that I had drawn.
Please advice on how to make sure I have this new square (from mouse) on top of my existing polygon.
P.S : I tried drawing the underlying polygon on the backbuffer and the square on the front, but the glutSwapBuffers() created havoc.
Like many others you seem to mistake OpenGL for a scene managment API, which is plain wrong. OpenGL does nothing else than draw something to the screen. After it's drawn OpenGL completely forgets about the polygon. So what this means is, that you have to draw everything you want to be shown every frame (often after clearing the framebuffer).
So clear the framebuffer, draw your polygon and draw your square. Once the square position (or anything else) changes, clear the framebuffer again, draw the polygon and draw your square. That's the way it works.
And also you should of course not draw anything in the mouse routine, let aside call glClear, which results in exactly the kind of rubbish you're experiencing. Instead update your scene and request the window to redraw itself, which in turn draws the whole scene in the display method:
mouseFunc()
{
updateSquare();
glutPostRedisplay();
}
displayFunc()
{
glClear(...);
drawPolygon();
drawSquare();
glutSwapBuffers();
}
And of course by all means don't draw to the front buffer when using double buffering.

Blitting over YUV Overlay

I have a YUV overlay that I want to draw a HUD over. Think of a video with a scrubber bar. I want to know what the fastest method of doing this would be. The platform I am on does not support Hardware Surfaces.
Currently I do things in this order:
Draw YUV overlay directly to screen
Blit scrubber bar directly to screen
Would there be any speed advantage in doing something like:
Draw YUV overlay to temporary SDL_Surface
Blit scrubber bar to temporary SDL_Surface
Blit temporary SDL_Surface to screen
I think the second way would be faster. Looking at program flow, every time you blit to the screen you might get stuck waiting for the direct blit to finish. Blitting to a temporary surface is just copying from one C array to another, so you can push the final blit to screen to the end of your program logic.