UV 贴图的 OpenGL-ES 纹理加载问题
我在 openGL-ES 纹理方面遇到了一些问题。我在 3ds max 中创建了一个模型并为其使用了 UV 贴图,如您所见 这里(第一张图片)是我的 UV 贴图。 如果没有 UV 贴图,我的纹理加载是“完美的”,但是使用 UV 贴图...(第二张图片 这里),看看转向架)。
我从 obj 文件加载这个模型(转向架),我的代码或 obj 没有任何问题,因为它正在处理简单的纹理,也许我的 loadtexture 方法不好,请检查它,或者你有任何问题吗?有想法吗? 谢谢你的回答,我没有想法了。
Loadtexture 代码:
private int[] textures = new int[3];
public void loadtexture(GL10 gl, Context mContext, String map_source) {
try {
InputStream is = mContext.getAssets().open(map_source);
Bitmap bitmap = BitmapFactory.decodeStream(is);
is.close();
gl.glGenTextures(3, textures, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
GL10.GL_NEAREST);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[1]);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
GL10.GL_LINEAR);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[2]);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
GL10.GL_LINEAR_MIPMAP_NEAREST);
if (gl instanceof GL11) {
gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_GENERATE_MIPMAP,
GL11.GL_TRUE);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
} else {
buildMipmap(gl, bitmap);
}
bitmap.recycle();
} catch (IOException e) {
// Should never happen
}
}
private void buildMipmap(GL10 gl, Bitmap bitmap) {
//
int level = 0;
//
int height = bitmap.getHeight();
int width = bitmap.getWidth();
//
while (height >= 1 || width >= 1) {
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, level, bitmap, 0);
//
if (height == 1 || width == 1) {
break;
}
// Increase the mipmap level
level++;
//
height /= 2;
width /= 2;
Bitmap bitmap2 = Bitmap.createScaledBitmap(bitmap, width, height,
true);
// Clean up
bitmap.recycle();
bitmap = bitmap2;
}
}
PS 抱歉我的英语。
Hy I have a little problem in openGL-ES texturing. I created a modell in 3ds max and used UV map for it, as you can see here(1st. picture) there is my UV map.
Without UV mapping my texture loading is "perfect", but with UV maps...(2nd picture here), look at the bogie).
I load this modell(bogie) from an obj file, there isn't any problem with my code or with the obj, because it is working with simple textures, maybe my loadtexture method is bad, pls check it, or do you have any Ideas?
Thanks for your answers, I'm out of ideas.
Loadtexture code:
private int[] textures = new int[3];
public void loadtexture(GL10 gl, Context mContext, String map_source) {
try {
InputStream is = mContext.getAssets().open(map_source);
Bitmap bitmap = BitmapFactory.decodeStream(is);
is.close();
gl.glGenTextures(3, textures, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
GL10.GL_NEAREST);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
GL10.GL_NEAREST);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[1]);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
GL10.GL_LINEAR);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[2]);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
GL10.GL_LINEAR_MIPMAP_NEAREST);
if (gl instanceof GL11) {
gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_GENERATE_MIPMAP,
GL11.GL_TRUE);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
} else {
buildMipmap(gl, bitmap);
}
bitmap.recycle();
} catch (IOException e) {
// Should never happen
}
}
private void buildMipmap(GL10 gl, Bitmap bitmap) {
//
int level = 0;
//
int height = bitmap.getHeight();
int width = bitmap.getWidth();
//
while (height >= 1 || width >= 1) {
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, level, bitmap, 0);
//
if (height == 1 || width == 1) {
break;
}
// Increase the mipmap level
level++;
//
height /= 2;
width /= 2;
Bitmap bitmap2 = Bitmap.createScaledBitmap(bitmap, width, height,
true);
// Clean up
bitmap.recycle();
bitmap = bitmap2;
}
}
P.S. Sorry for my english.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以我垂直翻转了它,因为加载地图在 opengl 中有点不同。我希望我能帮助那些遇到同样问题的人。
So I've flipped it vertically because loading maps is little bit diffrent in opengl. I hope that I helped some1 who get in to trouble with the same problem.