Discuz! Board

标题: [MetaHook]QGL Draw Circle [打印本页]

作者: Jerry小坏    时间: 2017-7-14 16:50
标题: [MetaHook]QGL Draw Circle

  1. #include <math.h>

  2. #define M_PI 3.1415926

  3. GLvoid draw_circle(const GLfloat radius, const GLuint num_vertex)  
  4. {  
  5.     GLfloat vertex[4];   
  6.     GLfloat texcoord[2];  
  7.   
  8.     const GLfloat delta_angle = 2.0 * M_PI / num_vertex;  
  9.   
  10.     qglBegin(GL_TRIANGLE_FAN);  
  11.     {  
  12.         //draw the vertex at the center of the circle  
  13.         texcoord[0] = 0.5;  
  14.         texcoord[1] = 0.5;  
  15.         qglTexCoord2fv(texcoord);  
  16.         vertex[0] = vertex[1] = vertex[2] = 0.0;  
  17.         vertex[3] = 1.0;         
  18.         qglVertex4fv(vertex);  
  19.   
  20.         //draw the vertex on the contour of the circle  
  21.         for(GLuint i = 0; i < num_vertex ; i++)  
  22.         {  
  23.             texcoord[0] = (cos(delta_angle * i) + 1.0) * 0.5;  
  24.             texcoord[1] = (sin(delta_angle * i) + 1.0) * 0.5;  
  25.             qglTexCoord2fv(texcoord);  
  26.   
  27.             vertex[0] = cos(delta_angle * i) * radius;  
  28.             vertex[1] = sin(delta_angle * i) * radius;  
  29.             vertex[2] = 0.0;  
  30.             vertex[3] = 1.0;  
  31.             qglVertex4fv(vertex);  
  32.         }  
  33.   
  34.         texcoord[0] = (1.0 + 1.0) * 0.5;  
  35.         texcoord[1] = (0.0 + 1.0) * 0.5;  
  36.         qglTexCoord2fv(texcoord);  
  37.   
  38.         vertex[0] = 1.0 * radius;  
  39.         vertex[1] = 0.0 * radius;  
  40.         vertex[2] = 0.0;  
  41.         vertex[3] = 1.0;  
  42.         qglVertex4fv(vertex);  
  43.     }  
  44.     qglEnd();   
  45. }
复制代码





欢迎光临 Discuz! Board (https://esfbbs.foxnyx.top/) Powered by Discuz! X3.2