rof*_*s91 1 c opengl visual-c++
我正在尝试使用Visual C++中的OpenGL构建六边形模型.我以某种方式无法检索正确的输出.
#include <windows.h>
#include <glut.h>
#include <math.h>
float x, inc = 3.14/6, pi = 3.14;
void RenderScene()
{
glColor3f(1,1,0);
for ( x=0.0; x<2*pi; x=x+inc )
{
glBegin(GL_LINE_STRIP);
glVertex2f(cos(x),sin(x));
glEnd();
}
}
void myDisplay(void)
{
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
RenderScene();
glPopMatrix();
glFlush();
}
void SetupRC(void)
{
glClearColor(0.0, 0.0, 1.0, 1.0);
glOrtho(-5.0,5.0,-5.0,5.0,-5.0,5.0);
}
void main(void)
{
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(640,480);
glutInitWindowPosition(10,15);
glutCreateWindow("Rofans Manao");
glutDisplayFunc(myDisplay);
SetupRC();
glutMainLoop();
}
Run Code Online (Sandbox Code Playgroud)
以上是我的代码.我的代码以前曾经工作过.我相信我做了一些看不见的错误.
你RenderScene()现在有以下循环:
for ( x=0.0; x<2*pi; x=x+inc )
{
glBegin(GL_LINE_STRIP);
glVertex2f(cos(x),sin(x));
glEnd();
}
Run Code Online (Sandbox Code Playgroud)
我想你打算这样做
glBegin(GL_LINE_STRIP);
for ( x=0.0; x<2*pi; x=x+inc )
{
glVertex2f(cos(x),sin(x));
}
glEnd();
Run Code Online (Sandbox Code Playgroud)
相反,出现某种形式的线条.