我在纹理球体映射方面遇到了一些可怕的问题。
这是我的代码:
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);
}
vertexbuffer包含一个球体的点,而texturebuffer包含了法线,我遇到了一个可怕的结果,我不明白什么是错的......
结果是img:
http://img198.imageshack.us/img198/6370/failfs.png
我正在使用Android OpenGL ES,但我认为错误与我的平台无关,但与我使用OpenGL API有关,我是这个库的新手。