(Sorry for top-posting.)
So, you’re trying to use OpenGL to render to an offscreen image of
your rotated sprites and then use those pixels with software 2D SDL?
I have to say I’m a little confused at why this becomes necessary. I
would suggest just going over to OpenGL for your drawing needs. It’s
really not that hard, and lets you ignore a lot of the more software-
oriented drawing ideas like dirty rectangles, etc. (You CAN use dirty
rects in OGL, however, but on most hardware it isn’t necessary for 2D
drawing.)
You mentioned speed as an issue with the software-based rotations and
scaling, which makes me think that you’re imagining transforming your
image in OpenGL and then drawing the resulting pixels to your SDL
context each frame, and I have to say this is probably (though your
situation may be an exception?) a tremendous waste of time and
effort. If you’re already using OpenGL, you may as well just use it
outright. As has been mentioned already, it’s pretty slow to read the
pixel data into a pixel array from the video hardware, so already the
speed you may have gotten with OpenGL is somewhat compromised.
Also, when they talk about using SDL_gfx, what they usually mean is
that you manipulate your image, and then save it into memory as a new
sprite or image, and then you can use the transformed sprites when
they’re needed, quickly, without having to load pre-transformed image
data from the disk, thereby lowering the amount of redundant data you
have to include with your program.
But if you’re going so far as to want to include fragment shader
programs in with your image manipulation, then you already have decent
OpenGL capabilities on your graphics card, and I’m pretty sure you’re
better off just using SDL to give you an OpenGL context, and rendering
into that…
– ScottOn Sep 16, 2008, at 8:51 PM, Mason Wheeler wrote:
I’ve seen several people ask about how to do image transformations
(rotation and zooming, mostly) and the answer is usually “use
SDL_gfx or do it in OpenGL.” Well, SDL_gfx is slow and I’d like to
be able to do things in GL.
I’ve looked up a lot of stuff on OpenGL programming and I’ve got a
handle on how texture mapping works and how you can map things at
strange angles by messing with the vertices in order to rotate,
scale or mirror a texture you’re drawing to the screen. Problem is,
everything I find is about drawing to the screen. (Or to the GL
buffer, which goes to the screen. Same difference in the end.) What
I really want to do is take a surface and rotate, scale and mirror
it, (or some combination of the three,) and possibly even run some
shaders on it for advanced image processing, and then NOT draw it to
the screen, but retrieve it back into an SDL_surface.
Does anyone know enough OpenGL to help me out? I need some sample
code showing what to do with an SDL_surface I’ve loaded into a GL
texture. Assume I already have a function written called
GL_Mutilate() that does all the image processing, and throw that in
at the appropriate place, then retrieve the result and return a
SDL_surface pointer.
If someone could write up a sample routine illustrating the basic
principles for doing this, I’d be very grateful.
Mason