gpt4 book ai didi

Android 模拟器 vs 手机 opengl 不一致

转载 作者:行者123 更新时间:2023-11-30 04:46:01 33 4
gpt4 key购买 nike

我遇到了一个问题,我的应用程序在我的模拟器上看起来是正确的,但在我的手机上它只显示了我的场景的一个 fragment 。

图片 here (右边是模拟器。

我的渲染器代码在这里。 (这个类是抽象的,但所有实现类所做的就是绘制多边形)

public abstract class AbstractRenderer implements Renderer {
float x = 0.5f;
float y = 1f;
float z = 3;

boolean displayCoordinateSystem = true;

public void onSurfaceCreated(GL10 gl, EGLConfig eglConfig) {
gl.glDisable(GL10.GL_DITHER);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
gl.glClearColor(.5f, .5f, .5f, 1);
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glEnable(GL10.GL_DEPTH_TEST);
}

public void onSurfaceChanged(GL10 gl, int w, int h) {
gl.glViewport(0, 0, w, h);
float ratio = (float) w / h;
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
gl.glFrustumf(-ratio, ratio, -1, 1, 0, 10);
}

public void onDrawFrame(GL10 gl) {
gl.glDisable(GL10.GL_DITHER);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
GLU.gluLookAt(gl, x, y, z, 0f, 0, 0f, 0f, 1f, 0f);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);

if(displayCoordinateSystem) {
drawCoordinateSystem(gl);
}

draw(gl);

// gl.glFlush();
}

private void drawCoordinateSystem(GL10 gl) {
ByteBuffer vbb = ByteBuffer.allocateDirect(6*3*4);
vbb.order(ByteOrder.nativeOrder());
FloatBuffer vertices = vbb.asFloatBuffer();

ByteBuffer ibb = ByteBuffer.allocateDirect(6*2);
ibb.order(ByteOrder.nativeOrder());
ShortBuffer indexes = ibb.asShortBuffer();

final float coordLength = 27f;

//add point (-1, 0, 0)
vertices.put(-coordLength);
vertices.put(0);
vertices.put(0);

//add point (1, 0, 0)
vertices.put(coordLength);
vertices.put(0);
vertices.put(0);

//add point (0, -1, 0)
vertices.put(0);
vertices.put(-coordLength);
vertices.put(0);

//add point (0, 1, 0)
vertices.put(0);
vertices.put(coordLength);
vertices.put(0);

//add point (0, 0, -1)
vertices.put(0);
vertices.put(0);
vertices.put(-coordLength);

//add point (0, 0, 1)
vertices.put(0);
vertices.put(0);
vertices.put(coordLength);

for(int i = 0; i < 6; i++) {
indexes.put((short)i);
}

vertices.position(0);
indexes.position(0);

gl.glColor4f(1, 1, 0, 0.5f);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertices);
gl.glDrawElements(GL10.GL_LINES, 2, GL10.GL_UNSIGNED_SHORT, indexes);

indexes.position(2);
gl.glColor4f(0, 1, 0, 0.5f);
gl.glDrawElements(GL10.GL_LINES, 2, GL10.GL_UNSIGNED_SHORT, indexes);

indexes.position(4);
gl.glColor4f(0, 0, 1, 0.5f);
gl.glDrawElements(GL10.GL_LINES, 2, GL10.GL_UNSIGNED_SHORT, indexes);
}

protected abstract void draw(GL10 gl);
}

我的猜测是我没有设置一些由模拟器实现默认设置的值。唯一的问题是我不知道那东西可能是什么。

希望收到你们的消息!

最佳答案

这是一个深度缓冲区问题:来自 glFrustum 的手册页中的“注释”部分:

near must never be set to 0.

您应该计算 near 值尽可能远离相机,far 值尽可能接近,同时仍然包含您想要绘制的东西。

关于Android 模拟器 vs 手机 opengl 不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4945977/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com