Android OpenGL ES 1.1 球体纹理映射问题
我在纹理球体映射方面遇到了严重的问题。
这是我的代码:
public void onSurfaceCreated(GL10 gl10, EGLConfig config) {
GL11 gl = (GL11) gl10;
gl.glDisable(GL10.GL_DEPTH_TEST); //Disable Depth Testing
gl.glEnable(GL11.GL_TEXTURE_2D);
gl.glEnable(GL11.GL_CULL_FACE);
gl.glCullFace(GL11.GL_FRONT);
gl.glFrontFace(GL11.GL_CCW);
sphere.loadGLTexture(gl10, context);
}
public void onDrawFrame(GL10 gl10) {
GL11ExtensionPack gl= (GL11ExtensionPack) gl10;
gl10.glMatrixMode(GL10.GL_PROJECTION);
gl10.glLoadIdentity();
gl10.glFrustumf(-5.0f, 5.0f, -5.0f, 5.0f, 1.0f, 100.0f); //Mio
gl10.glMatrixMode(GL10.GL_MODELVIEW);
gl10.glLoadIdentity();
GLU.gluLookAt(gl10, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -10.0f, 0.0f, 1.0f,0.0f);
sphere.draw(gl10);
}
public void onSurfaceChanged(GL10 gl, int width_, int height_) {
gl.glViewport(0, 0, width, height);
}
public void draw(GL10 gl10) {
GL11ExtensionPack gl = (GL11ExtensionPack) gl10;
GL11 gl11 = (GL11) gl10;
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures_ids.get(0));
gl10.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, totalVertexCount);
}
public void loadGLTexture(GL10 gl10, Context context) {
GL11 gl = (GL11) gl10;
gl.glGenTextures(2, textures_ids);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures_ids.get(0));
gl.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
gl.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_NEAREST);
gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE );
gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE );
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, this.image, 0);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL11.GL_FLOAT, 0, vertexBuffer);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0,textureBuffer);
}
顶点缓冲区包含球体的点,纹理缓冲区包含该点的法线,我遇到了一个可怕的结果,我不明白出了什么问题......
这是结果 img:
http://img198.imageshack.us/img198/6370/failfs.png
我正在使用 android OpenGL ES,但我认为错误与我的平台无关,但与我使用 OpenGL API 相关,我是这个库的新手。
I have a terrible issues with texure sphere mapping.
This is my code:
public void onSurfaceCreated(GL10 gl10, EGLConfig config) {
GL11 gl = (GL11) gl10;
gl.glDisable(GL10.GL_DEPTH_TEST); //Disable Depth Testing
gl.glEnable(GL11.GL_TEXTURE_2D);
gl.glEnable(GL11.GL_CULL_FACE);
gl.glCullFace(GL11.GL_FRONT);
gl.glFrontFace(GL11.GL_CCW);
sphere.loadGLTexture(gl10, context);
}
public void onDrawFrame(GL10 gl10) {
GL11ExtensionPack gl= (GL11ExtensionPack) gl10;
gl10.glMatrixMode(GL10.GL_PROJECTION);
gl10.glLoadIdentity();
gl10.glFrustumf(-5.0f, 5.0f, -5.0f, 5.0f, 1.0f, 100.0f); //Mio
gl10.glMatrixMode(GL10.GL_MODELVIEW);
gl10.glLoadIdentity();
GLU.gluLookAt(gl10, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -10.0f, 0.0f, 1.0f,0.0f);
sphere.draw(gl10);
}
public void onSurfaceChanged(GL10 gl, int width_, int height_) {
gl.glViewport(0, 0, width, height);
}
public void draw(GL10 gl10) {
GL11ExtensionPack gl = (GL11ExtensionPack) gl10;
GL11 gl11 = (GL11) gl10;
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures_ids.get(0));
gl10.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, totalVertexCount);
}
public void loadGLTexture(GL10 gl10, Context context) {
GL11 gl = (GL11) gl10;
gl.glGenTextures(2, textures_ids);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures_ids.get(0));
gl.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
gl.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_NEAREST);
gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE );
gl.glTexParameterf( GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE );
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, this.image, 0);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL11.GL_FLOAT, 0, vertexBuffer);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0,textureBuffer);
}
The vertexbuffer contains a points for a sphere and the texturebuffer contains the normals for that, I meet an horrible result and I don't understand what's wrong...
This is the result img:
http://img198.imageshack.us/img198/6370/failfs.png
I am working with android OpenGL ES but I think error isn't correlated with my platform but is correlated with my use of OpenGL API, I am a newbye with this library.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论