当前位置:编程学习 > wap >>

opengl贴图的问题,为什么中间会有一条线???

我先把图片分割,然后再贴到相邻的两个长方形内,为什么中间这个地方会有一条线呢,请高手给点提示。。。
谢谢了!

纹理设置代码如下:

int i, width, height;
BOOL sizeToFit = NO;
GLubyte * data = NULL;
CGContextRef ct = NULL;
width = CGImageGetWidth(image);
height = CGImageGetHeight(image);

if((width != 1) && (width & (width - 1))) 
{
i = 1;
while((sizeToFit ? 2 * i : i) < width)
i *= 2;
width = i;
}
if((height != 1) && (height & (height - 1))) 
{
i = 1;
while((sizeToFit ? 2 * i : i) < height)
i *= 2;
height = i;
}
while((width > kMaxTextureSize) || (height > kMaxTextureSize)) 
{
width /= 2;
height /= 2;
}

data = (GLubyte *)malloc(height * width * 4);
ct = CGBitmapContextCreate(data,
   width,
   height,
   8,
   width * 4,
   CGImageGetColorSpace(image),
   kCGImageAlphaPremultipliedLast);

CGContextClearRect(ct, CGRectMake(0, 0, width, height));
CGContextTranslateCTM(ct, 0.0, height);
CGContextScaleCTM(ct, 1.0, -1.0);
CGContextDrawImage(ct, CGRectMake(0, 0, width, height), image);
// CGImageRef saveImageRef = CGBitmapContextCreateImage(ct);
// UIImage * saveImage = [UIImage imageWithCGImage:saveImageRef];
// NSString * savePath = [NSString stringWithFormat:@"%@/Documents/%d.jpg", NSHomeDirectory(), location];
// [UIImageJPEGRepresentation(saveImage, 1.0) writeToFile:savePath atomically:YES];
// CGImageRelease(saveImageRef);
// CGContextRelease(ct);

glBindTexture(GL_TEXTURE_2D, location);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);     
//    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
// glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

free(data);

绘图代码如下:

// Our new object definition code goes here
[EAGLContext setCurrentContext:context];
glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glViewport(0, 0, backingWidth, backingHeight);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// glEnable(GL_CULL_FACE);
// glFrontFace(GL_CCW);


glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glScalef(scaleX, scaleY, scaleZ);
_angle = 30;
// _angle += 5;
glRotatef(_angle, 0, 1, 0);
glRotatef(10.0, 0, 1, 0);

glVertexPointer(3, GL_FLOAT, 0, vertices);
glTexCoordPointer(2, GL_SHORT, 0, texCoords);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

for (int i = 0; i < POLYGON; i++) 
{
glBindTexture(GL_TEXTURE_2D, _textures[i]);
glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4);
}

// Our new drawing code goes here
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];

我把data里面的内容保存的时候,并没有发现有这条缝隙

CGImageRef saveImageRef = CGBitmapContextCreateImage(ct);
UIImage * saveImage = [UIImage imageWithCGImage:saveImageRef];
NSString * savePath = [NSString stringWithFormat:@"%@/Documents/%d.jpg", NSHomeDirectory(), location];
[UIImageJPEGRepresentation(saveImage, 1.0) writeToFile:savePath atomically:YES];
CGImageRelease(saveImageRef);
CGContextRelease(ct);
--------------------编程问答-------------------- iphone版人气这么低啊~~~ --------------------编程问答-------------------- csdn的iphone不行` --------------------编程问答-------------------- 我都混cocoa 跟devdiv
--------------------编程问答--------------------
引用 3 楼 benyoulai5 的回复:
我都混cocoa 跟devdiv


我在cocoa也发了帖子,问题还是没解决,去devdiv看看
--------------------编程问答-------------------- 長方形的框線沒弄掉吧 --------------------编程问答--------------------
引用 3 楼 benyoulai5 的回复:
我都混cocoa 跟devdiv

我都混google跟stack overflow.....
--------------------编程问答-------------------- 是由于在分界处的偏导数不连续造成的 --------------------编程问答-------------------- 楼主搜索一下 opengl 0.375试试
如果还不行,试试改成nearest过滤 --------------------编程问答--------------------
引用 6 楼 cloudhsu 的回复:
引用 3 楼 benyoulai5 的回复:
我都混cocoa 跟devdiv

我都混google跟stack overflow.....


嗯呢 你是我心目中的大神
google也是在用 
--------------------编程问答--------------------
引用 7 楼 feng_source 的回复:
是由于在分界处的偏导数不连续造成的


还是你牛 --------------------编程问答--------------------
引用 8 楼 n5 的回复:
楼主搜索一下 opengl 0.375试试
如果还不行,试试改成nearest过滤


你更牛.............
补充:移动开发 ,  iPhone
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,