Sign in to follow this  

OpenGL Opengl-es texture having a stretched area not wanted

Recommended Posts


EDIT: i fixed it, i had to move a line down, and it works... But the image is actually in the wrong direction, upside down, if anyone has any idea about that
Would anyone know why i get this stretched slice in the texture?

The stretched area : (it starts in the middle, then goes left, and comes back again in the right side)


Here is the image without the texture, the triangles seem correctly drawn (even when i zoom in: the triangles seem to work fine) :


And the code : here is the offset, called every second, to make the path and texture move :

- (void) setOffsetY:(float)newOffsetY {
y_line = -_offsetY - winSize.height/self.scale; //readjust the bottom line where to connect the triangles to
self.position = CGPointMake(-_offsetY, _offsetY); //move to the top left
[self generatePolygons];//the triangles

Here is how i create the triangles (division = 512, the size of my texture image) :

_polyVertices[_nPolyVertices] = CGPointMake(p0.x, y_line);
_polyTexCoords[_nPolyVertices++] = CGPointMake(p0.x/division, y_line/division);
//V1: to the first "point"
_polyVertices[_nPolyVertices] = CGPointMake(p0.x, p0.y);
_polyTexCoords[_nPolyVertices++] = CGPointMake(p0.x/division, p0.y/division);
//V2, same y as point n°2:
_polyVertices[_nPolyVertices] = CGPointMake(p1.x, y_line);
_polyTexCoords[_nPolyVertices++] = CGPointMake(p1.x/division, y_line/division);
//V3 = same x,y as point at index 1
_polyVertices[_nPolyVertices] = CGPointMake(p1.x, p1.y);
_polyTexCoords[_nPolyVertices++] = CGPointMake(p1.x/division, p1.y/division);

and how i draw the texture :

- (void) draw {
//blue triangles
glColor4f(0, 0, 1, 1);
for(int i = 1; i < 50; i++) {
ccDrawLine(_polyVertices[i-1], _polyVertices[i]);
glBindTexture(GL_TEXTURE_2D, texture.textureID);
glColor4f(1, 1, 1, 1);
glVertexPointer(2, GL_FLOAT, 0, _polyVertices);
glTexCoordPointer(2, GL_FLOAT, 0, _polyTexCoords);
glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)_nPolyVertices);

Thanks Edited by PWall

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this