Open Graphics Library (OpenGL) is a cross-language, cross-platform application programming interface (API) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardware-accelerated rendering. (wikipedia)
要求
以上 FROM ZJUCG
六角星……
思路
根据尺寸要求首先对12个点中6个未标示的点的坐标进行计算。
其中两个为(0.1,0.3)(0.25,0)其余由对称可得。对颜色进行分析。中点(0,0)为白色,周围一圈边界为一段纯色一段渐变。(这里mark一下 矩形的内部填充不知道是怎么实现的。三角形的填充可以认为,比如投影到R坐标系中的三个点,那中间任意一个点的R是可以用线性进行确定的)
OrenGL相关
具体可以参考
http://www.cppblog.com/doing5552/archive/2009/01/08/71532.html
头文件
#include <GL/glut.h>
主函数
int main(int argc, char *argv[])
{
glutInit(&argc, argv); //对GLUT进行初始化
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); //设置显示方式,RGB 单缓存&多缓存
glutInitWindowPosition(100, 100); //窗口在屏幕中的位置
glutInitWindowSize(400, 400);//窗口的大小
glutCreateWindow("Birdy's OpenGL");//创建窗口
glutDisplayFunc(&myDisplay);
glutMainLoop();//循环
return 0;
}
简单的绘制
glBegin — delimit the vertices of a primitive or a group of like primitives
与glEnd对应 为一次绘制
glBegin说明
https://www.khronos.org/registry/OpenGL-Refpages/gl2.1/xhtml/glBegin.xml
glColor3f(1, 0, 0); //选择红色
glBegin(GL_QUADS);//开始绘制 矩形
{
glVertex2f(-0.9, 0.6);
glVertex2f(0.9, 0.6);
glVertex2f(0.9, -0.6);
glVertex2f(-0.9, -0.6);
}
glEnd();//结束
实现
对glBegin的模式进行分析后认为GL_TRIANGLE_FAN比较符合预期。
GL_TRIANGLE_FAN:Draws a connected group of triangles. One triangle is defined for each vertex presented after the first two vertices.
以中心为第一个绘制的点。
函数如下
/*@author Birdy@C*/
//确定每个点的坐标
const GLfloat point[2][12] =
{
{ 0, 0.1, 0.4, 0.25, 0.4, 0.1, 0,-0.1, -0.4, -0.25, -0.4, -0.1 },
{ 0.5, 0.3, 0.3, 0, -0.3, -0.3, -0.5, -0.3, -0.3,