您的位置:首页 > 编程语言

openGl代码入门笔记

2016-01-23 01:35 411 查看
</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.h

void 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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  OpenGL 图形学