OpenGL GL_POLYGON 凹多边形不着色

OpenGL GL_POLYGON concave polygon doesn#39;t color in(OpenGL GL_POLYGON 凹多边形不着色)
本文介绍了OpenGL GL_POLYGON 凹多边形不着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

当我尝试在 OpenGL 中使用多边形时遇到问题.我不知道如何解释这一点,但我所有的顶点都与开始的顶点相连.当我尝试为对象着色时会出现问题.我想画一个简单的对象.

I have a problem when I try to use Polygon in OpenGL. I don't know how to explain this but all my vertices are connected with the beginning one. The problem happens when I try to color the object. I want to draw a simple object.

void TOP (float x1, float y1, float x2, float h,float n)
{
  float r = x2-x1;
  if(n==1){glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);} // FOR FILL OR NO FILL OBJECT
  glBegin(GL_POLYGON);
     glVertex2f(x1,y1);
     glVertex2f(x2,y1);
     glVertex2f(x2,y1+h/7);
     y1=y1+h/7;
     glVertex2f(x2-r/5,y1+h/7);
     x2=x2-r/5; y1=y1+h/7;
     glVertex2f(x2,y1+2*h/7);
     y1=y1+2*h/7;
      glVertex2f(x2+r/5,y1+h/7);
      y1=y1+h/7; x2=x2+r/5;
      glVertex2f(x2,y1+2*h/7);
cout<<y1<<endl;
      y1=y1+2*h/7;
       glVertex2f(x2-r/5,y1); x2=x2-r/5;
      glVertex2f(x2,y1-h/7); y1=y1-h/7;
      glVertex2f(x2-r/5,y1);x2=x2-r/5;
      glVertex2f(x2,y1+h/7); y1=y1+h/7;
      glVertex2f(x2-r/5,y1);x2=x2-r/5;

       glVertex2f(x2,y1-h/7); y1=y1-h/7;
       glVertex2f(x2-r/5,y1);x2=x2-r/5;
        glVertex2f(x2,y1+h/7); y1=y1+h/7;
         glVertex2f(x2-r/5,y1);x2=x2-r/5;
         glVertex2f(x2,y1-2*h/7);y1=y1-2*h/7;
         glVertex2f(x2+r/5,y1-h/7);y1=y1-h/7; x2=x2+r/5;
         glVertex2f(x2,y1-2*h/7); y1=y1-2*h/7;
         glVertex2f(x2-r/5,y1-h/7); y1=y1-h/7;x2=x2-r/5;
          glVertex2f(x2,y1-h/7);

  glEnd();
}

输出:

推荐答案

GL_POLYGON 仅适用于 凸多边形一个>:

GL_POLYGON:绘制单个凸多边形.顶点 1N 定义了这个多边形.

GL_POLYGON: Draws a single, convex polygon. Vertices 1 through N define this polygon.

对于凹多边形,您至少有两个选择:

For concave polygons you have at least two options:

  1. 对多边形进行三角剖分并使用GL_TRIANGLES.

使用模板缓冲技巧.

这篇关于OpenGL GL_POLYGON 凹多边形不着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Prevent class inheritance in C++(防止 C++ 中的类继承)
Why should I declare a virtual destructor for an abstract class in C++?(为什么要在 C++ 中为抽象类声明虚拟析构函数?)
Why is Default constructor called in virtual inheritance?(为什么在虚拟继承中调用默认构造函数?)
C++ cast to derived class(C++ 转换为派生类)
C++ virtual function return type(C++虚函数返回类型)
Is there any real risk to deriving from the C++ STL containers?(从 C++ STL 容器派生是否有任何真正的风险?)