[SDL] SDL2 pinch zoom
jurksztowicz at gmail.com
Wed Mar 20 13:14:33 PDT 2013
2013/3/7 Mason Wheeler <masonwheeler at yahoo.com>
> I've got a window with an OpenGL renderer, and a routine that goes like
> Use SDL_Image to load an image to a surface.
> Create a texture from the surface.
> Render the texture to the window.
> Render a rectangle of color with a partially transparent alpha value over
> the top of the texture.
> When the image I'm loading is an 8-bit image, this works fine. But when
> it's a 32-bit image, the alpha doesn't work; instead of a translucent
> rectangle drawn over the image, I get a solid rectangle.
> I talked with Sam about this off-list, and he said that this looks really
> straightforward and there's no good reason why it should be behaving this
> way, and to ask you guys on here. So, does anyone have any reason why it
> should work this way? Here's the routine to draw the overlay; it gets
> called after the image is rendered, which is a simple call to
> procedure DrawShadedImage(const size: TPoint);
> dst: TRect;
> glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
> SDL_SetRenderDrawColor(imgDisplay.Renderer, 255, 64, 64, 130);
> //translucent light red
> dst := rect(0, 0, size.x, size.y);
> SDL_RenderFillRect(imgDisplay.Renderer, @dst);
> SDL_SetRenderDrawColor(imgDisplay.renderer, 255, 255, 255, 255)
> Sam and I suspect that the problem is in the image loading or converting
> code somewhere, that when given a 32-bit image it ends up creating a
> texture that doesn't like alpha blending somehow, but neither of us knows
> the graphics code well enough to be sure.
> Any ideas?
> SDL mailing list
> SDL at lists.libsdl.org
Calling "glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)" is potentially
useless because afterwards, when you call the SDL drawing functions, on
OpenGL the first thing they do is call GL_SetDrawingState, which
calls GL_SetBlendMode, which in turn may (and probably is) revert your
What I used to do before doing the SDL_RenderGeometry function, was to draw
a point at -1,-1 thus forcing SDL to a known internal state, then I changed
the blend function as you do. Then, when you call the draw function you
actually want, SDL won't touch the blend mode.
So, it may be worth a try to see what happens,after rendering the image,
call SDL_RenderDrawPoint, then call DrawShadedImage.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SDL