Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2|回复: 0
打印 上一主题 下一主题

[MetaHook]QGL Draw Circle

[复制链接]

189

主题

189

帖子

580

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
580
跳转到指定楼层
楼主
发表于 2017-7-14 16:50:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

  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. }
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Comsenz Inc.  

GMT+8, 2026-10-26 05:55 , Processed in 0.199030 second(s), 22 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表