如何在平面上包裹两个纹理?我想我做到了,但是纹理填满了整个物体而不仅仅是我想要它的条子。
感谢任何帮助 〜Aedon
InputStream is = context.getResources().openRawResource(R.drawable.woodtexture1);
InputStream is2 = context.getResources().openRawResource(R.drawable.bandtest);
Bitmap bitmap = null;
Bitmap b2 = null;
try {
//BitmapFactory is an Android graphics utility for images
bitmap = BitmapFactory.decodeStream(is);
b2 = BitmapFactory.decodeStream(is2);
} finally {
//Always clear and close
try {
is.close();
is2.close();
is = null;
is = null;
} catch (IOException e) {}
}
//Generate one texture pointer...
gl.glGenTextures(1, textures, 0);
//...and bind it to our array
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
//Create Nearest Filtered Texture
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
//Different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_REPEAT);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_REPEAT);
//Use the Android GLUtils to specify a two-dimensional texture image from our bitmap
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
//Generate one texture pointer...
gl.glGenTextures(1, textures, 0);
//...and bind it to our array
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
//Create Nearest Filtered Texture
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
//Different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_ONE);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_ONE);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, b2, 0);
答案 0 :(得分:0)
我不确定这是否是您想要的 - 但如果您希望纹理仅覆盖对象的一部分,请使用glTexCoordPointer
为对象设置纹理坐标。
但是,实际绘制代码的一些示例会很棒。