-
Notifications
You must be signed in to change notification settings - Fork 313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SDL2 fails to display image files with no alpha channel #239
Comments
Hi, and thanks for reporting this. I do see the same issue when testing this on my end. Not sure what SDL is doing here, normally OpenGL attaches 1 to the alpha channel, so it should work perfectly fine with blending. I did also test your changes but it didn't help on my end, I only get white even with blending completely disabled. So I think there is something else going on. I'm not too familiar with the SDL API, I would try to bring out a graphics debugger at this point. |
I have a few images still showing white boxes as well. The blend disable only worked on a couple images for me, so it's a hack. From what you said, "didn't help on my end", I'm guessing this is more of an OpenGL issue, or the states SDL may have changed. I'm at latest SDL version 2.0.16. I'll roll back to an earlier version see if I can find the suspect. |
If you do figure this one out, a PR would be very welcome :) |
Can you send a couple image files that are not displaying on your end. I recompiled my code base with the latest SDL2 and SDLImage, now all of my images are working with just that conditional blend fix. |
I'm on a new machine now, and I can't reproduce it here. I seem to be getting correct results with your proposed changes now. Soo, I don't know. Did you try a graphics debugger to look at the states without the fix? Only semi-related, but I also just noticed that I'm getting crashes whenever there are more than one image loaded. Eg. try replacing <rml>
<head>
<title>Demo</title>
<!--link type="text/template" href="window.rml" /-->
<style>
body
{
width: 300dp;
height: 225dp;
margin: auto;
font-family: LatoLatin;
font-weight: normal;
font-style: normal;
font-size: 15dp;
color: white;
}
div#title_bar div#icon
{
display: none;
}
div#content
{
text-align: left;
}
</style>
</head>
<body>
This is a sample.
<img src="high_scores_alien_1.tga"/>
<img src="high_scores_alien_2.tga"/>
</body>
</rml> |
Yea.. i'll check the graphics debug today actually and see if I can reproduce it. |
I've found that modifying ...
SDL_Surface* Surface = IMG_LoadTyped_RW(SDL_RWFromMem(Buffer, int(BufferLen)), 1, FileExt.c_str());
if (!Surface)
{
return false;
}
// Fix for 24-bit images (ie. no alpha channel) not rendering
SDL_Surface* ConvertedSurface = SDL_ConvertSurfaceFormat(Surface, SDL_PixelFormatEnum::SDL_PIXELFORMAT_RGBA32, 0);
if (!ConvertedSurface)
{
return false;
}
SDL_Texture* Texture = SDL_CreateTextureFromSurface(Renderer, ConvertedSurface);
...
SDL_FreeSurface(ConvertedSurface);
SDL_FreeSurface(Surface); |
Nice. I'll toss that in and throw some images at it on my end. Besides some animated gif frames, the small fix I had earlier seems to be doing the trick for me at the moment. I used GLIntercept to debug the OpenGL context calls, but I didn't notice any errors related to the blend states on the textures. I think GL is just accepting the processing as valid or intentional. Tested on windows7 x86/x64, windows10 x86/x64, MacOs 11.5.2 x64, Linux Lxle x32 & x64, Raspbery Pi 4 arm32. GLIntercept is a bit dated so I'm trying to get RenderDoc up and debugging, but It always complains about lack of a 3.2+ context. Original Code: OpenGL context will always be reset to version 2.1 by call to SDL_CreateRenderer()
The fix for this was to actually, create the Window and Renderer first New Code: OpenGL context version can be set After SDL_CreateRenderer() with SDL_GL_CreateContext() last
This can have implications on available GL extensions, shader version and which context pipeline functions SDL is using for GL. When I use a proper context version, I no longer need glew extensions to turn off shaders, as SDL has then built in. RmlRenderer.cpp
I guess the real motivation here is to rework the SDL example. I've taken a look at 1bysl's PR #252 using SDL_RenderGeometry() and it looks promising. When more time is available, I'll be able to work up some more solid code and test across all OS's. Any snippets of code or info to help the process is more than welcome :) |
Wow, quite the journey! Thanks for the deep dive into this. Looking forward to the reworked SDL sample, having a solid SDL backend would mean a lot. Here are some thoughts and ideas/wishlist:
Certainly not saying these suggestions need to be part of this work, just dumping my thoughts here for now :) I can't really contribute anything meaningful SDL-specific. Although let me know if I can contribute with OpenGL later on. |
It would be great to have another look and solve this now that we have merged the backends branch. So now we essentially have three SDL backends with different renderers: I'm only having this issue on the SDL/GL2 backend. It would be really nice if we could also remove the dependency on GLEW here. Could you help with this? I didn't even add an SDL_Renderer to the SDL/GL3 backend, there I am only using SDL to open and handle the window and provide input, as well as image loading. Here I decided to use surface blitting to ensure correct texture color channels. |
I made a fix for this for the SDL_GL2 backend, so RGB-textures should now work for all the SDL backends. I went with a variation of the suggestion from @RWD-Biggs, except I'm only converting the surface if no alpha channel is detected. I'm closing this and consider the issue fixed. With that said, I'll still happily take contributions to further improve the SDL backend(s) as discussed. |
Started messing around with RML again and I noticed something changed in SDL_Image that breaks Image files without alpha data. It's just a small fix, but worth a mention to anyone using SDL.
For some reason, calling glBlend states on a graphic with no alpha channel results in "white out" textures. I tested it out on the RmlUi sdl2 example and found the same results. BMP and JPG files will no work with the original implementation.. I'm not an OpenGL guy, but I found that, if you check the texture blend mode, turning off glBlend for such images will allow them to display again..
The issue lands on RML's side for this, because the texture is loaded just fine, yet, the RML example fails to show the image.
I can do a pull request if needed, but i'd like to do some more tests.
The text was updated successfully, but these errors were encountered: