openGLAPI之glPolygonOffset

openGL系列文章目录

前言

openGLAPI之glPolygonOffset函数详解

一、glPolygonOffset官方文档

glPolygonOffset官方文档说明

Name
glPolygonOffset — set the scale and units used to calculate depth values

C Specification
void glPolygonOffset( GLfloat factor,
GLfloat units);

Parameters
factor
Specifies a scale factor that is used to create a variable depth offset for each polygon. The initial value is 0.

units
Is multiplied by an implementation-specific value to create a constant depth offset. The initial value is 0.

Description
When GL_POLYGON_OFFSET_FILL, GL_POLYGON_OFFSET_LINE, or GL_POLYGON_OFFSET_POINT is enabled, each fragment’s depth value will be offset after it is interpolated from the depth values of the appropriate vertices. The value of the offset is factor×DZ+r×units, where DZ is a measurement of the change in depth relative to the screen area of the polygon, and r is the smallest value that is guaranteed to produce a resolvable offset for a given implementation. The offset is added before the depth test is performed and before the value is written into the depth buffer.

glPolygonOffset is useful for rendering hidden-line images, for applying decals to surfaces, and for rendering solids with highlighted edges.

Associated Gets
glIsEnabled with argument GL_POLYGON_OFFSET_FILL, GL_POLYGON_OFFSET_LINE, or GL_POLYGON_OFFSET_POINT.

glGet with argument GL_POLYGON_OFFSET_FACTOR or GL_POLYGON_OFFSET_UNITS.

Version Support
OpenGL Version
Function / Feature Name 2.0 2.1 3.0 3.1 3.2 3.3 4.0 4.1 4.2 4.3 4.4 4.5
glPolygonOffset ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔ ✔
See Also
glDepthFunc, glEnable, glGet, glIsEnabled

Copyright
Copyright © 1991-2006 Silicon Graphics, Inc. Copyright © 2010-2014 Khronos Group. This document is licensed under the SGI Free Software B License. For details, see https://khronos.org/registry/OpenGL-Refpages/LICENSES/LicenseRef-FreeB.txt.

二、翻译

glPolygonOffset 函式
發行項
2021/09/15
2 位參與者

GlPolygonOffset 函式會設定 OpenGL 用來計算深度值的小數位數和單位數。

語法
C++

複製
void glPolygonOffset(
GLfloat factor,
GLfloat units
);
參數
因素

指定用來為每個多邊形建立可變深度位移的比例因數。 初始值為零。

單位

指定乘以實值指定值的值,以建立常數深度位移。 初始值為0。

傳回值
此函式不會傳回值。

錯誤碼
GlGetError函式可以取出下列錯誤碼。

錯誤碼
Name 意義
GL _ 不正確 _ 操作
呼叫 glBegin 和對應的 glEnd呼叫之間呼叫了函數。
備註
當 _ 啟用 GL 多邊形 _ 位移時,每個片段的深度值將會在從適當頂點的深度值中插補之後位移。 位移的值是 係數 * ? z + r * 單位,其中? z 是相對於多邊形螢幕區域的變更深度度量,而 r 是保證為指定的執行產生可解析位移的最小值。 在執行深度測試之前,以及將值寫入深度緩衝區之前,會加入位移。

GlPolygonOffset 函式適用于轉譯隱藏行影像、將 decals 套用至表面,以及用來呈現具有反白顯示邊緣的純色。

GlPolygonOffset 函式對在意見緩衝區中放置的深度座標沒有任何作用。 它也不會影響選取專案。

下列函式會取出與 glPolygonOffset 相關的資訊:

具有引數 GL _ 多邊形 _ 位移 _ 因數的 glGet
具有引數 GL _ 多邊形 _ 位移 _ 單位的 glGet
具有引數 GL _ 多邊形 _ 位移 _ 填滿的 glIsEnabled
具有引數 GL _ 多邊形 _ 位移 _ 線的 glIsEnabled
具有引數 GL _ 多邊形 _ 位移 _ 點的 glIsEnabled
注意

GlPolygonOffset 函式僅適用于 OpenGl 1.1 版或更高版本。

規格需求
規格需求
需求 值
最低支援的用戶端
Windows 2000 Professional [僅限傳統型應用程式]
最低支援的伺服器
Windows 2000 Server [僅限傳統型應用程式]
標頭
Gl
程式庫
Opengl32 .lib
DLL
Opengl32.dll
另請參閱
glDepthFunc

glDisable

glEnable

glGet

glIsEnabled

glLineWidth

glStencilOp

glTexEnv

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
桥接模式和抽象工厂是两个不同的设计模式,但是可以结合使用。下面我来简单介绍一下如何在C++中实现桥接模式和抽象工厂。 首先,我们需要定义桥接模式中的抽象类和实现类。假设我们要实现一个图形库,可以绘制不同类型的图形,包括圆形、矩形和三角形。我们可以定义一个抽象类Shape,表示图形的基本属性和方法: ```cpp class Shape { public: virtual void draw() = 0; virtual ~Shape() {} }; ``` 然后,我们定义三个实现类,分别表示圆形、矩形和三角形: ```cpp class Circle : public Shape { public: void draw() override { cout << "Draw Circle." << endl; } }; class Rectangle : public Shape { public: void draw() override { cout << "Draw Rectangle." << endl; } }; class Triangle : public Shape { public: void draw() override { cout << "Draw Triangle." << endl; } }; ``` 接下来,我们需要实现桥接模式中的桥接类,它将抽象类和实现类进行桥接。假设我们要支持不同的绘制方式,包括OpenGL和DirectX。我们可以定义一个抽象类DrawAPI,表示绘制的基本属性和方法: ```cpp class DrawAPI { public: virtual void draw() = 0; virtual ~DrawAPI() {} }; ``` 然后,我们定义两个实现类,分别表示OpenGL和DirectX的绘制方式: ```cpp class OpenGLAPI : public DrawAPI { public: void draw() override { cout << "Draw using OpenGL." << endl; } }; class DirectXAPI : public DrawAPI { public: void draw() override { cout << "Draw using DirectX." << endl; } }; ``` 最后,我们需要使用抽象工厂来创建图形和绘制方式的组合。我们可以定义一个抽象工厂类AbstractFactory,表示图形和绘制方式的组合: ```cpp class AbstractFactory { public: virtual Shape* createShape() = 0; virtual DrawAPI* createDrawAPI() = 0; virtual ~AbstractFactory() {} }; ``` 然后,我们定义两个具体的工厂类,分别表示OpenGL和DirectX的图形和绘制方式的组合: ```cpp class OpenGLFactory : public AbstractFactory { public: Shape* createShape() override { return new Circle(); } DrawAPI* createDrawAPI() override { return new OpenGLAPI(); } }; class DirectXFactory : public AbstractFactory { public: Shape* createShape() override { return new Rectangle(); } DrawAPI* createDrawAPI() override { return new DirectXAPI(); } }; ``` 最后,我们可以使用这些类来绘制图形。例如,我们可以使用OpenGL和圆形来绘制一个图形: ```cpp AbstractFactory* factory = new OpenGLFactory(); Shape* shape = factory->createShape(); DrawAPI* api = factory->createDrawAPI(); api->draw(); shape->draw(); ``` 输出结果为: ``` Draw using OpenGL. Draw Circle. ``` 这就是桥接模式和抽象工厂在C++中的实现。通过使用桥接模式和抽象工厂,我们可以将抽象类和实现类进行解耦,从而实现更加灵活和可扩展的设计。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值