gpt4 book ai didi

ios - 多视口(viewport) OpenGL ES

转载 作者:行者123 更新时间:2023-11-28 22:53:21 31 4
gpt4 key购买 nike

我目前正在尝试制作一个使用多个 opengl es 视口(viewport)(即分屏)的 ios 应用程序。这是我的做法:

// Create default framebuffer object. The backing will be allocated for the current layer in -resizeFromLayer
glGenFramebuffersOES(1, &defaultFramebuffer);
glGenRenderbuffersOES(1, &colorRenderbuffer);
glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, colorRenderbuffer);

// Replace the implementation of this method to do your own custom drawing
const GLfloat squareVertices[] = {
-0.5f, -0.5f,
0.5f, -0.5f,
-0.5f, 0.5f,
0.5f, 0.5f,
};
const GLubyte squareColors[] = {
255, 255, 0, 255,
0, 255, 255, 255,
0, 0, 0, 0,
255, 0, 255, 255,
};

[EAGLContext setCurrentContext:context];

glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
glViewport(0, backingHeight/2, backingWidth/2, backingHeight/2);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(-1.0f, 1.0f, -1.5f, 1.5f, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glRotatef(3.0f, 0.0f, 0.0f, 1.0f);

glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

glVertexPointer(2, GL_FLOAT, 0, squareVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors);
glEnableClientState(GL_COLOR_ARRAY);

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
// equivalent to glutswapBuffers()
[context presentRenderbuffer:GL_RENDERBUFFER_OES];

/*********************SECOND VIEW*******/
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glBindFramebufferOES(GL_FRAMEBUFFER_OES, defaultFramebuffer);
glViewport(backingWidth/2, 0, backingWidth/2, backingHeight/2);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(-1.0f, 1.0f, -1.5f, 1.5f, -1.0f, 1.0f);
glMatrixMode(GL_MODELVIEW);
glRotatef(3.0f, 0.0f, 0.0f, 1.0f);

glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

glVertexPointer(2, GL_FLOAT, 0, squareVertices);
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, squareColors);
glEnableClientState(GL_COLOR_ARRAY);

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

glBindRenderbufferOES(GL_RENDERBUFFER_OES, colorRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];
/*********************END***************/

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
  1. 在模拟器上,只显示第二个视口(viewport)(在本例中是屏幕右下角的旋转立方体)。而在设备上,它们都出现但在闪烁...(左上角和右下角)
  2. glRotatef 应用了两次,但我只想应用一次或任何其他转换。

我想要的只是将同一场景显示两次。基本上,我试图模拟让 2 个摄像头观看同一件事,并将其显示在屏幕上。显然,我做错了什么,拥有 2 个单独的帧缓冲区和渲染缓冲区会更好还是有更简单的方法来实现这一点?

最佳答案

问题是这一行:

/*********************SECOND VIEW*******/
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_FRAMEBUFFER);

glClear 不受视口(viewport)的影响,如果你想部分清除,你需要使用剪刀测试或模板缓冲区。

请参阅 glClear 的文档.

关于ios - 多视口(viewport) OpenGL ES,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11349506/

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