简体   繁体   中英

Android OpenGL ES 2.0 Texture Animation

I'm new to OpenGL ES 2.0 and Android, and I'm trying to make a live wallpaper. I'm currently trying to use a texture atlas to create animations and changing textures. I've looked everywhere, and this tutorial is the most helpful thing I've found.

I understand how to load the texture atlas, but how would you change the texture object being rendered in the onDrawFrame method, so that it would be one square rendering the next texture every frame? What would the actual code look like?

Using what you have in that tutorial you can instead of filling up the uvBuffer (texCoord) buffer with random values, cycle through them each frame. So lets say you start with UV(0,0), UV(0.25, 0), UV(0, 0.25) and UV(0.25, 0.25). Next frame, you change the values in the uvBuffer to UV(0.25, 0), UV(0.5, 0), UV(0.25, 0.25), UV(0.5, 0.25). And so on.

Solution 1: Have a lookup array with all possible UV coordinates. Then use an int field to increase the step each frame. Put the next 4 items in a second array and replace the contents of the buffer.

Solution 2: Store the 4 UV coordinates in an array and one float field for x-coord, one for y-coord. Increase the x-coord by 0.25 each frame, the y-coord by 0.25 every 4 frames (or when the x-coord becomes 0.) replace the contents of the buffer with the uv-coords constructed from: x, x + 0.25, y, y + 0.25

You can either rebuild the enture buffer by clearing it, putting the array and rewinding it. Or you can use putFloat(int pos, float value) to replace existing entries in the buffer. The latter is likely more resource conservative.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM