---
title: "OpenGL"
author: "Perrin Yong"
author_profile: https://www.pystone.net/profile/
published_by: "Perrin Yong"
canonical: https://www.pystone.net/notes/opengl-notes/
type: note
content_role: unspecified
visibility: public
id_stability: rename-stable
source_path: "10-计算机、信息技术与工程/05-游戏图形与运行时/渲染基础/OpenGL.md"
content_hash: e89adc4c5cfd0de846903106b1e5b2cdfb1ae7c0891dedaa2e2a8d84bf22bb46
knowledge_version: 224c990773de.5fa8af6e39fa
site_commit: 224c990773de166d23a886306577dd90379529ce
notes_commit: 5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a
---
# OpenGL

> 创建时间：2020/10/21 22:27

  * OpenGL
    * Overview
      * 什么是OpenGL
      * 01状态机上下文环境
      * 相关程序库
        * Context and window toolkits
          * OpenGL Utility Toolkit (GLUT)
          * freeglut
          * GLFW
        * Extension loading libraries
          * GLEW（OpenGL Extension Wrangler）
      * OpenGL ES
      * 相关学习网站
    * Getting Started
      * 环境搭建
    * Ref

## Overview

### 什么是OpenGL

OpenGL (Open Graphics Library) is a cross-language, cross-platform application programming interface ( **API** ) for rendering 2D and 3D vector graphics. The API is typically used to interact with a graphics processing unit (GPU), to achieve hardware-accelerated rendering.

### 01状态机上下文环境

状态机
状态——当前绘制状态：光照设置，纹理设置

上下文（context）
GLFW库，把上下文信息赋值给要绘图的窗口

### 相关程序库

早期的 OpenGL 版本会一同发布配套的 GLU库(OpenGL Utility Library)，提供一些同时代硬件尚不支持的简单功能。

#### Context and window toolkits

These toolkits are designed to create and manage OpenGL windows, and manage input, but little beyond that.

##### OpenGL Utility Toolkit (GLUT)

> An old windowing handler, no longer maintained.

处理OpenGL程序的工具库，负责处理和底层操作系统的调用以及I/O，并包括了以下常见的功能：

  * 定义以及控制视窗

  * 侦测并处理键盘及鼠标的事件

  * 以一个函数调用绘制某些常用的立体图形，例如长方体、球、以及犹他茶壶（实心或只有骨架，如glutWireTeapot()）

  * 提供了简单菜单列的实现

> GLUT的两个主要目的是创建一个跨平台的库（事实上GLUT就是跨平台的），以及简化学习OpenGL的条件。透过GLUT编写OpenGL通常只需要增加几行额外GLUT的代码，而且不需要知道每个不同操作系统处理视窗的API。

##### freeglut

an open-source alternative to the OpenGL Utility Toolkit (GLUT) library.

GLUT (and hence FreeGLUT) allows the user to **create and manage windows containing OpenGL contexts on a wide range of platforms and also read the mouse, keyboard and joystick functions**. FreeGLUT is intended to be a full replacement for GLUT, and has only a few differences.

Freeglut’s API is a **superset** of the GLUT API, and it is more stable and up to date than GLUT.

> 小知识：superset（超集），对应于subset（子集）。如果一个集合S2中的每一个元素都在集合S1中，且集合S1中可能包含S2中没有的元素，则集合S1就是S2的一个超集，反过来，S2是S1的子集。

##### GLFW

Graphics Library Framework（图形库框架） - A cross-platform **windowing** and **keyboard-mouse-joystick handler** ; is more **game-oriented**
创建并管理窗口和 OpenGL 上下文，同时还提供了处理手柄、键盘、鼠标输入的功能。
可以代替GLUT

#### Extension loading libraries

Given the high workload involved in identifying and loading OpenGL extensions, a few libraries have been designed which **load all available extensions and functions automatically**. Examples include **GLEE** , **GLEW** and **glbinding**.

##### GLEW（OpenGL Extension Wrangler）

GLEW是一个跨平台的C++扩展库，是对底层 OpenGL 接口的封装，能自动识别你的平台所支持的全部OpenGL高级扩展函数，让你的代码跨平台。

> glad：和 glew 作用相同，glew 的升级版

### OpenGL ES

**OpenGL for Embedded Systems** ，是三维图形应用程序接口OpenGL的子集，针对手机、PDA和游戏主机等嵌入式设备而设计。

> OpenGL ES是从OpenGL裁剪定制而来的，去除了glBegin/glEnd，四边形（GL_QUADS）、多边形（GL_POLYGONS）等复杂图元等许多非绝对必要的特性。经过多年发展，现在主要有两个版本，OpenGL ES 1.x针对固定管线硬件的，OpenGL ES 2.x针对可编程管线硬件。OpenGL ES 1.0是以OpenGL 1.3规范为基础的，OpenGL ES 1.1是以OpenGL 1.5规范为基础的，它们分别又支持common和common lite两种profile。lite profile只支持定点实数，而common profile既支持定点数又支持浮点数。OpenGL ES 2.0则是参照OpenGL 2.0规范定义的，common profile发布于2005-8，引入了对可编程管线的支持。OpenGL ES 3.0于2012年公布，加入了大量新特性。

### 相关学习网站

官网 www.opengl.org
一些教程：
open.gl
opengl-tutorial.org
learnopengl <https://learnopengl.com/>
<https://www.khronos.org/opengl/wiki/Getting_Started>
中文教程：<https://wiki.jikexueyuan.com/project/modern-opengl-tutorial/>

## Getting Started

### 环境搭建

<https://blog.csdn.net/xn4545945/article/details/8579485> 正弦函数
<https://blog.csdn.net/Jaihk662/article/details/105496707>
<https://www.cnblogs.com/csu-lmw/p/11587594.html>
<https://blog.csdn.net/theonegis/article/details/50245459>
<https://blog.csdn.net/theonegis/article/details/50088155>
<https://zhuanlan.zhihu.com/p/81951298>
<https://www.cnblogs.com/msxh/p/9622617.html>
<https://blog.csdn.net/sigmarising/article/details/80470054>

## Ref

<https://en.wikipedia.org/wiki/OpenGL>
<https://www.cnblogs.com/msxh/p/9622617.html>
