PDA

View Full Version : Texture-binding issue (with video)



GarrettVD
10-14-2011, 06:49 PM
Hi all,
I'll preface by saying that I'm relatively new to OpenGL ES 2.0 (well, to OpenGL in general, really). I've been reading up quite a bit lately on it, as I'm developing an iPhone application using Cocos2D and Chipmunk Physics. From time-to-time, I need to go in and dabble with some OpenGL; primarily when I'm using a script not tailored to Cocos2D. As is the case with the Verlet integration-based rope code I'm working with.

Now, the script itself works fantastic if there is no need to apply a texture. Works great with just a color array. But I want to apply a rope texture, so I created a PVRTC texture and tried to bind that with my rope vertices. Now, I'm not sure what I'm doing wrong here, but it seems to fill up the view completely with the texture, instead of just binding it onto the rope vertices.

Can one of you OpenGL-wizards help a newbie like me out? :)

Here is a video of the issue: http://www.youtube.com/watch?v=U7P4_4B2C6A

And of course, the draw() method:


- (void)draw {
[super draw];
int count = _count + 1;

static const GLfloat texCoords[] = {
0.0, 1.0,
1.0, 1.0,
0.0, 0.0,
1.0, 0.0
};

cpVect verts[count*2];
generateVertexes(_particles, verts, count, _width);
NSString *path = [[NSBundle mainBundle] pathForResource:@"rope" ofType:@"pvrtc"];
NSData *texData = [[NSData alloc] initWithContentsOfFile:path];
GLuint texture[1];
glGenTextures(1, &texture[0]);

glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, 64, 64, 0, [texData length], [texData bytes]);

glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glVertexPointer(2, GL_FLOAT, 0, verts);
glTexCoordPointer(2, GL_FLOAT, 0, texCoords);

glDrawArrays(GL_TRIANGLE_STRIP, 0, count * 2);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

glEnableClientState(GL_COLOR_ARRAY);

}


Thanks a million!!

-G.

V-man
10-15-2011, 04:18 AM
Im not a gl es pro, but if it is anything like GL, then it could be
www.opengl.org/wiki/Common_Mistakes (http://www.opengl.org/wiki/Common_Mistakes)

Read the part about creating a texture.