搅拌机 + OpenGL + Cocos2d
我遇到了一个奇怪的问题,我无法解决,想知道以前是否有人见过这个问题。基本上我可以让我的搅拌机模型显示纹理,但它无法正确映射纹理。我已经制作了最简单的模型,这就是我得到的:
我无法发布图像,所以这里有一个通过 picasaweb 的链接, https://picasaweb.google.com/112176813871298741669/January192012?authuser=0&feat=directlink
我正在使用 cocos2d 并在 CCSprite 绘制方法中绘制纹理,如下所示
glBindTexture(GL_TEXTURE_2D, self.texture.name);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(vertexDataTextured), &MeshVertexData[0].vertex);
glTexCoordPointer(2, GL_FLOAT, 0, &MeshVertexData[0].texCoord2);
:在 init 方法中作为 CCTexture2D 加载。
有人有什么想法吗?很确定它是纹理坐标,但无法计算出来,它们看起来是正确的,请参阅此处的数据:
{/*v:*/{1.000000, -0.000000, -1.000000}, /*n:*/{0.000000, 0.999969, 0.000000}, /*t:*/{0.000000, 0.000000}},
{/*v:*/{-1.000000, -0.000000, -1.000000}, /*n:*/{0.000000, 1.000000, 0.000000}, /*t:*/{1.000000, 0.000000}},
{/*v:*/{-1.000000, 0.000000, 1.000000}, /*n:*/{0.000000, 1.000000, 0.000000}, /*t:*/{1.000000, 1.000000}},
{/*v:*/{1.000000, -0.000000, -1.000000}, /*n:*/{0.000000, 0.999969, 0.000000}, /*t:*/{0.000000, 0.000000}},
{/*v:*/{-1.000000, 0.000000, 1.000000}, /*n:*/{0.000000, 1.000000, 0.000000}, /*t:*/{1.000000, 1.000000}},
{/*v:*/{1.000000, 0.000000, 1.000000}, /*n:*/{0.000000, 1.000000, 0.000000}, /*t:*/{0.000000, 1.000000}},
所以纹理坐标是:
0.000000, 0.000000
1.000000, 0.000000
1.000000, 1.000000
0.000000, 0.000000
1.000000, 1.000000
0.000000, 1.000000
但仔细观察图像,我不能 100% 确定它是坐标,也许与 openGL 参数有关......
I'm having a strange problem that I can't work out and wonder if anybody has seen this issue before. Basically I can get my blender model to show with a texture but it doesn't map the texture properly. I've made the most simple model I can and this is what I get:
I can't post images, so here's a link through picasaweb,
https://picasaweb.google.com/112176813871298741669/January192012?authuser=0&feat=directlink
I'm using cocos2d and drawing the texture within the CCSprite draw method like so:
glBindTexture(GL_TEXTURE_2D, self.texture.name);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(vertexDataTextured), &MeshVertexData[0].vertex);
glTexCoordPointer(2, GL_FLOAT, 0, &MeshVertexData[0].texCoord2);
The texture is loaded as a CCTexture2D in the init method.
Anybody any ideas? Pretty sure its the texture coords, but can't work it out, they look right, see here for the data:
{/*v:*/{1.000000, -0.000000, -1.000000}, /*n:*/{0.000000, 0.999969, 0.000000}, /*t:*/{0.000000, 0.000000}},
{/*v:*/{-1.000000, -0.000000, -1.000000}, /*n:*/{0.000000, 1.000000, 0.000000}, /*t:*/{1.000000, 0.000000}},
{/*v:*/{-1.000000, 0.000000, 1.000000}, /*n:*/{0.000000, 1.000000, 0.000000}, /*t:*/{1.000000, 1.000000}},
{/*v:*/{1.000000, -0.000000, -1.000000}, /*n:*/{0.000000, 0.999969, 0.000000}, /*t:*/{0.000000, 0.000000}},
{/*v:*/{-1.000000, 0.000000, 1.000000}, /*n:*/{0.000000, 1.000000, 0.000000}, /*t:*/{1.000000, 1.000000}},
{/*v:*/{1.000000, 0.000000, 1.000000}, /*n:*/{0.000000, 1.000000, 0.000000}, /*t:*/{0.000000, 1.000000}},
So the texture coordinates are:
0.000000, 0.000000
1.000000, 0.000000
1.000000, 1.000000
0.000000, 0.000000
1.000000, 1.000000
0.000000, 1.000000
But looking closely at the images I'm not 100% sure it is the coordinates, maybe something to to with an openGL parameter....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的问题是消极的。纹理坐标的范围为 0-1,大于 1 的数字会导致纹理在多边形上平铺,小于 1 则表示仅使用一部分纹理。
使用
glTexCoordPointer(2, GL_FLOAT, 0, &MeshVertexData[0].texCoord2);
意味着您在检索纹理坐标时不会跳过顶点数据,因此使用一些顶点数据作为纹理坐标。 0 应该是到达数据中下一组纹理坐标所需的步幅。由于这个答案被标记为已接受,我已经对其进行了编辑以确保完整性,但如果@PeterT 将他的评论发布为答案,那么他的应该被标记为解决方案!
Your problem is the negative ones. Texture coordinates are in the range 0-1, with numbers higher than 1 resulting in tiling of the texture across the poly, and less than one meaning that only a proportion of the texture is used.
Using
glTexCoordPointer(2, GL_FLOAT, 0, &MeshVertexData[0].texCoord2);
means you're not skipping vertex data when retrieving texture coordinates, and so using some of the vertex data for texture coordinates. The 0 should be the stride required to reach the next set of texture coordinates in the data.Since this answer was marked accepted, I've edited it for completeness, though if @PeterT posts his comment as an answer then his should be marked as the solution!