OpenGL别名?

时间:2012-07-03 15:53:02

标签: winforms visual-studio-2008 opengl aliasing

我正在使用Forms创建win7 microsoft visual studio 08。我刚刚更改了我的显卡,我的应用程序中出现了某种别名。

img

可以认为灰线是一种别名,也是参考系统,几乎是不可见的。

如何解决这个问题?

我会发布部分代码以防万一: 1:绘画功能

private: void Paint(){



        int w = glControl1->Width;
        int h = glControl1->Height;


        float aspect_ratio = w / (float)h;
        Matrix4 perpective = Matrix4::CreatePerspectiveFieldOfView(MathHelper::PiOver4, aspect_ratio, 0.1f, 100000.0f);
        GL::MatrixMode(MatrixMode::Projection);
        GL::LoadMatrix(perpective);

        GL::MatrixMode(MatrixMode::Modelview);
        GL::LoadIdentity();
        GL::Viewport(0, 0, w, h);

        //Situacion de la camara en el espacio
        Matrix4 lookat = Matrix4::LookAt(100, 100, 100, 0, 0, 0, 0, 0, 1);
        GL::LoadMatrix(lookat);

        GL::Scale(this->zoom, this->zoom, this->zoom);


        GL::Rotate(xrot, 1.0f, 0.0f, 0.0f);
        GL::Rotate(yrot, 0.0f, 1.0f, 0.0f);
        GL::Clear(ClearBufferMask::ColorBufferBit | ClearBufferMask::DepthBufferBit);
           GL::ClearColor(Color::LightGray);



        Draw3Daxis();
        if (allowDraw){
            DrawSurface();
            }
        }

2:绘制图片中显示的所有内容的函数(它只是一堆GL :: Vertex3)

System::Void Draw3Daxis(){
         OpcionesPlot* opciones;
         opciones=OpcionesPlot::Instance();
         int extra=2;
         int sqrnumber=10;

        //Planos en los ejes
        GL::Color3(Color::White);
        GL::Begin(BeginMode::Quads);
        if(opciones->draw3DXYaxis){
            GL::Vertex3(0,0,0);
            GL::Vertex3(LENGTH,0,0);
            GL::Vertex3(LENGTH,LENGTH,0);
            GL::Vertex3(0,LENGTH,0);
         }
         if(opciones->draw3DXZaxis){
             GL::Vertex3(0,0,0);
             GL::Vertex3(LENGTH,0,0);
             GL::Vertex3(LENGTH,0,LENGTH);
             GL::Vertex3(0,0,LENGTH);
         }
         if(opciones->draw3DYZaxis){
             GL::Vertex3(0,0,0);
             GL::Vertex3(0,LENGTH,0);
             GL::Vertex3(0,LENGTH,LENGTH);
             GL::Vertex3(0,0,LENGTH);
        }
         GL::End();


         // ejes XYZ
         GL::Color3(Color::Black);
         GL::Begin(BeginMode::Lines);
         if(opciones->draw3DXYaxis){
            GL::Vertex3(0,0,0);
            GL::Vertex3(LENGTH+extra,0,0);
            GL::Vertex3(0,0,0);
            GL::Vertex3(0,LENGTH+extra,0);
         }
         if(opciones->draw3DXZaxis){
             GL::Vertex3(0,0,0);
             GL::Vertex3(LENGTH+extra,0,0);
             GL::Vertex3(0,0,0);
             GL::Vertex3(0,0,LENGTH+extra);
         }
         if(opciones->draw3DYZaxis){
             GL::Vertex3(0,0,0);
             GL::Vertex3(0,LENGTH+extra,0);
             GL::Vertex3(0,0,0);
             GL::Vertex3(0,0,LENGTH+extra);
        }

         //--> lineas de los planos
         GL::Color3(Color::DarkGray);
         for(int i=1;i<=sqrnumber;i++){
             if(i==sqrnumber)
                 GL::Color3(Color::Black);
             if(opciones->draw3DXYaxis){
                 GL::Vertex3(LENGTH/sqrnumber*i,0,0);
                 GL::Vertex3(LENGTH/sqrnumber*i,LENGTH,0);
                 GL::Vertex3(0,LENGTH/sqrnumber*i,0);
                 GL::Vertex3(LENGTH,LENGTH/sqrnumber*i,0);
             }
             if(opciones->draw3DXZaxis){
                 GL::Vertex3(LENGTH/sqrnumber*i,0,0);
                 GL::Vertex3(LENGTH/sqrnumber*i,0,LENGTH);
                 GL::Vertex3(0,0,LENGTH/sqrnumber*i);
                 GL::Vertex3(LENGTH,0,LENGTH/sqrnumber*i);

             }
             if(opciones->draw3DYZaxis){
                 GL::Vertex3(0,0,LENGTH/sqrnumber*i);
                 GL::Vertex3(0,LENGTH,LENGTH/sqrnumber*i);
                 GL::Vertex3(0,LENGTH/sqrnumber*i,0);
                 GL::Vertex3(0,LENGTH/sqrnumber*i,LENGTH);
             }

         }
        GL::End();
        // triangulos para los ejes
        //----->cuadrado
        GL::Color3(Color::Black);
        GL::Begin(BeginMode::Quads);
        float quadside=0.7;
        if(opciones->draw3DXYaxis){
            GL::Vertex3((float)LENGTH+extra,quadside,quadside);
            GL::Vertex3((float)LENGTH+extra,-quadside,quadside);
            GL::Vertex3((float)LENGTH+extra,-quadside,-quadside);
            GL::Vertex3((float)LENGTH+extra,quadside,-quadside);

            GL::Vertex3(quadside,(float)LENGTH+extra,quadside);
            GL::Vertex3(-quadside,(float)LENGTH+extra,quadside);
            GL::Vertex3(-quadside,(float)LENGTH+extra,-quadside);
            GL::Vertex3(quadside,(float)LENGTH+extra,-quadside);


         }
         if(opciones->draw3DXZaxis){
            GL::Vertex3((float)LENGTH+extra,quadside,quadside);
            GL::Vertex3((float)LENGTH+extra,-quadside,quadside);
            GL::Vertex3((float)LENGTH+extra,-quadside,-quadside);
            GL::Vertex3((float)LENGTH+extra,quadside,-quadside);

            GL::Vertex3(quadside,quadside,(float)LENGTH+extra);
            GL::Vertex3(-quadside,quadside,(float)LENGTH+extra);
            GL::Vertex3(-quadside,-quadside,(float)LENGTH+extra);
            GL::Vertex3(quadside,-quadside,(float)LENGTH+extra);
         }
         if(opciones->draw3DYZaxis){
            GL::Vertex3(quadside,(float)LENGTH+extra,quadside);
            GL::Vertex3(-quadside,(float)LENGTH+extra,quadside);
            GL::Vertex3(-quadside,(float)LENGTH+extra,-quadside);
            GL::Vertex3(quadside,(float)LENGTH+extra,-quadside);

            GL::Vertex3(quadside,quadside,(float)LENGTH+extra);
            GL::Vertex3(-quadside,quadside,(float)LENGTH+extra);
            GL::Vertex3(-quadside,-quadside,(float)LENGTH+extra);
            GL::Vertex3(quadside,-quadside,(float)LENGTH+extra);

        }
        GL::End();


        // --> triangulos para hacer la punta
        GL::Begin(BeginMode::Triangles);
        if(opciones->draw3DXYaxis){
            GL::Vertex3((float)LENGTH+extra,quadside,quadside);
            GL::Vertex3((float)LENGTH+extra,-quadside,quadside);
            GL::Vertex3(LENGTH+extra+5,0,0);
            GL::Vertex3((float)LENGTH+extra,-quadside,quadside);
            GL::Vertex3((float)LENGTH+extra,-quadside,-quadside);
            GL::Vertex3(LENGTH+extra+5,0,0);
            GL::Vertex3((float)LENGTH+extra,-quadside,-quadside);
            GL::Vertex3((float)LENGTH+extra,quadside,-quadside);
            GL::Vertex3(LENGTH+extra+5,0,0);
            GL::Vertex3((float)LENGTH+extra,quadside,-quadside);
            GL::Vertex3((float)LENGTH+extra,quadside,quadside);
            GL::Vertex3(LENGTH+extra+5,0,0);

            GL::Vertex3(quadside,(float)LENGTH+extra,quadside);
            GL::Vertex3(-quadside,(float)LENGTH+extra,quadside);
            GL::Vertex3(0,LENGTH+extra+5,0);
            GL::Vertex3(-quadside,(float)LENGTH+extra,quadside);
            GL::Vertex3(-quadside,(float)LENGTH+extra,-quadside);
            GL::Vertex3(0,LENGTH+extra+5,0);
            GL::Vertex3(-quadside,(float)LENGTH+extra,-quadside);
            GL::Vertex3(quadside,(float)LENGTH+extra,-quadside);
            GL::Vertex3(0,LENGTH+extra+5,0);
            GL::Vertex3(quadside,(float)LENGTH+extra,-quadside);
            GL::Vertex3(quadside,(float)LENGTH+extra,quadside);
            GL::Vertex3(0,LENGTH+extra+5,0);

        }
        if(opciones->draw3DXZaxis){
            GL::Vertex3((float)LENGTH+extra,quadside,quadside);
            GL::Vertex3((float)LENGTH+extra,-quadside,quadside);
            GL::Vertex3(LENGTH+extra+5,0,0);
            GL::Vertex3((float)LENGTH+extra,-quadside,quadside);
            GL::Vertex3((float)LENGTH+extra,-quadside,-quadside);
            GL::Vertex3(LENGTH+extra+5,0,0);
            GL::Vertex3((float)LENGTH+extra,-quadside,-quadside);
            GL::Vertex3((float)LENGTH+extra,quadside,-quadside);
            GL::Vertex3(LENGTH+extra+5,0,0);
            GL::Vertex3((float)LENGTH+extra,quadside,-quadside);
            GL::Vertex3((float)LENGTH+extra,quadside,quadside);
            GL::Vertex3(LENGTH+extra+5,0,0);

            GL::Vertex3(quadside,quadside,(float)LENGTH+extra);
            GL::Vertex3(-quadside,quadside,(float)LENGTH+extra);
            GL::Vertex3(0,0,LENGTH+extra+5);
            GL::Vertex3(-quadside,quadside,(float)LENGTH+extra);
            GL::Vertex3(-quadside,-quadside,(float)LENGTH+extra);
            GL::Vertex3(0,0,LENGTH+extra+5);
            GL::Vertex3(-quadside,-quadside,(float)LENGTH+extra);
            GL::Vertex3(quadside,-quadside,(float)LENGTH+extra);
            GL::Vertex3(0,0,LENGTH+extra+5);
            GL::Vertex3(quadside,-quadside,(float)LENGTH+extra);
            GL::Vertex3(quadside,quadside,(float)LENGTH+extra);
            GL::Vertex3(0,0,LENGTH+extra+5);
         }
         if(opciones->draw3DYZaxis){
            GL::Vertex3(quadside,(float)LENGTH+extra,quadside);
            GL::Vertex3(-quadside,(float)LENGTH+extra,quadside);
            GL::Vertex3(0,LENGTH+extra+5,0);
            GL::Vertex3(-quadside,(float)LENGTH+extra,quadside);
            GL::Vertex3(-quadside,(float)LENGTH+extra,-quadside);
            GL::Vertex3(0,LENGTH+extra+5,0);
            GL::Vertex3(-quadside,(float)LENGTH+extra,-quadside);
            GL::Vertex3(quadside,(float)LENGTH+extra,-quadside);
            GL::Vertex3(0,LENGTH+extra+5,0);
            GL::Vertex3(quadside,(float)LENGTH+extra,-quadside);
            GL::Vertex3(quadside,(float)LENGTH+extra,quadside);
            GL::Vertex3(0,LENGTH+extra+5,0);

            GL::Vertex3(quadside,quadside,(float)LENGTH+extra);
            GL::Vertex3(-quadside,quadside,(float)LENGTH+extra);
            GL::Vertex3(0,0,LENGTH+extra+5);
            GL::Vertex3(-quadside,quadside,(float)LENGTH+extra);
            GL::Vertex3(-quadside,-quadside,(float)LENGTH+extra);
            GL::Vertex3(0,0,LENGTH+extra+5);
            GL::Vertex3(-quadside,-quadside,(float)LENGTH+extra);
            GL::Vertex3(quadside,-quadside,(float)LENGTH+extra);
            GL::Vertex3(0,0,LENGTH+extra+5);
            GL::Vertex3(quadside,-quadside,(float)LENGTH+extra);
            GL::Vertex3(quadside,quadside,(float)LENGTH+extra);
            GL::Vertex3(0,0,LENGTH+extra+5);

        }
        GL::End();
        Write3D(LENGTH,3,3,GLUT_BITMAP_9_BY_15,"X");
        Write3D(3,LENGTH,3,GLUT_BITMAP_9_BY_15,"Y");
        Write3D(3,3,LENGTH,GLUT_BITMAP_9_BY_15,"Z");
     }

1 个答案:

答案 0 :(得分:2)

尝试在绘制每组对象之前禁用深度测试(首先是参考平面,然后是第二个轴,然后是参考网格)。

看起来你的轴与参考平面是Z形的。

您有多种选择 -

  1. 绘制线条(而不是平面)时禁用深度测试。这将确保不会发生z-fighting。
  2. 继续深度测试,但在绘制平面时使用glPolygonOffset来抵消它们,这样就不会发生z-fighting。
  3. 绘制平面时使用GL_LEQUAL(或其他任何)作为DepthFunc,但在绘制线时使用GL_EQUAL。这个应该让事情好起来。