Coding in C is very funny
You're programmer. You'd better debug your program, because "black screen" in OpenGL app can be caused by zillion different reasons. From our point of view we can only guess. And we don't like it.
My guess
(okay, sometimes we like to guess)
This:
FIBITMAP* temp = imagen;
imagen = FreeImage_ConvertTo32Bits(imagen);
FreeImage_Unload(temp);
Your temp
and imagen
points to same place, so after FreeImage_Unload(temp);
both points to... we don't know where. Then you get pixels from it:
char* pixeles = (char*)FreeImage_GetBits(imagen);
What does it returns? We don't' know. You don't check if pixels
exists after that.
Undefined behavior etc. It doesn't even crash.
Also, AFAIR, you cannot read and write at same dib
.
Instead do:
FREE_IMAGE_FORMAT formato = FreeImage_GetFileType("sample.png",0);
if(formato == FIF_UNKNOWN) { /* go angry here */ }
FIBITMAP* imagen = FreeImage_Load(formato, "sample.png");
if(!imagen ) { /* go very angry here */ }
FIBITMAP* temp = FreeImage_ConvertTo32Bits(imagen);
if(!imagen) { /* go mad here */ }
FreeImage_Unload(imagen);
imagen = temp;
(or just comment out all conversion stuff)
How to debug:
- Check for errors after loading and processing image. Does image loads at all?
- Check for OpenGL errors. Does everything go right there?
- In pixel shader, set output color to white, so you can be sure that your geometry is fine (what? you don't use shaders? =( )
- After texture loading, write it directly to
.raw
file (or in other format) and inspect it with bitmap editor
How to check for errors:
Carefully read the FreeImage documentation and tutorial samples. Look at error checking implementation. Basically, you will need to set callback function. Implement it. Set it. (Or at least copy-paste). Do same + glGetError()
for OpenGL.
Happy coding! =)
Edit: FreeImage have SwapRedBlue32()
helper function, so you don't need those for loop.