【发布时间】:2019-10-15 03:50:44
【问题描述】:
我正在尝试在窗口中绘制一个带有平滑线条的空心圆。由于某种原因,圆圈没有出现。到目前为止,我已经找到了圆的代码,但是线条是锯齿状的,我需要它们是平滑的。我希望能够最终将其他对象放入圆圈与对象接壤的圆圈中。以下是我的代码:
#include <iostream>
#include <math.h>
#include <GL/glut.h> // include GLUT library
#include <GL/gl.h>
#include <GL/glu.h>
#include <stdlib.h>
#include <Windows.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
//#include "RGBpixmap.h"
using namespace std;
void DrawCircle()
{
glBegin(GL_LINE_LOOP);
for (int i = 0; i <= 300; i++) {
double angle = 2 * M_PI * i / 300;
double x = cos(angle);
double y = sin(angle);
glVertex2d(x, y);
}
glEnd();
}
//***********************************************************************************
void myInit()
{
glClearColor(1, 1, 1, 0); // specify a background clor: white
gluOrtho2D(-300, 300, -300, 300); // specify a viewing area
glPointSize(1); // change point size back to 1
}
//***********************************************************************************
void myDisplayCallback()
{
DrawCircle();
glClear(GL_COLOR_BUFFER_BIT); // draw the background
glFlush(); // flush out the buffer contents
}
//***********************************************************************************
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitWindowSize(600, 600); // specify a window size
glutInitWindowPosition(100, 0); // specify a window position
glutCreateWindow("Drawing Window"); // create a titled window
myInit(); // setting up
glutDisplayFunc(myDisplayCallback); // register a callback
glutMainLoop(); // get into an infinite loop
return 0;
}
【问题讨论】: