0
我有几个不同的3D元素,我想在不同的视图中使用OpenGL显示。如何使用iOS显示多个OpenGL ES 2.0视图?
我一直在玩这个代码< excellent tutorial>。当我只有一个元素可以使用单个视图显示时,情况显示得很好,但是如果我有多个元素,它只会显示一个元素。
IBOutlet UIView *openGL;
openGLA = [[OpenGLView alloc] initWithFrame:screenBounds Vertices:[self renderVertices:[self getBucketA]] Indices:[self renderIndices:[self getBucketA]]];
openGLZ = [[OpenGLView alloc] initWithFrame:screenBounds Vertices:[self renderVertices:[self getBucketZ]] Indices:[self renderIndices:[self getBucketZ]]];
[openGL addSubview:openGLA];
[openGL addSubview:openGLZ];
[openGLA render];
[openGLZ render];
[openGLA release];
[openGLZ release];
仅显示A或仅显示Z,但两者仅显示Z坐标最接近屏幕的显示内容。我确实明确规定事物不透明。
@interface OpenGLView : UIView
- (void)setupLayer
{
_eaglLayer = (CAEAGLLayer*) self.layer;
_eaglLayer.opaque = NO;
}
- (id)initWithFrame:(CGRect)frame Vertices:(NSMutableArray *)vertices Indices:(NSMutableArray *)indices
{
self = [super initWithFrame:frame];
if (self)
{
[self setupLayer];
[self setupContext];
[self setupDepthBuffer];
[self setupRenderBuffer];
[self setupFrameBuffer];
[self compileShaders];
[self setupVBOs];
}
return self;
}
- (void)render
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
CC3GLMatrix *projection = [CC3GLMatrix matrix];
float h = 4.0f * self.frame.size.height/self.frame.size.width;
[projection populateFromFrustumLeft:-2 andRight:2 andBottom:-h/2 andTop:h/2 andNear:4 andFar:10];
glUniformMatrix4fv(_projectionUniform, 1, 0, projection.glMatrix);
CC3GLMatrix *modelView = [CC3GLMatrix matrix];
[modelView populateFromTranslation:CC3VectorMake(0, 0, -7)];
[modelView rotateBy:CC3VectorMake(20, -45, -20)];
glUniformMatrix4fv(_modelViewUniform, 1, 0, modelView.glMatrix);
glViewport(0, 0, self.frame.size.width, self.frame.size.height);
glVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), 0);
glVertexAttribPointer(_colorSlot, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*) (sizeof(float) * 3));
glDrawElements(GL_TRIANGLES, indicesSize/sizeof(Indices[0]), GL_UNSIGNED_SHORT, 0);
[_context presentRenderbuffer:GL_RENDERBUFFER];
}
这些方法大部分都是直接从教程中得到,并且最小的不相关的修改(我认为)。
有什么我需要做的,以显示所有不同的意见?这种方法会起作用还是应该做其他事情?
终于找到了解决我的问题,当我获得的OpenGL更多的知识,我能够返工的东西,并把一切都在一个单一的视图,并把事情的工作就是我想要的。 – GRW 2012-09-05 17:34:37