1
votes

I have an anti-aliasing issue. My goal is to render a texture on a "sheared rectangle" that is to say a parallelepiped. But with the code below, the vertical lines are pixellised. I tried with no success to change the glShadeModel, the glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); with GL_LINEAR, GL_NEAREST_MIPMAP_LINEAR, etc. In the "InitializeGL" sequence, I tried adding "glEnable(GL_POLYGON_SMOOTH);" but I guess it's for polygons and not textures. I found articles about using mip-mapping, or "close-up" filters, but did not understood how to code it in OpenGL. What is the best way to render a texture on a parallelepiped without aliasing ? Here below, you can see the "yTanAngle" that I had to obtain a shearing effect :

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textureId);
glBegin(GL_QUADS);
glColor4ub(255,255,255,incrustInfo->atexte);
glTexCoord2d(0.0, 0.0); glVertex2d(x0, y0);
glTexCoord2d(1.0, 0.0); glVertex2d(x1, y0);
glTexCoord2d(1.0,1.0);  glVertex2d(x1 + yTanAngle, y1);
glTexCoord2d(0.0,1.0);  glVertex2d(x0 + yTanAngle, y1);
glEnd();
glDisable(GL_TEXTURE_2D);

I also tried to apply a shearing matrix :

//--- Shearing
GLdouble shearing[16] = {1.0,0.0,0.0,0.0, tan(angle*M_PI/180.0),1.0,0.0,0.0, 0.0,0.0,1.0,0.0, 0.0,0.0,0.0,1.0};
glMultMatrixd(shearing);

But I still have a pixellised image. And another problem is that I want to apply this shearing only to this gl_quad, and not to the global matrix (all elements get sheared).

As asked by Nils Pipenbrinck, here is a screenshot (but it's done from a Windows screenshot saved to .BMP and loaded to freeimagehosting which provides a .PNG link ... however we can see the pixelisation of the flag): sheared flag needs antialiasing
(source: uploads.im)

2
Try glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); while creating the texture. Maybe it's what you want.lisyarus
I have tried "GL_LINEAR" in magnify and minify filters without success: still pixellised.Arnaud

2 Answers

0
votes

Now this is an interesting problem. From the picture I assume that is fits exactly into to the device space. You would think that filtering would resolve this issue, but it doesn't.

To understand why this is the case you need to look at how filtering works. If the texel does not fit into the pixel what should the graphic card do? With GL_NEAREST it picks the texel that matches best and uses that. with GL_LINEAR it takes weighed average of the texels that fall into the pixel.

What happens when the texel and the pixel match perfectly? With GL_NEAREST the pixel is picked as expected. With GL_LINEAR all pixels, that is exactly one are takes and their weighted average is taken. As you can see in this case the texture is replicated perfectly.

What are your options?

The cleanest thing you can to is slant the flag in your graphic editor and draw a normal rectangle, though with alpha blending.

A slightly hacky solution is to move the rectangle by 0.5 device coordinates to the left or right. This will change the perfect overlap and the GL_LINEAR filtering will apply.


As an aside, if this is your GUI and it will never be scaled (like used in a 3D scene), then you should not use mipmaps, you are wasting memory space.

0
votes

Using mipmap while creating the texture finally did the trick.

Before the glTexImage2D, I added:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

and after the glTexImage2D, I added:

glGenerateMipmap(GL_TEXTURE_2D);

And the CPU consumption is not altered for my 200x300 images.