Sign in Join
Wiki copytemporary

OpenGL/zh CN: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11OpenGL (**Open** **G**raphics **L**ibrary) 是一个跨平台的3D图像API.市面上流行的显卡都支持OpenGL硬件加速, 它是解决高级图形软件开发的一个好的方案。
22
33## Free Pascal的OpenGL单元
44
55FreePascal OpenGL 接口由下列单元构成:
66
77- **gl**: 单元的主要功能包括绘置多边形, applying transformations, setting colors and materials,... Procedures always start with the preposition "gl".
88- **glu**: This unit contains OpenGL utils. Although it has some useful functions, this unit is not necessary as you can implement all glu Procedures with the functionality of the gl unit. Procedures always start with the preposition "glu".
99- **glext**: Vendors can provide additional functionality through extensions. Use this unit to use these extensions.
1010 The functionality specific to higher OpenGL versions (1.2 and later) is available in this unit as well. Initializing this functionality is similar to initializing normal OpenGL extensions: just call Load_GL_version_X_Y function. If your OpenGL library version is older than X.Y, Load_GL_version_X_Y will return false.
1111- **glut**: 该单元提供建立OpenGL窗口的功能。 尽管这是一个跨平台的单元, 基本上所有Windows操作系统都没有默认的glut dll.
1212- **glx**: glx provides functionality to set up an OpenGL window in an x window system. Procedures always start with the preposition "glx". Obviously, you cannot use this unit on non-x window systems such as Windows.
1313
1414## Lazarus 内的 OpenGL 单元
1515
1616Lazarus 包含 TOpenGLControl - LCL 控件 提供 OpenGL 环境. 可以找到这个包 lazarus/components/opengl/lazopenglcontext.lpk. 还有一个例子: lazarus/examples/openglcontrol/openglcontrol_demo.lpi.  (注:我在ubuntu 9.04 64bit里没有编译成功,郁闷。提示lGL没有发现,我在/usr/lib/发现libgl-2.0.so)
1717
1818## 第三方 OpenGL 单元
1919
2020- [[GLScene]] is a Lazarus package with lots of extra features for OpenGL applications.
2121- [[Castle Game Engine]] allows you to navigate and render 3D worlds (in VRML, X3D and other 3D formats).
2222
2323(注:不知道SDL算不算!)
2424
2525## 教程
2626
2727[[OpenGL Tutorial]] OpenGL 教程
2828
2929## Q/A using OpenGL binding
3030
3131**Q: I don't understand why the ARB version does not work.** **AFAIK it has the same entry points as the core functionality and** **OpenGL versions are required to support the ARB version of functions** **even if the non ARB version is in the core now.**
3232
3333A: No. OpenGL doesn't have to support the extension entry points, even when it supports the same functionality in core already. Vendor is free to remove the extensions, and support only the "core" functions.
3434
3535Also, sometimes when functionality is promoted from ARB extension into core it's slightly changed (although in 99% cases it stays the same). Example is the GLSL shaders, that expose (very slightly) different API through ARB extensions and through core 2.0 specification.
3636
3737Basically, what is exposed through extensions is completely orthogonal to what is exposed through core functionality, so they should be initialized separately. In particular cases, you can make tricks like
3838
3939``` pascal
4040if glIsBufferARB = nil then glIsBufferARB := @glIsBuffer;
4141```
4242
4343but this should be left to the final programmer that knows that "ARB_vertex_buffer_object" behavior is identical to how it works in core.
4444
4545**Q: When I try to use the gluTessCallback function from the glu** **unit, either the compiler complains or I get a segmentation fault** **when I try to run my program. How can I get it to work properly?**
4646
4747A: The gluTessCallback function is defined in the following way in the **glu** unit:
4848
4949``` pascal
5050{$IFDEF Windows}
5151 {$DEFINE extdecl := stdcall}
5252{$ELSE}
5353 {$DEFINE extdecl := cdecl}
5454{$ENDIF}
5555
5656gluTessCallback: procedure(tess: PGLUtesselator; which: GLenum; fn: TCallBack); extdecl;
5757```
5858
59-<b>Windows note:</b>A common problem is that the calling convention of the glu functions seems to vary in several different GLUT DLLs builds for windows. In some it is stdcall, in some cdecl. The most used one seems to be stdcall.
59+Windows note:A common problem is that the calling convention of the glu functions seems to vary in several different GLUT DLLs builds for windows. In some it is stdcall, in some cdecl. The most used one seems to be stdcall.
6060
6161You should define your callback functions like so:
6262
6363``` pascal
6464procedure MyTessBegin(which: GLEnum);
6565{$IFDEF Windows} stdcall; {$else} cdecl; {$endif}
6666begin
6767 glBegin(which);
6868end;
6969
7070procedure MyTessEnd;
7171{$IFDEF Windows} stdcall; {$else} cdecl; {$endif}
7272begin
7373 glEnd(); // The () is required
7474end;
7575
7676procedure MyTessVertex(data: Pointer);
7777{$IFDEF Windows} stdcall; {$else} cdecl; {$endif}
7878begin
7979 glVertex3dv(PGLDouble(data));
8080end;
8181```
8282
8383Note the cdecl/stdcall modifiers; they are required. You then call gluTessCallback in the following manner:
8484
8585``` pascal
8686gluTessCallback(tess, GLU_TESS_BEGIN, TCallBack(@MyTessBegin));
8787gluTessCallback(tess, GLU_TESS_END, TCallBack(@MyTessEnd));
8888gluTessCallback(tess, GLU_TESS_VERTEX, TCallBack(@MyTessVertex));
8989```
9090
9191Make sure you cast the pointer to your callback function to the TCallBack type, as shown above.
9292
9393Alternatively, if you want to refer to the OpenGL functions directly, use the following calling convention:
9494
9595``` pascal
9696gluTessCallback(tess, GLU_TESS_BEGIN, TCallBack(glBegin));
9797gluTessCallback(tess, GLU_TESS_END, TCallBack(glEnd));
9898gluTessCallback(tess, GLU_TESS_VERTEX, TCallBack(glVertex3dv));
9999```
100100
101101Finally, [here](http://www.ludicity.org/files/tess_demo.pp) is source code for a simple tessellation demo (uses glut).
102102
103103Go to back [[Package List|Packages List]]
104104
105105---
106106*From the Free Pascal wiki, page "OpenGL/zh CN", as it stood on 2020-02-23 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history