OpenGL 入门

OpenGL(Open Graphics Library,开放式图形库)是用于渲染 2D、3D 矢量图形的跨语言、跨平台的应用程序编程接口。这个接口由近350个不同的函数调用组成,用来绘制从简单的图形到复杂的三维景象。OpenGL常用于CAD、虚拟现实、科学可视化程序和电子游戏开发。

这里使用 freeglut 库进行学习

  • glBegin()
    • GL_POINTS: individual points
    • GL_LINES: pairs of vertices interpreted as individual line segments
    • GL_LINE_STRIP: series of connected line segments
    • GL_LINE_LOOP: same as above, with a segment added between last and fist vertives.
    • GL_TRIANGLES: triples of vertices interpreted as triangles
    • GL_TRIANGLE_STRIP: linked strip of triangles
    • GL_TRIANGLE_FAN: inked fan of triangles
    • GL_QUADS: quadruples of vertices interpreted as four-sided polygons.
    • GL_QUAD_STRIP: linked strip of quadrilaterals
    • GL_POLYGON: boundary of a simple, convex polygon

示例:

glBegin(GL_POINTS);
glVertex2f(100.0f, 100.0f);
glEnd();
glBegin(GL_LINES);
glVertex2f(100.0f, 100.0f);
glVertex2f(200.0f, 140.0f);
glEnd();

OpenGL transformation functions (GL_MODELVIEW)

  • glTranslate(x, y, z): 沿 (x, y, z) 方向平移
  • glRotate(x, y, z): 以 (x, y, z) 为轴旋转
  • glScale(x, y, z): 从原点向外缩放,(x, y, z) 为各方向缩放比例
  • glMatrixMode: Specify current matrix for geometric-viewing, projection, texture or colour transformations
  • glLoadIdentity: Set current matrix to identity
  • glLoadMatrix: Set elements of current matrix
  • glMultMatrix
  • glGetIntegerv: Get max stack depth or current number of matrices in the stack for selected matrix mode
  • glPushMatrix: Copy the top matrix in the stack and store copy in the second stack position
  • glPopMatrix: Erase top matrix in stack and move second matrix to top stack
  • glPixelZoom: Specify 2D scaling parameters for raster operations

Note that the last matrix specified in the program is the first applied.

Projection Functions (GL_PROJECTION)

  • gluLookAt(eye_position, look_at, look_up): 相机和参考点的坐标,look_up 是向上向量,用来投影出 y 轴正方向。
  • glOrtho(left, right, bottom, top, near, far)
  • glFrustum(left, right, bottom, top, near, far)
  • gluPerspective(fov, aspect, near, far): less often used than glFrustum()
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

SP FA

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值