Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 如何使用此代码作为起点在opengl中绘制一个较小的圆?_C_Opengl - Fatal编程技术网

C 如何使用此代码作为起点在opengl中绘制一个较小的圆?

C 如何使用此代码作为起点在opengl中绘制一个较小的圆?,c,opengl,C,Opengl,我试图用opengl在c中画一个圆,比上面显示的要小。问题是我似乎找不到如何缩小它的尺寸……有人能帮我吗 #define GLUT_DISABLE_ATEXIT_HACK #include <GL/gl.h> #include <GL/glut.h> #include <stdio.h> #include <math.h> #define PI 3.1415926535898 GLint circle_points =100; // This

我试图用opengl在c中画一个圆,比上面显示的要小。问题是我似乎找不到如何缩小它的尺寸……有人能帮我吗

#define GLUT_DISABLE_ATEXIT_HACK
#include <GL/gl.h>
#include <GL/glut.h>
#include <stdio.h>

#include <math.h>
#define PI 3.1415926535898
GLint circle_points =100;
 // This is the draw function.
void draw()
{

glClear(GL_COLOR_BUFFER_BIT);
double angle = 2*  PI/circle_points ;
glPolygonMode( GL_FRONT, GL_FILL );
glColor3f(0.2, 0.5, 0.5 );
glBegin(GL_POLYGON);
    double angle1=0.0;
    glVertex2d( cos(0.0) , sin(0.0));
    int i;
    for ( i=0 ; i< circle_points ;i++)
    {
        printf( "angle = %f \n" , angle1);
        glVertex2d(cos(angle1),sin(angle1));
        angle1 += angle ;
    }
glEnd();
glFlush();
}

void init()
{
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);
}

void keyboard (unsigned char key , int x, int y)
{
exit(0);

}

void main( int argc,char **argv)
 {
     glutInit(&argc,argv);
 glutInitDisplayMode(GLUT_SINGLE |GLUT_RGB);
 glutInitWindowSize(250,250);
 glutInitWindowPosition(100,100);
 glutCreateWindow("ch06");
 init();
 glutKeyboardFunc(keyboard);
 glutDisplayFunc(draw);
        glutMainLoop();
 }
#定义过剩、禁用、退出
#包括
#包括
#包括
#包括
#定义PI 3.1415926535898
闪烁圆_点=100;
//这是draw函数。
作废提款()
{
glClear(GLU颜色缓冲位);
双角度=2*PI/圆_点;
glPolygonMode(GL_前端,GL_填充);
GL3F(0.2,0.5,0.5);
glBegin(GL_多边形);
双角度1=0.0;
glVertex2d(cos(0.0),sin(0.0));
int i;
对于(i=0;i
您可以更改行:

    glVertex2d(cos(angle1),sin(angle1)); 
    glVertex2d(cos(0.0),sin(0.0)); 
致:

这将绘制一个半径为0.25而不是1的圆

编辑:如DASN所示,您还需要将
0.25f*
添加到行:

    glVertex2d(cos(angle1),sin(angle1)); 
    glVertex2d(cos(0.0),sin(0.0)); 

当然,您也可以使用以下命令在图形代码前加上前缀:

glScalef(0.25f, 0.25f, 1.0f);
但这将更改您的modelview矩阵,因此最好也使用矩阵堆栈保留它:

glPushMatrix();
glScalef(0.25, 0.25f, 1.0f);
/* drawing code goes here. */
glPopMatrix();

thanx,我还必须改变这句话:glVertex2d(cos(0.0),sin(0.0));但你的回答很准确。塔克斯