OpenGL ES 1.1不会渲染纹理吗? [英] OpenGL ES 1.1 wont render textures?

查看:115
本文介绍了OpenGL ES 1.1不会渲染纹理吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对,我提出了类似的问题,我尝试完全重建文件,现在发生的情况是纹理根本无法渲染.图片为512x512.由于某种原因,纹理只能在模拟器上使用,而不能在我的iPod上使用.

Right, I posted a similar question, Ive tried completely rebuilding the files and what happens now is textures aren't rendering at all. The image is 512x512. For some reason the texture works on simulator but not my iPod.

在名为EAGLView的类中,有beginDraw和finishDraw,它们在我的游戏循环的开始和结束时被调用.创建视图时会调用布局子视图.

In a class called EAGLView there is, beginDraw and finishDraw which are called at the beggining and end of my game loop. Layout subviews is called when I create the view.

-(void)beginDraw
{
    // Make sure that you are drawing to the current context
    [EAGLContext setCurrentContext:context];
    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
    // make sure we are in model matrix mode and clear the frame
    glMatrixMode(GL_MODELVIEW);
    glClear(GL_COLOR_BUFFER_BIT);
    // set a clean transform
    glLoadIdentity();   
}

-(void)finishDraw
{
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
    [context presentRenderbuffer:GL_RENDERBUFFER_OES];  
}

- (void)layoutSubviews 
{
    [EAGLContext setCurrentContext:context];
    [self destroyFramebuffer];
    [self createFramebuffer];
    [self setupViewLandscape];
}

- (BOOL)createFramebuffer {    
    glGenFramebuffersOES(1, &viewFramebuffer);
    glGenRenderbuffersOES(1, &viewRenderbuffer);

    glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
    glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);

    [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(CAEAGLLayer*)self.layer];
    glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);

    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
    glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);

    if (USE_DEPTH_BUFFER) {
        glGenRenderbuffersOES(1, &depthRenderbuffer);
        glBindRenderbufferOES(GL_RENDERBUFFER_OES, depthRenderbuffer);
        glRenderbufferStorageOES(GL_RENDERBUFFER_OES, GL_DEPTH_COMPONENT16_OES, backingWidth, backingHeight);
        glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_DEPTH_ATTACHMENT_OES, GL_RENDERBUFFER_OES, depthRenderbuffer);
    }

    if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
        NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
        return NO;
    }

    return YES;
}

我的TexturedQuad渲染方法是

My texturedQuad render method is

-(void)render
{
    glVertexPointer(vertexSize, GL_FLOAT, 0, vertexes);
    glEnableClientState(GL_VERTEX_ARRAY);
    glColorPointer(colorSize, GL_FLOAT, 0, colors); 
    glEnableClientState(GL_COLOR_ARRAY);    

    if (materialKey != nil) {
        [[MaterialController sharedMaterialController] bindMaterial:materialKey];

        glEnableClientState(GL_TEXTURE_COORD_ARRAY); 
        glTexCoordPointer(2, GL_FLOAT, 0, uvCoordinates);
    } 
    //render
    glDrawArrays(renderStyle, 0, vertexCount);  
}

这也是bindMaterial方法:

Also here is the bindMaterial method:

-(void)bindMaterial:(NSString*)materialKey 
{
    NSNumber *numberObj = [materialLibrary objectForKey:materialKey];
    if (numberObj == nil) return;
    GLuint textureID = [numberObj unsignedIntValue];

    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, textureID);
}

渲染我的sceneObject时会调用它: (TexturedQuad是网格的子类)

It is called when my sceneObject is rendered: (TexturedQuad is a subclass of mesh)

-(void)render
{
    if (!mesh || !active) return; // if we do not have a mesh, no need to render
    // clear the matrix
    glPushMatrix();
    glLoadIdentity();
    glMultMatrixf(matrix);
    [mesh render];  
    glPopMatrix();
}

最后是我的Test课: 将对象添加到场景中时,将唤醒被唤醒

And lastly my Test class: Awake is called when the object is added to the scene

-(void)awake
{
    self.mesh = [[MaterialController sharedMaterialController] quadFromAtlasKey:@"boxNotSelected"];
    self.scale = BBPointMake(50.0, 50.0, 1.0);
}

感谢您抽出宝贵的时间阅读本文档,并感谢您提供任何帮助=]

Thanks for taking your time to read this and thanks if you offer any help =]

推荐答案

即使我的纹理在侧面的文件管理器中以及在代码中都被称为menuAtlas,但答案仍然是正确的,因此无法同时进行更改到mA工作了.我不明白为什么,但是我怀疑它与缓存有关.

Answer turned out to be the even though my texture was called menuAtlas both in the file manager at the side and in the code it wouldn't work so changing both to mA worked. I don't understand why but I have a suspicion that it involves something to do with caching.

这篇关于OpenGL ES 1.1不会渲染纹理吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆