# OpenGL: 在空间绘制出一系列螺旋上升的点

#define GLUT_DISABLE_ATEXIT_HACK
#include <math.h>

#include "gl/glut.h"
#pragma comment(lib, "glut32.lib")

void Drawing()
{
GLfloat x, y, z = -50.0f, inc = 0, angle;
glPushMatrix();                             //将当前矩阵压入矩阵堆栈
{
glRotatef(-45.0f, 1.0f, 0.0f, 0.0f);    //将当前坐标系绕X轴旋转-45度
glRotatef(15.0f, 0.0f, 1.0f, 0.0f);     //将当前坐标系再绕Y轴旋转15度

glColor3f(0.0f, 1.0f, 0.0f);            //将绘图色设置为红色
glBegin(GL_POINTS);//注意GL_POINT 跟GL_POINTS的区别
{
for (angle = 0.0f; angle <= 2.0f * 3.14159f * 3.0f; angle += 0.1f)
{
x = inc * sin(angle);           //计算点的X坐标
y = inc * cos(angle);           //计算点的Y坐标
glVertex3f(x, y, z);            //绘制点
z += 0.5f;                      //Z坐标增量
inc += 0.3f;                    //半径增量
}
}
glEnd();
}
glPopMatrix();                              //恢复原矩阵
glutSwapBuffers();							//这里就不用glFlush();
}

void Initialization()
{
glClearColor(0.0f, 0.0f, 0.0f,1.0f);
}

void OnDisplay()
{
glClear(GL_COLOR_BUFFER_BIT);
Drawing();
}

void OnReshape(int w, int h)
{
GLfloat aspect =(GLfloat)w / (GLfloat)h;
GLfloat nRange = 100.0f;

glViewport(0, 0, w, h);

glMatrixMode(GL_PROJECTION);     //将当前矩阵指定为投影模式

//设置三维投影区
if (w <= h)
{
glOrtho(-nRange, nRange, -nRange / aspect, nRange / aspect, -nRange, nRange);
}
else
{
glOrtho(-nRange, nRange, -nRange * aspect, nRange * aspect, -nRange, nRange);
}
glMatrixMode(GL_MODELVIEW);     //将当前矩阵恢复为模型视图模式
}

void main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
glutInitWindowSize(640, 480);
glutInitWindowPosition(10, 10);
glutCreateWindow("绘制三维点");
glutDisplayFunc(OnDisplay);
glutReshapeFunc(OnReshape);

Initialization();
glutMainLoop();
}