Discuz! Board
标题:
[MetaHook]QGL Draw Circle
[打印本页]
作者:
Jerry小坏
时间:
2017-7-14 16:50
标题:
[MetaHook]QGL Draw Circle
#include <math.h>
#define M_PI 3.1415926
GLvoid draw_circle(const GLfloat radius, const GLuint num_vertex)
{
GLfloat vertex[4];
GLfloat texcoord[2];
const GLfloat delta_angle = 2.0 * M_PI / num_vertex;
qglBegin(GL_TRIANGLE_FAN);
{
//draw the vertex at the center of the circle
texcoord[0] = 0.5;
texcoord[1] = 0.5;
qglTexCoord2fv(texcoord);
vertex[0] = vertex[1] = vertex[2] = 0.0;
vertex[3] = 1.0;
qglVertex4fv(vertex);
//draw the vertex on the contour of the circle
for(GLuint i = 0; i < num_vertex ; i++)
{
texcoord[0] = (cos(delta_angle * i) + 1.0) * 0.5;
texcoord[1] = (sin(delta_angle * i) + 1.0) * 0.5;
qglTexCoord2fv(texcoord);
vertex[0] = cos(delta_angle * i) * radius;
vertex[1] = sin(delta_angle * i) * radius;
vertex[2] = 0.0;
vertex[3] = 1.0;
qglVertex4fv(vertex);
}
texcoord[0] = (1.0 + 1.0) * 0.5;
texcoord[1] = (0.0 + 1.0) * 0.5;
qglTexCoord2fv(texcoord);
vertex[0] = 1.0 * radius;
vertex[1] = 0.0 * radius;
vertex[2] = 0.0;
vertex[3] = 1.0;
qglVertex4fv(vertex);
}
qglEnd();
}
复制代码
欢迎光临 Discuz! Board (https://esfbbs.foxnyx.top/)
Powered by Discuz! X3.2