Pixel Format like GL_ALPHA8 for font rendering?


#1

Since OpenGL is going out of fashion I am evaluating to use the SDL2 2D Accelerated Rendering API since 2D is all I need. Until now I cache my fonts in OpenGL textures using format GL_ALPHA8.

I cannot find an equivalent pixel format in SDL_PixelFormatEnum. What’s the recommended format in this use case?

Greetings, chris


#2

OpenGL is going out of fashion? According to who? Only thing I’ve heard along those lines recently is that Apple, which has been straight-up hemorrhaging market share ever since Android got good enough to be a worthwhile alternative to iOS, is attempting to deprecate it on their platform and replace yet another well-established open standard with their own proprietary thing. This will only serve to generate more frustration and backlash from developers and drive even more people away from their platform so… don’t worry about it. Stick to OpenGL.

Mason


#3

Apple of course. The computer fashion company :slight_smile:
They have declared the OpenGL API deprecated on their platforms and whether I like it or not, I have to prepare for the situation that OpenGL gets removed from their platform, which I need to support.
I hoped that the SDL2 2D Accelerated Rendering API could give me all I need with it’s various backends to support several platforms and I need to write my graphics only once (again).

That’s what I would really like to do, everything is working fine in my code with OpenGL, but that’s not going to work long term :frowning_face:

chris


#4

If you’re just doing 2D, then don’t bother with OpenGL or Metal. Just let SDL2 handle everything in the background for you. SDL2 is a wrapper around DirectX, OpenGL, Metal, Vulkan, Android, iOS, and more. And if it doesn’t support it currently, give it time, (if it becomes popular enough to justify writing the backend for it).

GL_ALPHA8 is a way of telling OpenGL that you want a bit format with an alpha channel that is at least 8 bits. Most likely this is going to give you a 32 bit depth surface/texture. If that’s true then any of the SDL_PIXELFORMAT_XXXX8888 formats is probably what you’re going to need. You can check out the formats here: SDL_PixelFormatEnum

GL_ALPHA8 means “I explicitly want an 8-bit alpha texture”. GL_ALPHA means “I want an alpha texture, I don’t care how many bits, let the driver decide”. In practice it’s most likely going to be 8 on current hardware.


#5

Well there’s your problem. As long as developers fail to realize that Apple needs them more than they need Apple, they’ll continue giving Apple the leverage to pull more abusive stunts like this, to the detriment of everyone except Apple.


#6

I doubt Apple will be removing OpenGL any time soon (at least in the next 5 years, probably more). Feels like it’s more of a marketing move for metal. But sure, it’s possible that Apple is arrogant enough to actually do it. However, I think they would have to give another notice plenty of time beforehand, as a big portion of old games/graphics software would stop working. (Also if not many people migrate to metal early it should make the decision to remove OpenGL harder for them.)

While the SDL2 drawing API is quite enough for old school 2d games, not having shaders is really a non-starter for me, even for 2d stuff. So for a modern looking 2d game the solution would be to make your drawing code independent enough from other code, so that it’s easy to implement multiple drawing backends.

My game is 3d, but simple enough to work nicely on ~all platforms using OpenGL. So I’m not going to be adding another drawing backend just for Apple. Personally I will just drop Apple if they drop OpenGL, but obviously that is not an option for many people.


#7

I never thought about that. I believed it would be 1 byte per pixel. What a waste of texture memory. But if it works that way I can use RGBA32 like my other image textures for fonts also.
I guess I have to set the pixels to (1, 1, 1, alpha) when I upload my font image then.

Thanks, chris


#8

SDL_SetColorKey might be what you want then. Have a surface who’s format is: SDL_PIXELFORMAT_RGB332 and then set a Color Key to one of the colors. Granted, this is kind of binary as only one color at a time currently can be transparent.

This only works on surfaces though, and if you upload it to a texture, it’d become a 32 bit depth image anyways: Indexed color still around for SDL2?