Android NDK OpenGL texture tutorial - Skin Investigation

Android NDK OpenGL texture tutorial

ETC1 textures loading and alpha handling with Android NDK

The drawback is that textures in its compressed form are bigger than .jpg or .png files with the same image, so more disk space will be consumed. Further in the article I will also describe way how I solved it.

Creating ETC1 texture

Every GPU vendor has its own set of tools including tool for compressing textures. I am using tool from ARM. After you run the tool you will get initial screen. Open image file with you texture (do not forget that open GL ES needs height and width to be power of 2) and you should get screen like this:
Select the texture(s) in left panel and press "Compress" icon. The compression parameters panel will pop up:
Choose ETC1/ETC2 tab (1.) and select PKM as output format. PKM is very simple format that ads small header to compressed data. The header is this:

+0: 4 bytes header "PKM "
+4: 2 bytes version "10"
+6: 2 bytes data type (always zero)
+8: 2 bytes extended width
+10: 2 bytes extended height
+12: 2 bytes original width
+14: 2 bytes original height
+16: compressed texture data

In ETC1 format each 4x4 pixel bloc is compressed into 64 bits. So the extended width and height are the original dimensions rounded up to multiple of four. If you are using power of 2 textures then the original and extended dimensions are the same.

From these parameters you can calculate the size of compressed data like this:

(extended width / 4) * (extended height / 4) * 8

This formula just says: there is so many 4x4 pixel blocks and each of them is 8 bytes long (64 bits).

Parameters marked 2. and 5. on the picture will affect quality of compression. The compression takes quite a lot of time. So during development you can use worse quality if you do not want to wait. But be sure that when finishing your game you use maximum quality - the size of output remains the same.

Under 3. do not forget to check that ETC1 is chosen and udder 4. choose to create separate texture for alpha channel. This texture will have the same dimensions as the original one. But in the red channel of it there will be stored alpha instead of color. The green and blue channels are unused so theoretically you can put any additional information there (but not with the tool - it would be up to you how to do it).

Loading ETC1 texture

Now when you have the texture compressed it is time to load it into GPU.

//------------------------------------------------------------------------ u16 TextureETC1::swapBytes(u16 aData) { return ((aData & 0x00FF) < 8) | ((aData & 0xFF00) > 8); } //------------------------------------------------------------------------ void TextureETC1::construct(SBC::System::Collections::ByteBuffer& unpacked) { // check if data is ETC1 PKM file - should start with text "PKM " (notice the space in the end) // read byte by byte to prevent endianness problems u8 header[4]; header[0] = (u8) unpacked.getChar; header[1] = (u8) unpacked.getChar; header[2] = (u8) unpacked.getChar; header[3] = (u8) unpacked.getChar; if (header[0] != 'P' || header[1] != 'K' || header[2] != 'M' || header[3] != ' ') LOGE("data are not in valid PKM format");

swapBytes is just help method the real work is done in construct method. ByteBuffer is our simple wrapper around array of bytes holding not only data but also its size. This is not important here it just increases readability.

More about Android NDK OpenGL texture tutorial

Alias Maya 3D Rendering

by whasaa

Here is a short list of my Maya Collection if you like any of these email me at Each DVD/CD $10.00 for download only.
Alias Maya Digital Tutors Fundamentals DVD
Alias Maya Gnomon Rendering DVD
Alias Maya Gnomon Texture Painting Fundamentals 2DVDS
Alias Maya Gnomon Texture Painting Weathered Surfaces 2DVDS
Alias Maya Enoble Tutorials 2DVDS
Alias Maya Understanding Fluid Effects CD
Alias Maya Techniques Exploring Particles CD
Alias Maya Techniques Rig Body Simulations For Visual Effects CD
Alias Maya Techniques Using Mental Ray CD

CorelDRAW X7 review: Customizable features make this robust design program ..  — PCWorld
.. purchase, as well as a $25 monthly subscription. People miffed by Adobe's wholesale move to subscriptions will find a great alternative here. ..

Galaxy 61 Delivers Show Open for VH1's 'The Fabulous Life  — Animation World Network
VHI recently called upon Galaxy 61 to create a show intro for the new 2014 season of The Fabulous Life, the hit series that reveals the extravagant places, possessions and pastimes of pop-culture's most famous celebrities. The Brooklyn-based ..

Class on Demand,Inc. Class on Demand: After Effects Apprentice 301 Online Streaming Educational Training Tutorial with Chris & Trish Meyer, 99926
Photography (Class on Demand,Inc.)
  • Are You Ready to Tackle Visual Effects Jobs and Start Creating Your Own Graphical Elements from Scratch?
  • 5 Lessons For the Advanced Intermediate After Effects Apprentice
  • Arm Yourself With the Tools to Create Powerful and Appealing Digital Motion Graphics

Hunterdon County Polytech students bridge the gap thanks to local Rotary Clubs  — Hunterdon County Democrat
This year's Job Fair, on March 25, attracted the Dave Gansfuss Allstate Agent for an agency logo; G&H Publishing and author Katherine Kurz for children's book illustrations; Artiste Salon for a new logo, brochure and social media materials; St.

Nintendo Mischief Makers
Video Games (Nintendo)
  • Puzzle/action starring a robotic cleaning maid named Marina on a mission to rescue her kidnapped creator from the clutches of an evil emperor.
  • 60 stages filled with challenging puzzles, Vast array of characters and enemies, Simple controls, Variety of items and moves
  • Players: 1
Class on Demand Class on Demand Complete Training for Red Giant Trapcode Particular 2 Educational Training Tutorial DVD with Harry Frank 99901
Photography (Class on Demand)
  • Explore Emitter Types and Functions In-depth Through This Series of Informative and Project-Focused Lessons
  • Learn To Use Particular in New and Interesting Ways
  • Over 6 Hours of Expert Training with Harry J. Frank
Related Posts