我从http://heikobehrens.net/2009/08/27/obj2opengl/下载banana.h文件。我在EAGLView.mm中包含了.h文件。我替换为EAGLView.mm文件。我按照说明用另一种3D模式替换茶壶。但是我没有任何替换输出。我不知道我在哪里弄错了
namespace {
// Teapot texture filenames
const char* textureFilenames[] = {
"banana.jpg",
/*
"TextureTeapotBrass.png",
"TextureTeapotBlue.png",
"TextureTeapotRed.png"
*/
}
// Model scale factor
const float kObjectScale = 3.0f;
}
- (void) setup3dObjects
{
// build the array of objects we want drawn and their texture
// in this example we have 3 targets and require 3 models
// but using the same underlying 3D model of a teapot, differentiated
// by using a different texture for each
for (int i=0; i < [textures count]; i++)
{
Object3D *obj3D = [[Object3D alloc] init];
// obj3D.numVertices = NUM_TEAPOT_OBJECT_VERTEX;
obj3D.numVertices =bananaNumVerts;
obj3D.vertices = bananaVerts;
obj3D.normals = bananaNormals;
obj3D.texCoords = bananaTexCoords;
obj3D.numIndices = 0;
obj3D.indices = nil;
obj3D.texture = [textures objectAtIndex:i];
[objects3D addObject:obj3D];
[obj3D release];
}
}
在renderFrame中替换为:
glVertexPointer(3, GL_FLOAT, 0, bananaVerts);
glNormalPointer(GL_FLOAT, 0, bananaNormals);
glTexCoordPointer(2, GL_FLOAT, 0, bananaTexCoords);
glDrawArrays(GL_TRIANGLES, 0, bananaNumVerts);
我在哪里弄错了?
最佳答案
您的代码是正确的。尝试增加比例尺大小,因为您的模型可能很小。更改
const float kObjectScale = 50.0f; // Scale up
并且也使用.png格式的纹理。
关于iphone - 不能用香蕉代替茶壶,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19312941/