projecting image with opengl and Antialiasing

antialiasing, c++, opengl

Solution

First I wonder why you are using OpenGL 4.0 to work with fixed (deprecated ) pipeline... But let's get to the problem.What you need is MSAA .I am not sure ,enabling it via control panel will always do the trick.Usually it is done inside the code. Unfortunately for you , you selected to use GLUT which has no option to set hardware MSAA level.If you want to be able to do so switch to GLFW.Another option is do do it manually but that implies you use custom FBOs.In such a scenario you can create FBO with MSAA texture attachment setting MSAA level for the texture (also you can apply custom multisampling algorithms in fragment shader if you wish). Here is a thread on this topic.

GLFW allows you specifying MSAA level on window setup.See the related API.

MSAA does degrade the performance ,but how much depends on your hardware and probably OpenGL drivers.

Problem

In my work I overlap a part of a captured frame with an image. I open my webcam with openCV and then I transform the captured frame in a texture and display it in a GLUT window. Also, I overlap a part of this texture with this image: I do this in real time, and the result is: As you can see, edges of projected image are inaccurate. I think it is an aliasing problem, but I don't know how to do the antialiasing process with opengl. I've tried to look for on web, but I didn't find a good solution for my problem. In my "calculate" function I transform the mat image into a texture usign the following code: ``` GLvoid calculate(){ ... ... cvtColor(image, image, CV_BGR2RGB); glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glBindTexture(GL_TEXTURE_2D, textures[1]); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); //glTexImage2D(GL_TEXTURE_2D, 0, 4,image.cols, image.rows, 0, GL_RGB,GL_UNSIGNED_BYTE, image.data); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, image.cols, image.rows, GL_RGB, GL_UNSIGNED_BYTE, image.data); } ``` and I show the result using this code: ``` GLvoid Show(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_TEXTURE_2D); // Matrice di proiezione glMatrixMode (GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, WIDTH, HEIGHT, 0); // Matrice model view glMatrixMode(GL_MODELVIEW); glLoadIdentity(); ... ... glBindTexture(GL_TEXTURE_2D, textures[1]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f((GLfloat)((coord[3].x)),(GLfloat)(coord[3].y)); glTexCoord2f(1.0f, 0.0f); glVertex2f((GLfloat)((coord[0].x)),(GLfloat)(coord[0].y)); glTexCoord2f(1.0f, 1.0f); glVertex2f((GLfloat)((coord[1].x)),(GLfloat)(coord[1].y)); glTexCoord2f(0.0f, 1.0f); glVertex2f((GLfloat)((coord[2].x)),(GLfloat)(coord[2].y)); glEnd(); } glFlush(); glutSwapBuffers(); } ``` In initialization function I write this: ``` GLvoid Init() { glGenTextures(2, textures); glClearColor (0.0, 0.0, 0.0, 0.0); glEnable (GL_POLYGON_SMOOTH); glHint (GL_POLYGON_SMOOTH_HINT, GL_DONT_CARE); glDisable(GL_DEPTH_TEST); } ``` but it doesn't work... I work on Win7 x64, with OPenGL 4.0 and Glut 3.7. My video card is an NVidia GeForce gt 630. also I enabled antialiasing from Nvidia control panel, but nothing is changed. does anyone know how to help me?

Original source

Related problems