case ParticleEmitter3DDrawTextureMap:
{
static const GLfloat squareStrip = {
+0.01f, +0.01f, +0.0f,
-0.01f, +0.01f, +0.0f,
-0.01f, -0.01f, +0.0f,
+0.01f, +0.01f, +0.0f,
-0.01f, -0.01f, +0.0f,
+0.01f, -0.01f, +0.0f,
};
static const GLfloat tex = {
1.0, 1.0,
0.0, 1.0,
0.0, 0.0,
1.0, 1.0,
0.0, 0.0,
1.0, 0.0,
};
//static const GLfloat squareNormals[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
glScalef(oneParticle->particleSize, oneParticle->particleSize, oneParticle->particleSize);
;
glEnable(GL_TEXTURE);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
//glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, squareStrip);
//glNormalPointer(GL_FLOAT, 0, squareNormals);
glTexCoordPointer(3, GL_FLOAT, 0, tex);
glDrawArrays(GL_TRIANGLES, 0, 6);
glDisable(GL_TEXTURE);
//glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
break;
}
As a test, I was mapping this image onto the sprites:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiWsWhx8l-BpVgfWH0_u5q6u-yzgIfBQ2kXMqVvrmT4rr-ff3ONHWCNN6y8Wb3KQSKDIeo_0VsCw7mHgx6sV6ASEvMtXHxWZvwpS8fn_Y7jCqaNV22v6MCyEA3H7jsj9qkt8_3wpnjrHo8/s400/texture.jpg)
But, what I get is this:
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzD12td3KgOdNMX-y5SX4kyjdCVpLbOS-ov1T3w5ToiaL59EeKdCgi8Ub6xHo21CXdEqFiJIB_fetbnLP96Tssdmrhr8q1hpL3gihVDp1WK9msEdkYGwm7DzsswQMOLC23RL2UBtKxXOY/s400/iPhone+SimulatorScreenSnapz001.jpg)
My guess, this is either a texture coordinate issue or a blending function issue. I've tried many, many permutations, both with triangle strips and triangles, and using glDrawArrays() and glDrawElements(), and I've tried every permutation of texture coordinates I can think of, yet I've never been able to get both triangles mapped right.
Here's a slightly different version that gives the same result:
case ParticleEmitter3DDrawTextureMap:
{
static const GLfloat squareVertices = {
+0.01f, +0.01f, +0.0f,
-0.01f, +0.01f, +0.0f,
-0.01f, -0.01f, +0.0f,
+0.01f, -0.01f, +0.0f,
};
static const GLfloat tex = {
1.0, 0.0,
0.0, 1.0,
0.0, 0.0,
1.0, 0.0,
};
static const GLushort triangle1 = {0,2,1};
static const GLushort triangle2 = {2,3,0};
//static const GLfloat squareNormals[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
glScalef(oneParticle->particleSize, oneParticle->particleSize, oneParticle->particleSize);
;
glEnable(GL_TEXTURE);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
//glEnableClientState(GL_NORMAL_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, squareVertices);
//glNormalPointer(GL_FLOAT, 0, squareNormals);
glTexCoordPointer(3, GL_FLOAT, 0, tex);
//glDrawArrays(GL_TRIANGLES, 0, 6);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, &triangle1);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_SHORT, &triangle2);
glDisable(GL_TEXTURE);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
break;
}
The thing is, I know that these texture coordinates are right. I've copied verbatim the coordinates and drawing code from probably a half-dozen code samples and tutorials I found on the web. That, combined with the fact that I can't find any set of texture coordinates that works, makes me thing I'm doing something terribly wrong somewhere else. I tried switching the winding order of the triangle vertices, and that had no visible effect. I also played with the blending functions with no success.
If there's anyone out there who's pretty good with OpenGL who can point out the boneheaded thing I'm doing here, I would really appreciate it. I think it's possible that it's the same thing that was keeping me from getting the UV-mapped OBJ files to display correctly.
If you're the first person to figure out what I'm doing wrong, you're welcome to a free copy of Beginning iPhone Development, though if you can figure this out, you've probably no need of it. Unfortunately, I can't afford to spend more time on this right now, so unless someone can figure this out, the particle tutorial is probably going to go on a shelf for a few weeks while I dig out from the Macworld backlog.
No comments:
Post a Comment