如何在opengl中绘制一个实心圆 [英] how to draw a filled circle in opengl

查看:1370
本文介绍了如何在opengl中绘制一个实心圆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在OpenGL中制作好的,漂亮的圆形填充2D圆圈时遇到了一些麻烦。我使用GNU C编译器,CodeBlocks IDE和Windows XP。下面的代码生成一个椭圆,看起来更像是一个番茄,因为它的宽度有多高。所以问题是,如何在中间缩小以使其像实际圆圈一样更圆。



Hi, I'm having a bit of trouble making a good, nice, round, filled 2D circle in OpenGL. I use GNU C compiler, CodeBlocks IDE and Windows XP. The following code produces an ellipse that looks more like a "tomato" in the sense that it is wide for how tall it is. So the problem is, how to "thin it out" in the middle to make it more round like an actual circle.

//filled circle
float x1,y1,x2,y2;
float angle;
double radius=0.1;

x1 = 0.5,y1=0.6;
glColor3f(1.0,1.0,0.6);

glBegin(GL_TRIANGLE_FAN);
glVertex2f(x1,y1);

for (angle=1.0f;angle<361.0f;angle+=0.2)
{
    x2 = x1+sin(angle)*radius;
    y2 = y1+cos(angle)*radius;
    glVertex2f(x2,y2);
}

glEnd();

推荐答案

今天早上我发生了变化输出窗口为1:1的方形,如600x600,一旦我做了,一切都很完美,所以我觉得已达到完美,哈哈。尽管如此,我可以自由地运行一些关于gluOrtho2d和gluPerspective的东西,因为我的IDE /编译器(codeblocks / gnu)中的自动代码不使用它们。无论如何,听起来这些对4:3和诸如此类的东西都很有用,再次感谢你的时间,Saurabh。-B
Well it occured to me this morning to change the output window to a 1:1 square shape, like 600x600 and once I did, everything was perfect, so I guess perfection has been reached, haha. Nonetheless, feel free to run something past me about gluOrtho2d and gluPerspective, because the auto-code from my IDE/compiler (codeblocks/gnu) doesn't use those. At any rate, it sounds like those are useful for 4:3 and whatnot, and thanks again for your time, Saurabh.-B


是的,那肯定是宽高比。您使用哪个函数初始化相机 - gluOrtho2D或gluPerspective?你需要将这些函数的参数与窗口的宽高比相匹配。



-Saurabh
Yes then it is definitely about aspect ratio. Which function are you using for initialize camera - gluOrtho2D or gluPerspective? You need to match the parameters to these functions with the aspect ratio of the window.

-Saurabh


sin和cos期望角度为弧度而不是度数。



sin and cos expects angle to be in radians and not in degrees.

bala_48225写道:
bala_48225 wrote:

for (角度= 1.0f;角度<361.0f;角度+ = 0.2)

for (angle=1.0f;angle<361.0f;angle+=0.2)





尝试:

for(angle = 0.0f; angle< 2 * 3.14159; angle + = 0.2)



-Saurabh



Try:
for(angle=0.0f ; angle<2*3.14159 ; angle+=0.2)

-Saurabh


这篇关于如何在opengl中绘制一个实心圆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆