texure mapping anti-alias

I have an 512 by 512 image like this:

I mapped it to a 3D plane:


The location and perspective are all correct. But you can see that the edge is very jigsaw. Does not Open GL has anti-alias or I just did not turn it on?

I am on iPhone ios.

Here is my code:

      CGContextRef spriteContext = CGBitmapContextCreate(spriteData, spriteWidth, spriteHeight, 8, spriteWidth * 4, CGImageGetColorSpace(spriteImage), kCGImageAlphaPremultipliedLast);

    CGContextTranslateCTM(spriteContext, 0, spriteHeight);

    CGContextScaleCTM(spriteContext, 1, -1);

      CGContextDrawImage(spriteContext, CGRectMake(0.0, 0.0, (CGFloat)spriteWidth, (CGFloat)spriteHeight), spriteImage);

      CGContextRelease(spriteContext);



    glDeleteTextures(1, &spriteTexture);

    glGenTextures(1, &spriteTexture);

    // Bind the texture name. 

    glBindTexture(GL_TEXTURE_2D, spriteTexture);

    // Set the texture parameters to use a minifying filter and a linear filer (weighted average)

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_FILTER, GL_LINEAR);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );



    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, spriteWidth, spriteHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, spriteData);

glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);

 glClearColor(.0f, 0.0f, 0.0f, .0f);

 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);



 //Setup model view matrix

 glMatrixMode(GL_MODELVIEW);



GLfloat teapot_vertices1[12];




glLoadMatrixf(m);





teapot_vertices1[0] = frames;

teapot_vertices1[1] = frameh;

teapot_vertices1[2] = 0;

teapot_vertices1[3] = frames + framel;;

teapot_vertices1[4] = frameh;

teapot_vertices1[5] = 0;

teapot_vertices1[6] = 0;

teapot_vertices1[7] = 0;

teapot_vertices1[8] = 0;

teapot_vertices1[9] = framel;

teapot_vertices1[10] = 0;

teapot_vertices1[11] = 0;







glVertexPointer(3 ,GL_FLOAT, 0, teapot_vertices1);






for(int i = 0; i < num_teapot_indices; i += new_teapot_indicies[i] + 1)

 {

      glDrawElements(GL_TRIANGLE_STRIP, new_teapot_indicies[i], GL_UNSIGNED_SHORT, &new_teapot_indicies[i+1]);

 }





//glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);



 glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);

 [context presentRenderbuffer:GL_RENDERBUFFER_OES];

Linear interpolation doesn’t produce good antialiasing of textures when the texture is much larger than the screen area it covers. Mipmapping is a better approach. Try creating several mip layers for the texture and set the min filter to GL_LINEAR_MIPMAP_LINEAR (trilinear filtering).

I tried your approach and now the edge inside is much better:

But the border edge is still jigsaw. Any way we can fix this?

thank you very very much for your help.

Fireman

Multisampling smooths out edges of geometry. I’m not sure what modes are available on iOS, but you need a framebuffer with multiple samples, or a multisample renderbuffer/texture with an FBO. Then call glEnable(GL_MULTISAMPLE) before drawing your geometry. This does cause more of a performance hit than trilinear filtering, however.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.