[英]Circle doesn't appear on the screen
The following code doesn't show the circle on the screen, why doesn't work? 以下代码未在屏幕上显示圆圈,为什么不起作用? I can't see any error.
我看不到任何错误。
void display(void){
glClear(GL_COLOR_BUFFER_BIT);
int circle_points=100;
int i;
double theta,cx=200, cy=300,r=100;
int MyCircle(){
glBegin(GL_LINE_LOOP);
glColor3f(1.0,1.0,1.0); //preto
for(i=0;i<circle_points;i++){
theta=(2*pi*i)/circle_points;
glVertex2f(cx+r*cos(theta),cy+r*sin(theta));
}
glEnd();
}
glFlush();
}
No idea why you are trying to declare a function inside a function. 不知道为什么要尝试在函数内部声明一个函数。 I'm not quite sure how that compiled, much less ran.
我不太确定该如何编译,更不用说运行了。
The logic is sound though: 逻辑是合理的:
#include <GL/glut.h>
#include <math.h>
void MyCircle( void )
{
const int circle_points=100;
const float cx=0, cy=0, r=100;
const float pi = 3.14159f;
int i = 0;
glBegin(GL_LINE_LOOP);
glColor3f(1.0,1.0,1.0); //preto
for(i=0;i<circle_points;i++)
{
const float theta=(2*pi*i)/circle_points;
glVertex2f(cx+r*cos(theta),cy+r*sin(theta));
}
glEnd();
}
void display( void )
{
const double w = glutGet( GLUT_WINDOW_WIDTH );
const double h = glutGet( GLUT_WINDOW_HEIGHT );
const double ar = w / h;
glClear( GL_COLOR_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( -150 * ar, 150 * ar, -150, 150, -1, 1 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
MyCircle();
glutSwapBuffers();
}
int main( int argc, char **argv )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );
glutInitWindowSize( 640, 480 );
glutCreateWindow( "GLUT" );
glutDisplayFunc( display );
glutMainLoop();
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.