Darren
Darren

Reputation: 269

Blender + OpenGL + Cocos2d

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....

Upvotes: 1

Views: 606

Answers (1)

Matt Lacey
Matt Lacey

Reputation: 8255

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!

Upvotes: 1

Related Questions