Opengl es 为什么我的OpenGL ES纹理不能正确渲染?

Opengl es 为什么我的OpenGL ES纹理不能正确渲染?,opengl-es,render,Opengl Es,Render,我正在使用OpenGL制作一个我正在尝试制作的应用程序。我一直在学习一本关于iPhone游戏开发的书 我的问题是,我的网格类的子类texturedQuad似乎无法正确渲染。(虽然它在模拟器中工作。)四边形渲染为我在texturedQuad类中设置的普通颜色,似乎没有渲染纹理 这是一个名为MenuOptionObject.m的类,它是我试图渲染的实际对象,我觉得它与示例中使用的spaceShip.m文件类似。这个文件确实有效,所以我不明白为什么当我使用几乎相同的“引擎”时,如果你可以这样称呼它 我

我正在使用OpenGL制作一个我正在尝试制作的应用程序。我一直在学习一本关于iPhone游戏开发的书

我的问题是,我的网格类的子类texturedQuad似乎无法正确渲染。(虽然它在模拟器中工作。)四边形渲染为我在texturedQuad类中设置的普通颜色,似乎没有渲染纹理

这是一个名为MenuOptionObject.m的类,它是我试图渲染的实际对象,我觉得它与示例中使用的spaceShip.m文件类似。这个文件确实有效,所以我不明白为什么当我使用几乎相同的“引擎”时,如果你可以这样称呼它

我觉得我错过了一些明显的东西。我研究的例子很有效。我还有一个名为texturedButton的类,它可以工作,并且还使用texturedQuad

以下是mesh.m代码:

 #import "Mesh.h"
#import "MaterialController.h"
#import "TexturedQuad.h"


@implementation Mesh

@synthesize vertexCount,vertexSize,colorSize,renderStyle,vertexes,colors;

- (id)initWithVertexes:(CGFloat*)verts 
           vertexCount:(NSInteger)vertCount 
            vertexSize:(NSInteger)vertSize
           renderStyle:(GLenum)style;
{
    self = [super init];
    if (self != nil) 
    {
        self.vertexes = verts;
        self.vertexCount = vertCount;
        self.vertexSize = vertSize;
        self.renderStyle = style;
    }
    return self;
}

// called once every frame
-(void)render
{
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisable(GL_TEXTURE_2D);
    // load arrays into the engine
    glVertexPointer(vertexSize, GL_FLOAT, 0, vertexes);
    glEnableClientState(GL_VERTEX_ARRAY);
    glColorPointer(colorSize, GL_FLOAT, 0, colors); 
    glEnableClientState(GL_COLOR_ARRAY);

    //render
    glDrawArrays(renderStyle, 0, vertexCount);  
}


+(CGRect)meshBounds:(Mesh*)mesh scale:(BBPoint)scale
{
    if (mesh == nil) return CGRectZero;
    // need to run through my vertexes and find my extremes
    if (mesh.vertexCount < 2) return CGRectZero;
    CGFloat xMin,yMin,xMax,yMax;
    xMin = xMax = mesh.vertexes[0];
    yMin = yMax = mesh.vertexes[1];
    NSInteger index;
    for (index = 0; index < mesh.vertexCount; index++) {
        NSInteger position = index * mesh.vertexSize;
        if (xMin > mesh.vertexes[position] * scale.x) xMin = mesh.vertexes[position] * scale.x;
        if (xMax < mesh.vertexes[position] * scale.x) xMax = mesh.vertexes[position] * scale.x;
        if (yMin > mesh.vertexes[position + 1] * scale.y) yMin = mesh.vertexes[position + 1] * scale.y;
        if (yMax < mesh.vertexes[position + 1] * scale.y) yMax = mesh.vertexes[position + 1] * scale.y;
    }
    CGRect meshBounds = CGRectMake(xMin, yMin, xMax - xMin, yMax - yMin);
    if (CGRectGetWidth(meshBounds) < 1.0) meshBounds.size.width = 1.0;
    if (CGRectGetHeight(meshBounds) < 1.0) meshBounds.size.height = 1.0;
    return meshBounds;
}

- (void) dealloc
{
    [super dealloc];
}



@end
最后,对于MenuOptionObject.m:

#import "MenuOptionObject.h"
#import "MaterialController.h"
#import "MenuSceneController.h"

@implementation MenuOptionObject
@synthesize bounds, circleBouncePoint;

-(id)initWithQuad:(NSString *)quad
{
    self = [super init];
    if (self != nil)
    {
        self.mesh = [[MaterialController sharedController] quadFromAtlasKey:quad];
    }
    return self;
}

// called once when the object is first created.
-(void)awake
{   
    self.scale = BBPointMake(28.0, 28.0, 1.0);
    self.sceneController = (SceneController *)[MenuSceneController sharedController];
}

-(void)update
{
    [super update];
    //[self sideCollisionUpdates];
    //[self circleCollisionUpdates];
}


-(void)dealloc
{
    [sceneController release];
    [super dealloc];
}

@end

在渲染纹理几何体之前,您是否记得调用
glEnable(GL\U TEXTURE\U 2D)

您是否记得调用
glEnable(GL\U TEXTURE\U 2D)
在渲染纹理几何体之前?

答案是正确的,尽管我的纹理在侧面的文件管理器和代码中都被称为menuAtlas,但它不起作用,因此将两者都更改为mA是有效的。我不明白为什么,但我怀疑它与缓存有关。

答案是正确的,尽管我的纹理在侧面的文件管理器和代码中都被称为menuAtlas,但它不起作用,所以将两者都改为mA是有效的。我不明白为什么,但我怀疑它与缓存有关。

它是在materialController
-(void)bindMaterial:(NSString*)materialKey{NSNumber*numberObj=[materialLibrary objectForKey:materialKey];if(numberObj==nil)返回;GLuint textureID=[numberObj unsignedIntValue];glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D,textureID);
感谢您仔细阅读并做出响应,尽管它是在materialController的bindMaterial方法中完成的
-(void)bindMaterial:(NSString*)materialKey{NSNumber*numberObj=[materialLibrary objectForKey:materialKey];如果(numberObj==nil)return;GLuint textureID=[numberObj unsignedIntValue];glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D,textureID);}
感谢您仔细阅读了所有内容并做出了响应。请参见(我不完全确定差异,帖子太长了)。请参见(我不完全确定差异,帖子太长了)。
#import "MenuOptionObject.h"
#import "MaterialController.h"
#import "MenuSceneController.h"

@implementation MenuOptionObject
@synthesize bounds, circleBouncePoint;

-(id)initWithQuad:(NSString *)quad
{
    self = [super init];
    if (self != nil)
    {
        self.mesh = [[MaterialController sharedController] quadFromAtlasKey:quad];
    }
    return self;
}

// called once when the object is first created.
-(void)awake
{   
    self.scale = BBPointMake(28.0, 28.0, 1.0);
    self.sceneController = (SceneController *)[MenuSceneController sharedController];
}

-(void)update
{
    [super update];
    //[self sideCollisionUpdates];
    //[self circleCollisionUpdates];
}


-(void)dealloc
{
    [sceneController release];
    [super dealloc];
}

@end