OpenGL Overview

转自:http://www.songho.ca/opengl/gl_overview.html

opengl 概述

状态机

glBegin()glEnd()

glFlush() glFinish()

1.概述

opengl 是一个软件接口,用于访问图形硬件.拥有跨平台性,独立于硬件接口,使用到大量不同的硬件平台.网络性,即客户端和服务端在不同的计算机上.客户端指执行opengl程序的计算机,服务端指用于绘制的计算机.

opengl命名方式: 核心函数库命令 前缀gl

                            实用库命令 前缀glu

                            常量 GL_和大写字母

                            后缀  定义参数个数 和 数据类型 示例:glColor3f(1.0, 0.0, 0.0) 

2.状态机

Opengl是一个状态机.状态机包含模式和属性,它们被设置后一直有效状态,知道被修改.模式启用禁用查询:glEnable() glDisable() glIsEnabled().属性保存恢复:glPushAttrib() glPopAttrib()

示例:

glPushAttrib(GL_LIGHTING_BIT); // elegant way to change states because

glDisable(GL_LIGHTING); // you can restore exact previous states

glEnable(GL_COLOR_MATERIAL); // after calling

glPopAttrib(); // restore GL_LIGHTING_BIT

3.glBegin() glEnd() 

用于绘制几何图元.在glBegin()和 glEnd() 之间,可以设置一些列顶点数据.这种方式被称为立即显示模式. 

void glBegin( GLenum mode )

参数:

mode 

Specifies the primitive or primitives that will be created from vertices presented between glBegin and the subsequent glEnd. Ten symbolic constants are accepted: GL_POINTSGL_LINESGL_LINE_STRIPGL_LINE_LOOPGL_TRIANGLESGL_TRIANGLE_STRIPGL_TRIANGLE_FANGL_QUADSGL_QUAD_STRIP, and GL_POLYGON.

注意事项:Only a subset of GL commands can be used between glBegin and glEnd.The commands are glVertexglColorglIndexglNormalglTexCoordglEvalCoordglEvalPointglMaterial, and glEdgeFlag. Also, it is acceptable to use glCallList or glCallLists to execute display lists that include only the preceding commands. If any other GL command is called between glBegin and glEnd, the error flag is set and the command is ignored.

错误:

GL_INVALID_ENUM is generated if mode is set to an unaccepted value. 

GL_INVALID_OPERATION is generated if a command other than glVertexglColorglIndexglNormalglTexCoordglEvalCoordglEvalPointglMaterialglEdgeFlagglCallList, or glCallLists is called between glBegin and the corresponding glEnd.

GL_INVALID_OPERATION is generated if glEnd is called before the corresponding glBegin is called, or if glBegin is called within a glBegin/glEnd sequence.

示例:

glBegin(GL_TRIANGLES);

glColor3f(1, 0, 0); // set vertex color to red

glVertex3fv(v1); // draw a triangle with v1, v2, v3

glVertex3fv(v2);

glVertex3fv(v3);

glEnd();

4.glFlush() glFinish()

opengl命令不是立即被执行,所有的命令存储在缓冲中,直到缓冲被填满,才执行.为了提高效率而考虑,比如网络传输中一条命令执行一次传输和将命令打包成组一次性发出去相比,效率就会比较差.

glFlush() 清空缓冲中所有命令,强迫所有缓冲中的命令立即执行,而不需要等待缓冲被填满.glFlush命令执行后,立即返回,但所有的命令都会被执行完成,在特定的时间内。

glFinish() 跟glFlush()一样,有所不同的是:等待所有命令被执行完成后,才返回.如果你需要同步一些事物,需要用的到.

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值