gpt4 book ai didi

c++ - opengl画半圆

转载 作者:行者123 更新时间:2023-11-30 17:02:27 26 4
gpt4 key购买 nike

我正在尝试画半个圆;当我运行代码时,我没有收到任何错误,但没有打印任何内容。有人可以让我知道我做错了什么吗?我尝试更改窗口位置,但没有成功。

#include<GL/glut.h>
#include <math.h>

void DrawHalfCircle()
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glColor4f(1, 0, 0, 0);
int number = 20; //number of vertices,
float radius = 0.4f; // radius of the circle
float twopi = 2.0f*3.14159f;
glMatrixMode(GL_MODELVIEW); //operate in model view
glLoadIdentity();//after every matrixmode, loadidentity is used.
glTranslatef(0.5f, 0.0f, 0.0f); //to move the position of circle towards +ve x axis
glBegin(GL_TRIANGLE_FAN); //drawing circle using triangle fan
glColor3f(0.0f, 0.0f, 1.0f); //blue in color
glVertex2f(0.0f, 0.0f); //placing at the origin
for (int i = 0; i <= 21; i++)
glVertex2f(radius*cosf(i*twopi / number), radius*sinf(i*twopi / number));
glEnd();
glFlush();
}

主要内容

 int main()

{
glutInit(&argc, argv); //initialize glut
glutInitWindowSize(640, 480); //width and height
glutInitWindowPosition(0, 50); //bottom-left corner
glutCreateWindow("drawing half a circle");
glutDisplayFunc(DrawHalfCircle);
glutMainLoop(); //loops itself again and again
return 0;

}

最佳答案

这两个函数画了 2 个半圆,一个是实心的,另一个是空心的。(在 C++ 中),我猜你的 main 是正确的。

void drawLeftCircle()   // the filled one
{
float radius = 70;
float twoPI = 2 * PI;

glBegin(GL_TRIANGLE_FAN);

for (float i = PI; i <= twoPI; i += 0.001)
glVertex2f((sin(i)*radius), (cos(i)*radius));

glEnd();
glFlush();
}


void drawRightHalfCircle() // the empty one
{
float radius = 70;
float twoPI = 2 * PI;

glBegin(GL_POINTS);

for (float i = 0.0; i <= twoPI / 2; i += 0.001)
glVertex2f((sin(i)*radius), (cos(i)*radius));

glEnd();
glFlush();
}

关于c++ - opengl画半圆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36538563/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com