📄 opengl12.pas
字号:
{******************************************************************************}
{ }
{ Borland Delphi Runtime Library }
{ OpenGL interface unit }
{ }
{ }
{ This is an interface unit for the use of OpenGL from within Delphi and Kylix.}
{ It contains the translations of gl.h, glu.h, glx.h as well as context }
{ and extension management functions. }
{ }
{ The original Pascal code is: OpenGL12.pas }
{ The initial developer of the Pascal code is Mike Lischke }
{ }
{ }
{ Portions created by Microsoft are }
{ Copyright (C) 1995-2001 Microsoft Corporation. }
{ All Rights Reserved. }
{ }
{ Portions created by Silicon Graphics Incorporated are }
{ Copyright (C) 1995-2001 Silicon Graphics Incorporated }
{ All Rights Reserved. }
{ }
{ Portions created by NVidia are }
{ Copyright (C) 1995-2001 NVidia }
{ All Rights Reserved. }
{ }
{ Portions created by Brian Paul }
{ Copyright (C) 1995-2001 Brian Paul }
{ All Rights Reserved. }
{ }
{ }
{ The original file is: gl.h }
{ The original file is: glut.h }
{ The original file is: glx.h }
{ }
{ Portions created by Mike Lischke are }
{ Copyright (C) 2001 Mike Lischke. }
{ }
{ Portions created by John O'Harrow are }
{ Copyright (C) 2001 John O'Harrow. }
{ }
{ Portions created by Eric Grange are }
{ Copyright (C) 2001 Eric Grange. }
{ }
{ Portions created by Olivier Chatelain }
{ Copyright (C) 2001 Olivier Chatelain. }
{ }
{ Portions created by Tom Nuydens }
{ Copyright (C) 2001 Tom Nuydens. }
{ }
{ Portions created by Matthias Thoma are }
{ Copyright (C) 2001 Matthias Thoma. }
{ }
{ Portions created by Sven Bobrowski are }
{ Copyright (C) 2001 Sven Bobrowski }
{ }
{ Portions creates by Michael Kuntzman for }
{ "The Keepers" Game Project [http://thekeepers.sourceforge.net/] are }
{ Copyright (C) 2003 to: }
{ - Michael Kuntzman [technobot@users.sourceforge.net] }
{ - Romi Kuntsman [romik@users.sourceforge.net] }
{ }
{ }
{ Obtained through: }
{ }
{ Joint Endeavour of Delphi Innovators (Project JEDI) }
{ }
{ You may retrieve the latest version of this file at the Project }
{ JEDI home page, located at http://delphi-jedi.org }
{ }
{ The contents of this file are used with permission, subject to }
{ the Mozilla Public License Version 1.1 (the "License"); you may }
{ not use this file except in compliance with the License. You may }
{ obtain a copy of the License at }
{ http://www.mozilla.org/MPL/MPL-1.1.html }
{ }
{ Software distributed under the License is distributed on an }
{ "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or }
{ implied. See the License for the specific language governing }
{ rights and limitations under the License. }
{ }
{******************************************************************************}
unit OpenGL12;
//----------------------------------------------------------------------------------------------------------------------
//
// This is an interface unit for the use of OpenGL from within Delphi and contains
// the translations of gl.h, glu.h and glx.h as well as some support functions.
// OpenGL12.pas contains bug fixes and enhancements of Delphi's and other translations
// as well as support for extensions.
//
// NOTE: In order to fully support multi thread rendering it is necessary to hold all
// extension address in threadvars. For single threaded applications this would be an
// unnecessary time penalty, however. Hence there is a compiler switch to
// allow single threaded OpenGL application to use vars while multi threaded applications
// will use threadvars. By default the switch MULTITHREADOPENGL (see compiler switch under der interface keyword)
// is not active and must explicitly enabled to take effect.
//
//----------------------------------------------------------------------------------------------------------------------
//
// function InitOpenGL: Boolean;
// Needed to load the OpenGL DLLs and all addresses of the standard functions.
// In case OpenGL is already initialized this function does nothing. No error
// is raised, if something goes wrong, but you need to inspect the result in order
// to know if all went okay.
// Result: True if successful or already loaded, False otherwise.
//
// function InitOpenGLFromLibrary(GL_Name, GLU_Name: String): Boolean;
// Same as InitOpenGL, but you can specify specific DLLs. Useful if you want to
// use different DLLs than the default ones. This function closes previously
// loaded DLLs before it tries to open the new libraries.
// Result: True if successful, False otherwise.
//
// procedure CloseOpenGL;
// Unloads the OpenGL DLLs and sets all function addresses to nil, including
// extensions. You can load and unload the DLLs as often as you like.
//
// procedure ClearExtensions;
// Sets all extension routines to nil. This is needed when you change the Pixelformat
// of your OpenGL window, since the availability of these routines changes from
// PixelFormat to Pixelformat (and also between various vendors).
//
// function CreateRenderingContext(DC: HDC; Options: TRCOptions; ColorBits, StencilBits, AccumBits, AuxBuffers: Integer;
// Layer: Integer; var Palette: HPALETTE): HGLRC;
// Sets up a pixel format and creates a new rendering context depending of the
// given parameters:
// DC - the device context for which the rc is to be created
// Options - options for the context, which the application would like to have
// (it is not guaranteed they will be available)
// ColorBits - the color depth of the device context (Note: Because of the internal DC handling of the VCL you
// should avoid using GetDeviceCaps for memory DCs which are members of a TBitmap class.
// Translate the Pixelformat member instead!)
// StencilBits - requested size of the stencil buffer
// AccumBits - requested size of the accumulation buffer
// AuxBuffers - requested number of auxiliary buffers
// Layer - ID for the layer for which the RC will be created (-1..-15 for underlay planes, 0 for main plane,
// 1..15 for overlay planes)
// Note: The layer handling is not yet complete as there is very few information
// available and (until now) no OpenGL implementation with layer support on the low budget market.
// Hence use 0 (for the main plane) as layer ID.
// Palette - Palette Handle created within function (need to use DeleteObject(Palette) to free this if <> 0)
// Result: the newly created context or 0 if setup failed
//
// procedure ActivateRenderingContext(DC: HDC; RC: HGLRC);
// Makes RC in DC 'current' (wglMakeCurrent(..)) and loads all extension addresses
// and flags if necessary.
//
// procedure DeactivateRenderingContext;
// Counterpart to ActivateRenderingContext.
//
// procedure DestroyRenderingContext(RC: HGLRC);
// RC will be destroyed and must be recreated if you want to use it again.
//
// procedure ReadExtensions;
// Determines which extensions for the current rendering context are available and
// loads their addresses. This procedure is called from ActivateRenderingContext
// if a new pixel format is used, but you can safely call it from where you want
// to actualize those values (under the condition that a rendering context MUST be
// active).
//
// procedure ReadImplementationProperties;
// Determines other properties of the OpenGL DLL (version, availability of extensions).
// Again, a valid rendering context must be active.
//
// function HasActiveContext: Boolean;
// Determines whether the calling thread has currently an active rendering context.
//
//
// SDL support by Michael Kuntzman:
// ================================
//
// Use the "DEFINE USE_SDL" directive to enable SDL support. This will also disable most of the non SDL-related
// routines. The following routiness were introduced:
//
// function SDL_LoadGLFunctions(const LoadGLU: Boolean = True): Boolean;
// Loads all OpenGL functions upto OpenGL version 1.2, including extensions.
// If LoadGLU is set to True, also calls SDL_LoadGLUFunctions. Returns True on
// success, False on failure. The function must be called AFTER the
// OpenGL32.dll or other OpenGL library has been loaded with
// SDL_GL_LoadLibrary, and a video mode has been set with SDL_SetVideoMode.
// Note that the loaded functions and library will be unloaded by SDL during
// SDL_Close.
//
// function SDL_LoadGLUFunctions: Boolean;
// Loads all GLU functions, including extensions. Returns True on success,
// False on failure. The function doesn't actually use any SDL routines, and
// hance may be safely called at any time. The functions and library should be
// unloaded with SDL_UnloadGLUFunctions when they are no longer needed.
//
// procedure SDL_UnloadGLUFunctions;
// Unloads the functions and library that were previously loaded by
// SDL_LoadGLUFunctions.
//
// function SDL_IsGLLoaded: Boolean;
// Returns True if the OpenGL functions have been successfully loaded by
// SDL_LoadGLFunctions.
//
// function SDL_IsGLULoaded: Boolean;
// Returns True if the GLU functions have been successfully loaded by
// SDL_LoadGLUFunctions.
//
// function SDL_IsGLAndGLULoaded: Boolean;
// Returns True if the both OpenGL and GLU functions have been successfully
// loaded by SDL_LoadGLFunctions and SDL_LoadGLUFunctions.
//
//----------------------------------------------------------------------------------------------------------------------
//
// This translation is based on different sources:
//
// - first translation from Artemis Alliance Inc.
// - previous versions from Mike Lischke
// - Alexander Staubo
// - Borland OpenGL.pas (from Delphi 3)
// - Microsoft and SGI OpenGL header files
// - www.opengl.org, www.sgi.com/OpenGL
// - nVidia extension reference as of December 1999
// - nVidia extension reference as of January 2001
// - vertex_array_range sample by Tom Nuydens at Delphi3D
// - minor bug fixes and greatly extended by John O'Harrow (john@elmcrest.demon.co.uk)
// - initial context activation balancing by Eric Grange (egrange@infonie.fr)
// - additional nVidia extensions by Olivier Chatelain (Olivier.Chatelain@xitact.com)
// - SDL support by Michael Kuntzman (technobot@users.sourceforge.net)
//
// Contact: public@lischke-online.de, www.lischke-online.de
//
// Version: 1.2.16
//----------------------------------------------------------------------------------------------------------------------
//
// September 2004
// - Fix for the fix: The definition of GLboolean was correct, that of GL_TRUE and GL_FALSE was not.
// May 2004
// - The type of GLboolean (BYTEBOOL) is wrong and causes compiler errors. It is now Byte as in the original C header.
// June 2003
// - Delphi 7 conditional symbols to disable .NET warnings.
// 19-Apr-2003 mk:
// - Added some routines to load the OpenGL functions through SDL. SDL support
// enabled/disabled through the USE_SDL define.
//
// 12-Feb-2002 dml :
// - Further modifications to allow unit to compile under Free Pascal
// as suggested by "QuePasha Pepe" <mrkroket@hotmail.com>
//
// 25-OCT-2001 dre :
// - Made modifications to allow unit to compile under Free Pascal
// - added tMaxLogPalette declaration to Free Pascal
// - included fix to ReadExtensions
// - Added Set8088CW procedure
//
// 13-SEP-2001 ml:
// - added PWGLSwap etc. declarations for Delphi 3
// 18-AUG-2001 ml:
// - multi thread support for function addresses (extensions)
// 28-JUL-2001 ml:
// - included original type names (+ $EXTERNALSYM directives)
// 10-JUL-2001 ml:
// - TGLubyte changed to UCHAR
// 05-JUL-2001 ml:
// - own exception type for OpenGL
// - TGLboolean is now of type BYTEBOOL
// 05-MAY-2001 ml:
// - correct tracking of RC creation and release as well as multithreaded RC activation
// - compatibility routines for users of other OpenGL unit variants
// - improved rendering context creation
// - bug fixes
// 01-MAY-2001 ml:
// - added more nVidia extensions
//----------------------------------------------------------------------------------------------------------------------
interface
{$Include Compilers.inc}
{.$define MULTITHREADOPENGL}
{.$define USE_SDL}
{$ifdef COMPILER_7_UP}
// For some things to work we need code, which is classified as being unsafe for .NET.
// We switch off warnings about that fact. We know it and we accept it.
{$warn UNSAFE_TYPE off}
{$warn UNSAFE_CAST off}
{$warn UNSAFE_CODE off}
{$endif COMPILER_7_UP}
{$ifdef FPC}
{$MODE DELPHI}
{$MACRO ON}
{$DEFINE VER100}
{$endif}
uses
{$ifdef USE_SDL}
SDL,
{$endif}
{$ifdef MSWINDOWS}
Windows
{$endif MSWINDOWS}
{$ifdef LINUX}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -