gpt4 book ai didi

Android OpenGL 只渲染一半的屏幕

转载 作者:行者123 更新时间:2023-11-30 04:49:41 24 4
gpt4 key购买 nike

我遵循了一个 opengl 应用程序的示例,但我不知道为什么会发生这种情况...

我有一个 GLSurfaceView,它对应的渲染器绘制了一个三角形。但是,我没有在屏幕上看到整个 View ,我只有上半部分,而且它也被复制了,正如你在图片上看到的那样。我正在使用 Nexus One alt text

xml:

<?xml version="1.0" encoding="utf-8"?>
<com.forgottenprojects.geoturista.DrawingLayer
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawing"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

Activity 在 list 中有这个:

android:theme="@android:style/Theme.NoTitleBar.Fullscreen"

DrawingLayer 类:

public class DrawingLayer extends GLSurfaceView {
private TriangleRenderer renderer;
private Context context;
public DrawingLayer(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
public DrawingLayer(Context context) {
super(context);
init(context);
}
private void init(Context c)
{
this.context = c;
setEGLConfigChooser(false);
this.renderer = new TriangleRenderer(c);
setRenderer(renderer);
setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
getHolder().setFormat(PixelFormat.TRANSLUCENT);
}
}

三角形渲染器(大部分来自 Apress Pro Android 2 书)

public class TriangleRenderer implements Renderer {
private final static int VERTS = 3;
private FloatBuffer mFVertexBuffer;
private ShortBuffer mIndexBuffer;

TriangleRenderer(Context context)
{
ByteBuffer vbb = ByteBuffer.allocateDirect(VERTS * 3 * 4);
vbb.order(ByteOrder.nativeOrder());
mFVertexBuffer = vbb.asFloatBuffer();
ByteBuffer ibb = ByteBuffer.allocateDirect(VERTS * 2);
ibb.order(ByteOrder.nativeOrder());
mIndexBuffer = ibb.asShortBuffer();
float[] coords = {
-0.5f, -0.5f, 0, // (x1,y1,z1)
0.5f, -0.5f, 0,
0.0f, 0.5f, 0
};
for (int i = 0; i < VERTS; i++) {
for(int j = 0; j < 3; j++) {
mFVertexBuffer.put(coords[i*3+j]);
}
}
short[] myIndecesArray = {0,1,2};
for (int i=0;i<3;i++)
{
mIndexBuffer.put(myIndecesArray[i]);
}
mFVertexBuffer.position(0);
mIndexBuffer.position(0);
}
protected void draw(GL10 gl)
{
gl.glColor4f(1.0f, 0, 0, 0.5f);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mFVertexBuffer);
gl.glDrawElements(GL10.GL_TRIANGLES, VERTS,
GL10.GL_UNSIGNED_SHORT, mIndexBuffer);
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
gl.glDisable(GL10.GL_DITHER);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_FASTEST);
gl.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glEnable(GL10.GL_DEPTH_TEST);
}
@Override
public void onDrawFrame(GL10 gl) {
gl.glDisable(GL10.GL_DITHER);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glClearColor(1.0f, 0.5f, 0.7f, 1.0f);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1f, 0f);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
draw(gl);
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL10.GL_PROJECTION);
float ratio = (float)width / (float)height;
gl.glLoadIdentity();
gl.glFrustumf(-ratio, ratio, -1, 1, 3, 7);
}
}

提前致谢!

最佳答案

它适用于

setEGLConfigChooser(8,8,8,8,4,4);

但我不知道如何在它后面应用透明度(因为还有另一个带有相机 View 的表面 View )

关于Android OpenGL 只渲染一半的屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3883793/

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