openGl代码入门笔记

来源:互联网 发布:淘宝美工网站 编辑:程序博客网 时间:2024/05/21 12:25
</pre><pre name="code" class="cpp">// ConsoleApplication1.cpp : Defines the entry point for the console application.//#include <stdafx.h> #include <GL/glut.h>//引入头文件glut.h,包含了gl.h和glu.hvoid init(void){glClearColor(0.5, 0.5, 0.5, 0.0);//使用glClearColor函数清空颜色缓冲区,新值由参数指定,参数顺序为r-g-b-a//其中参数a即alpha,代表不透明度,但在本代码中不造为何0.0-1.0不能观察出变化glMatrixMode(GL_PROJECTION);//指定一个矩阵模式用作下一次矩阵操作的目标gluOrtho2D(0.0, 200.0, 0.0, 150.0);}void lineSegment(void){glClear(GL_COLOR_BUFFER_BIT);glColor3f(1.0, 0.0, 0.0);glBegin(GL_LINES);glVertex2i(180, 15);glVertex2i(10, 145);glEnd();int point1[] = { 100, 100 };glBegin(GL_POINTS);for (int i = 0; i < 20; ++i){glVertex2iv(point1);point1[0]++;point1[1]++;}glEnd();glFlush();}int main(int argc, char *argv[]){glutInit(&argc, argv);//GLUT(OpenGL实用函数工具包)初始化glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);//设置初始显示模式(显示窗口的缓存、颜色模型等等)glutInitWindowPosition(0, 0);//设置显示窗口左上角的位置,X轴向右,Y轴向下glutInitWindowSize(400, 400);//初始化窗口尺寸glutCreateWindow("openGL");//窗口创建init();glutDisplayFunc(lineSegment);//调用图形显示函数glutMainLoop();//激活显示窗口及其内部图形内容(非交互?)return 0;}


0 0