我正在尝试在 OpenGL ES 2.0 iOS 中绘制一个 3D 立方体。我创建了一个结构,通过它我试图容纳与立方体相关的各种信息(位置坐标、纹理映射、法线)。现在我需要告诉 OpenGL 在哪里可以找到这个结构中的法线。一切都正确编译和渲染,但我在下面显示的最后一行给了我这个警告:
Incompatible integer to pointer conversion passing 'unsigned long' to parameter of type 'const GLvoid *' (aka 'const void *')
为什么我的代码返回无符号长?我不知道如何修改它以获取该行所要求的指针。谁能看到我做错了什么?谢谢。
这是结构:
typedef struct {
GLKVector3 positionCoordinates;
GLKVector2 textureCoordinates;
GLKVector3 normalCoordinates;
} VertexData;
坐标数据:
VertexData cameraVertices[] = {
//{ position x, position y, position z}, {texture}, {normalX, normalY, normalZ}
{ { 0.5f, -0.5f, -0.5f}, {0.0f, 0.0f}, { 1.0f, 0.0f, 0.0f} }, // rightward facing (+X)
{ { 0.5f, 0.5f, -0.5f}, {1.0f, 0.0f}, { 1.0f, 0.0f, 0.0f} },
{ { 0.5f, -0.5f, 0.5f}, {0.0f, 1.0f}, { 1.0f, 0.0f, 0.0f} },
{ { 0.5f, -0.5f, 0.5f}, {0.0f, 1.0f}, { 1.0f, 0.0f, 0.0f} },
{ { 0.5f, 0.5f, -0.5f}, {1.0f, 0.0f}, { 1.0f, 0.0f, 0.0f} },
{ { 0.5f, 0.5f, 0.5f}, {1.0f, 1.0f}, { 1.0f, 0.0f, 0.0f} },
{ { 0.5f, 0.5f, -0.5f}, {0.0f, 0.0f}, { 0.0f, 1.0f, 0.0f} }, // upward facing (+Y)
{ {-0.5f, 0.5f, -0.5f}, {1.0f, 0.0f}, { 0.0f, 1.0f, 0.0f} },
{ { 0.5f, 0.5f, 0.5f}, {0.0f, 1.0f}, { 0.0f, 1.0f, 0.0f} },
{ { 0.5f, 0.5f, 0.5f}, {0.0f, 1.0f}, { 0.0f, 1.0f, 0.0f} },
{ {-0.5f, 0.5f, -0.5f}, {1.0f, 0.0f}, { 0.0f, 1.0f, 0.0f} },
{ {-0.5f, 0.5f, 0.5f}, {1.0f, 1.0f}, { 0.0f, 1.0f, 0.0f} },
{ {-0.5f, 0.5f, -0.5f}, {0.0f, 0.0f}, {-1.0f, 0.0f, 0.0f} }, // leftward facing (-X)
{ {-0.5f, -0.5f, -0.5f}, {1.0f, 0.0f}, {-1.0f, 0.0f, 0.0f} },
{ {-0.5f, 0.5f, 0.5f}, {0.0f, 1.0f}, {-1.0f, 0.0f, 0.0f} },
{ {-0.5f, 0.5f, 0.5f}, {0.0f, 1.0f}, {-1.0f, 0.0f, 0.0f} },
{ {-0.5f, -0.5f, -0.5f}, {1.0f, 0.0f}, {-1.0f, 0.0f, 0.0f} },
{ {-0.5f, -0.5f, 0.5f}, {1.0f, 1.0f}, {-1.0f, 0.0f, 0.0f} },
{ {-0.5f, -0.5f, -0.5f}, {0.0f, 0.0f}, { 0.0f, -1.0f, 0.0f} }, // downward facing (-Y)
{ { 0.5f, -0.5f, -0.5f}, {1.0f, 0.0f}, { 0.0f, -1.0f, 0.0f} },
{ {-0.5f, -0.5f, 0.5f}, {0.0f, 1.0f}, { 0.0f, -1.0f, 0.0f} },
{ {-0.5f, -0.5f, 0.5f}, {0.0f, 1.0f}, { 0.0f, -1.0f, 0.0f} },
{ { 0.5f, -0.5f, -0.5f}, {1.0f, 0.0f}, { 0.0f, -1.0f, 0.0f} },
{ { 0.5f, -0.5f, 0.5f}, {1.0f, 1.0f}, { 0.0f, -1.0f, 0.0f} },
{ { 0.5f, 0.5f, 0.5f}, {0.0f, 0.0f}, { 0.0f, 0.0f, 1.0f} }, // forward facing (+Z)
{ {-0.5f, 0.5f, 0.5f}, {1.0f, 0.0f}, { 0.0f, 0.0f, 1.0f} },
{ { 0.5f, -0.5f, 0.5f}, {0.0f, 1.0f}, { 0.0f, 0.0f, 1.0f} },
{ { 0.5f, -0.5f, 0.5f}, {0.0f, 1.0f}, { 0.0f, 0.0f, 1.0f} },
{ {-0.5f, 0.5f, 0.5f}, {1.0f, 0.0f}, { 0.0f, 0.0f, 1.0f} },
{ {-0.5f, -0.5f, 0.5f}, {1.0f, 1.0f}, { 0.0f, 0.0f, 1.0f} },
{ { 0.5f, -0.5f, -0.5f}, {0.0f, 0.0f}, { 0.0f, 0.0f, -1.0f} }, // rear facing (-Z)
{ {-0.5f, -0.5f, -0.5f}, {1.0f, 0.0f}, { 0.0f, 0.0f, -1.0f} },
{ { 0.5f, 0.5f, -0.5f}, {0.0f, 1.0f}, { 0.0f, 0.0f, -1.0f} },
{ { 0.5f, 0.5f, -0.5f}, {0.0f, 1.0f}, { 0.0f, 0.0f, -1.0f} },
{ {-0.5f, -0.5f, -0.5f}, {1.0f, 0.0f}, { 0.0f, 0.0f, -1.0f} },
{ {-0.5f, 0.5f, -0.5f}, {1.0f, 1.0f}, { 0.0f, 0.0f, -1.0f} },
};
以及相关的代码行(基本上在 viewDidLoad 中):
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), offsetof(VertexData, positionCoordinates));
glEnableVertexAttribArray(GLKVertexAttribNormal);
glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, sizeof(VertexData), offsetof(VertexData, normalCoordinates));