在我的OpenGL程序中绘制七边形时遇到问题。我想在一个矩形内绘制一个七边形,到目前为止我可以绘制红色矩形,但七边形不会出现。
我不认为我需要转换为学位,除非我想要旋转它吗?这是我的代码:
void CChildView::OnGLDraw(CDC* pDC)
{
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
int width, height;
GetSize(width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, // left
1.0, // right
0.0, // bottom
GLdouble(height) / GLdouble(width), // top
1.0, // near
-1.0); // far
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glColor3d(1., 0., 0.);
glBegin(GL_POLYGON); // Rectangle
glVertex2d(0.25, 0.25);
glVertex2d(0.75, 0.25);
glVertex2d(0.75, 0.75);
glVertex2d(0.25, 0.75);
glEnd();
glColor3d(1., 1., 1.);
int numPoints = 7; // Heptagon
double x, y;
double radius = 0;
double centerx = 0;
double centery = 0;
glBegin(GL_POLYGON);
for (int i = 0; i < numPoints; i++)
{
x = centerx + radius * sin(2.0*M_PI*i / numPoints);
y = centery + radius * cos(2.0*M_PI*i / numPoints);
glVertex2d(x, y);
}
glEnd();
glColor3d(0., 1., 0.);
glBegin(GL_LINES);
glVertex2d(m_linefmx, m_linefmx);
glVertex2d(m_linetox, m_linetoy);
glEnd();
}
答案 0 :(得分:0)
问题是radius
被初始化为0并且从未改变,因此所有点都计算为(0,0)。