Drawing translucent images on OpenGL renderer fails

Let’s say I have a texture loaded, and I run the following:

SDL_SetRenderDrawColor(myRenderer, 255, 255, 255, 100);
SDL_SetRenderDrawBlendMode(myRenderer, SDL_BLENDMODE_BLEND);
SDL_RenderCopy(myRenderer, myTexture, rect1, rect2);

I would expect the image to be rendered at approximately 40% opacity.? Instead, it shows up at 100% opacity!

Looking through the code, it appears that this is because GL_SetDrawingState, which is in charge of calling glColor, is called for rendering lines and points, but not for rendering textures.

Mason

Don’t textures have their own blending mode?

2013/6/15, Mason Wheeler :> Let’s say I have a texture loaded, and I run the following:

SDL_SetRenderDrawColor(myRenderer, 255, 255, 255, 100);
SDL_SetRenderDrawBlendMode(myRenderer, SDL_BLENDMODE_BLEND);
SDL_RenderCopy(myRenderer, myTexture, rect1, rect2);

I would expect the image to be rendered at approximately 40% opacity.
Instead, it shows up at 100% opacity!

Looking through the code, it appears that this is because
GL_SetDrawingState, which is in charge of calling glColor, is called for
rendering lines and points, but not for rendering textures.

Mason

Does it do what you expect with a different renderer? I think the
SDL_SetTextureColorMod and SDL_SetTextureAlphaMod APIs would be what you
want.

Jonny D

sigh You’re right, of course.? Nevermind… x.x

Mason________________________________
From: Sik the hedgehog <sik.the.hedgehog at gmail.com>
To: Mason Wheeler <@Mason_Wheeler>; SDL Development List
Sent: Saturday, June 15, 2013 8:21 PM
Subject: Re: [SDL] Drawing translucent images on OpenGL renderer fails

Don’t textures have their own blending mode?

2013/6/15, Mason Wheeler <@Mason_Wheeler>:

Let’s say I have a texture loaded, and I run the following:

SDL_SetRenderDrawColor(myRenderer, 255, 255, 255, 100);
SDL_SetRenderDrawBlendMode(myRenderer, SDL_BLENDMODE_BLEND);
SDL_RenderCopy(myRenderer, myTexture, rect1, rect2);

I would expect the image to be rendered at approximately 40% opacity.
Instead, it shows up at 100% opacity!

Looking through the code, it appears that this is because
GL_SetDrawingState, which is in charge of calling glColor, is called for
rendering lines and points, but not for rendering textures.

Mason