使用以下在opengl中绘制实心圆的函数,如何使其显示在窗口的不同坐标处?
我有以下代码在 opengl 中绘制一个实心圆。问题是它绘制在屏幕的中心。我如何让它绘制在它的另一个位置?
这是代码:
#define CIRCLE_RADIUS = 0.15f
int circle_points = 100;
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( CIRCLE_RADIUS * cos(0.0) , CIRCLE_RADIUS * sin(0.0));
int i;
for (i = 0; i < circle_points; i++)
{
glVertex2d(CIRCLE_RADIUS * cos(angle1), CIRCLE_RADIUS *sin(angle1));
angle1 += angle ;
}
glEnd();
glFlush();
}
I have got the following code to draw a filled circle in opengl. The problem is that it draws at the center of the screen. How do I make it draw in another position of it?
Here is the code:
#define CIRCLE_RADIUS = 0.15f
int circle_points = 100;
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( CIRCLE_RADIUS * cos(0.0) , CIRCLE_RADIUS * sin(0.0));
int i;
for (i = 0; i < circle_points; i++)
{
glVertex2d(CIRCLE_RADIUS * cos(angle1), CIRCLE_RADIUS *sin(angle1));
angle1 += angle ;
}
glEnd();
glFlush();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最明显的方法是首先调用
glTranslate
。但请注意,通过结合使用glPointSize
和glPoint
,您已经可以更轻松地完成相同的任务:在开始绘制圆圈之前,您需要类似的内容:
否则,你的“圆圈”最终可能会变成正方形。
编辑:在不知道如何设置坐标的情况下,不可能知道“左上角”位置是什么,但您可以这样做:
然后您可以调用(例如):
当然,我的方向假设没有(例如)旋转您的视图,因此
x
向右增加,y
向上增加。The obvious way would be to call
glTranslate
first. Note, however, that you can already accomplish the same a bit more easily with a combination ofglPointSize
andglPoint
:Before you start drawing the circles, you'll want something like:
Otherwise, your "circles" could end up as squares.
Edit: Without knowing how you've set up your coordinates, it's impossible to know what the "top-left" position is, but you could do something like this:
You could then call (for example):
Of course, the directions I've given assume haven't (for example) rotated your view, so
x
increases to the right andy
increases upward.