I'm currently developing a GUI system for a 3D game I'm working on. I'm using instanced rendering for a pretty good compromise of speed and memory usage. Everything works well so far, I'm able to display multiple colored rectangles on the screen (up to 200k@60fps).
Now, I'm trying to add textures to be able to display characters, icons and framebuffer contents. That's where my problem occurs. I'm using FreeImage as the image loading library. The code which loads the image file and creates a OpenGL texture object is copied straight from another project.
When I try to display the texture, I only see a black rectangle on the screen. Note, that the code worked fine in the old project. The only case in which I see a colored box, is when I set the with and height passed to glTexImage2D
to 1
:
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_BGRA, GL_UNSIGNED_BYTE, (void*)bits)
Everything other than that does not work. There are no error codes generated by glGetError()
. I've also tried generating a random texture, which does not work either which sizes above 1x1:
float* data = new float[4 * 2 * 2 * 4]{
1.0f,0.3f,0.5f,1.0f,
0.0f,0.7f,0.5f,1.0f,
0.0f,0.5f,0.2f,1.0f,
0.0f,0.0f,0.0f,1.0f
};
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 2, 0, GL_RGBA, GL_FLOAT, (void*)data);
I'm using GLFW for the window and GLEW to enable using modern OpenGL. My IDE is VS2017 and I'm running Windows 10 64bit with the lates nVidia drivers for my GTX1060 (GL 4.6.0, 387.92). It would be nice if anyone could help since I've been searching my mistake for the last few days.
Complete texture loading code is available here. If any more information or code is needed, please leave a comment.