OpenGL ES 1.1 wont render textures?

点点圈 提交于 2019-12-24 19:12:50

问题


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.

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;
}

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);  
}

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);
}

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();
}

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 =]


回答1:


Are you making any calls to glTexParameter anywhere, and are you creating mip maps? It could just be that the GPU is sampling a map you haven't supplied. What happens if you set MIN_FILTER to GL_NEAREST or GL_LINEAR?




回答2:


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.



来源:https://stackoverflow.com/questions/6246340/opengl-es-1-1-wont-render-textures

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!