Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello readers. Here I am with another problem. I learnt Win32 and OpenGL programming. I found that bitmaps can be stored in resource scripts for easy and quick access. I also know how to create a texture in OpenGL by loading an image from a file. But can we generate an OpenGL texture from the image in resource scripts. Please let me know if anyone of you guys knows the code for this. Thanks for reading.

What I have tried:

Searching on Google provided a lot of answers but none was suitable and easy.
Posted
Updated 7-Sep-20 7:42am

1 solution

If you know how to load a file and make a usable texture from it then you are almost all the way there. To access a texture resource, call LoadBitmap. From there, follow similar steps to what you did with the file's texture. Both methods should result in an HBITMAP that OpenGL can use.

If that description is too vague then hopefully this sample app can help : 50 OpenGL Win32 Projects in One[^]
 
Share this answer
 
Comments
VD-Flash 7-Sep-20 13:53pm    
Thank you for the above link. It will be quite useful for me. But as you said above I can load an image using LoadBitmap and receive a HBITMAP handle and convert it into texture as I regularly do. But is a HBITMAP data type acceptable by glTexImage2D? Because I usually load the image from file using the pre built stb_image library which returns a unsigned char* data type which can be used in the last parameter of glTexImage2D.
Rick York 7-Sep-20 14:05pm    
Have a look at this function : https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getbitmapbits

There are set of functions in that family, linked to at the bottom of the page, that can be helpful.
VD-Flash 7-Sep-20 14:14pm    
Thanks for the link. It works fine. 😀
Rick York 7-Sep-20 15:47pm    
Please remember to mark your question as "answered" so it is removed from the active list.
VD-Flash 7-Sep-20 15:52pm    
OK

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900