I want to make a Game Splash Screen using of course OpenGL and SDL, I searched how to make it, you know the first thing people do when they don't know how to do something? I didn't find shit about how to do it, apparently I'm the first in the world asking this. So I had the idea of simply drawing a image the size of the screen, because I'm running the game in fullscreen mode, and I found out about “BlitFramebuffer
”, here is the code I'm using for loading the Texture:
int channels = 0;
unsigned char* image = SOIL_load_image(path.c_str(), &mWidth, &mHeight, &channels, SOIL_LOAD_AUTO);
if (image == nullptr)
{
SDL_Log("SOIL failed to load image %s: %s", path.c_str(), SOIL_last_result());
return false;
}
int format = GL_RGB;
if (channels == 4)
{
format = GL_RGBA;
}
glGenTextures(1, &mTextureID);
glBindTexture(GL_TEXTURE_2D, mTextureID);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, mWidth, mHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
SOIL_free_image_data(image);
And to draw the BlitFramebuffer
:
GLuint fboID = 0;
glGenFramebuffers(1, &fboID);
glBindFramebuffer(GL_READ_FRAMEBUFFER, fboID);
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(0, 0, textureWidth, textureHeight, 0, 0, textureWidth, textureHeight, GL_COLOR_BUFFER_BIT, GL_LINEAR);
It works, despite the image being drawn upside down (simple to solve, just use some image editor and flip the image) and the alpha being drawn as black for some reason, something that I also didn't found shit about. But ok I guess.
The other thing some Splash Screens in games have is the fading effect, it should be something simple as changing the alpha, but apparently it isn't, I didn't found shit about how to do it even less because I'm using “BlitFramebuffer
”, I found out about using shader and quads, but I don't want to use shaders if possible. But this is the way I tried, I don't know if there is another ways.