问题描述
我想提出一个OpenGL ES 2.0的Android的传送带。我有为功能,在每次迭代中调用drawSquares功能,吸引广场转了一圈。即通过改变modelMatrix每一个新的正方形绘制时间完成。 (绘制平方我用同样的顶点和片段着色器)
I am making a OpenGL ES 2.0 android carousel. I have a "for" function that in each iteration calls "drawSquares" function that draws squares in a circle. That is done by changing the modelMatrix every time a new square is drawn. (For drawing the squares I use the same vertex and fragment shader)
我需要在正方形应用纹理,但对于每平方为具有不同的纹理。我似乎无法能够做到这一点。我试图调用之前drawSquare权改变手柄纹理数据的价值。
I need to apply textures on the squares, but for every square to have a different texture. I can't seem to be able to do this. I tried changing the value of the handle for the texture data right before the call drawSquare.
mTextureDataHandle = TextureHelper.loadTexture(context, item.getTexture());
但是,每一个广场上有相同的纹理。
But every square has the same texture.
有的可以提出建议,或者告诉我实现这个的最佳方式。我阅读有关OpenGL ES 2.0的约两个月了,但还是填补有很多事情我不明白。请帮忙,我就深深的AP preciate每一个建议。感谢ü!!!
Can some suggest something, or tell me the best way to implement this. I am reading about opengl es 2.0 for about two months now, but still fill that there are many things I don't understand. Please help, i would deeply appreciate every advice. Thank u!!!
推荐答案
开始的。你有几个选项 -
Start Here. You have a couple of options -
- glBindTexture - 每次将一个新的纹理到你的处理时间,你将不得不重新绑定
-
使用句柄的数组 - 你可以设置mTextureDataHandle起来为int [],填写好,然后每个纹理绑定到一个单独的GL纹理:
- glBindTexture - every time you load a new texture into your handle, you will have to bind it again
Use an array of handles - you can set mTextureDataHandle up as an int[], fill it in and then bind each texture to a separate GL Texture:
mTextureDataHandle[0] = ...; //Load textures - repeat for [1..N]
/*
* Select which GL texture spot to use - GL has 30 pointers to use, your device
* likely won't support that many
*/
GLES20.glSetActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GL_TEXTURE_2D, mTextureDataHandle[0]);
GLES20.glSetActiveTexture(GLES20.GL_TEXTURE1);
GLES20.gBindTexture(GL_TEXTURE_2D, mTextureDataHandle[1]);
//To draw with the right texture select which GL texture to point to (index):
GLES20.glUniform1i(mtextureUniformHandle, index);
drawStuff();
您将被设备所支持的纹理的数量限制在这里 - 用
You will be restricted here by the number of textures supported by your device - use
IntBuffer max = IntBuffer.allocate(1);
GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_IMAGE_UNITS, max);
Log.d("tag","Texture units: " + max.get());
或两个选项的一些组合 - 即通过让pre加载纹理数组保存加载处理器时间,但您可能需要绑定至少他们中的一些动态,以避免运行出可用的材质。
Or some combination of the two options - i.e. save processor time from loading by having an array of pre-loaded textures, but you may need to bind at least some of them on the fly to avoid running out of available textures.
这篇关于OpenGL ES 2.0的纹理加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!