Part1. C++ OpenGL game in Android Studio. Question: How to load texture from png file?

558 views
Skip to first unread message

Evgen Chigir

unread,
Oct 31, 2023, 11:29:37 AM10/31/23
to android-ndk
Hello!

2 month ago I've started writing 2D game using C++ in Android Studio.
I use NDK (native developer kit):
    OpenGL ES (use texture shader to draw fast images)
    I wrote minimal C++ code  in one file (handle touch event, render graphic 50 times per second)
    I don't have any Java code.

So, I have minimal C++ code to make game and drawing images very fast.
My game looks like:

my_game_for_google_discussion.png

Question:
I have bmp files in assets.
And bmp file size is big. 100 px x 100 px with 3byte for color = 30 kb
If 20 pictures with 100 x 100 = 600 kb

Please tell me is exist any way to load texture from png file using C++?
Thank you

yu...@unity3d.com

unread,
Nov 1, 2023, 5:03:16 AM11/1/23
to android-ndk
(I'm not an expert here, just pointing at a direction)
I guess you can't upload PNG onto the GPU so conversion would be needed anyway. Maybe http://www.libpng.org/pub/png/libpng.html can help you with this.

However, if you want to look into compressed textures - there are directly-GPU-supported formats (ETC2, ASTC, ...). What you could do is convert your BMP textures into one of these and load them instead. There are free converters available:
Compression rate depends on quality settings.

Keep in mind that compressed textures degrade visual quality. In some cases you better keep them uncompressed.

Another possible direction: do you really need 24-bit RGB for your textures? can you get away with 4 bits per channel instead of 8?

Good luck with your game!

Evgen Chigir

unread,
Nov 1, 2023, 10:34:21 AM11/1/23
to android-ndk
Thank you  for C++ libpng library. I've investigated that this library with loading png images and theoretically I can use it. I will download it.

It was also interesting to read about compression textures because this also will be solution for me if reading png file will take long processor time.

By the way, your idea not use 24-bit RGB also good. In OpenGL in function glTexImage2D  when I create texture  I can use  4 bits per channel or 5 red, 6 green, 5 blue.

I think game graphic it is the most important thing in the game.

My graphic hope not very bad
djin_for_google_discussion2.png

Question 1:
Maybe need add lightning from hands for djin?

Question 2:
I draw each square 100 x 100 pixels. I have in one image 5 sprites and total size is 150 kb as bmp.
If I will use png maybe for good quality in game I should draw images for 1 sprite as 200 x 200 pixels?

среда, 1 ноября 2023 г. в 12:03:16 UTC+3, yu...@unity3d.com:
Reply all
Reply to author
Forward
0 new messages