⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 opengl.pas

📁 Delphi7编程80例(完全版)
💻 PAS
📖 第 1 页 / 共 5 页
字号:
unit OpenGL;

//------------------------------------------------------------------------------
//
//  Extended translation of the OpenGL header files (version 1.1) for Delphi 2.0+
//
//------------------------------------------------------------------------------
//
//  This is a maintained interface unit for the use of OpenGL with Delphi and contains
//  the translations for gl.h, glu.h and support functions prepared for the use
//  of the SGI & Microsoft OpenGL DLLs. This unit contains bug fixes and enhancements
//  of Borland's and other translations as well as support for extensions.
//
//------------------------------------------------------------------------------
//
//  Usage: Simply take this unit in the uses clause of your project files, which
//         need to call OpenGL. In addition, you could compile this unit and replace
//         the original .dcu file (D3 only) in the lib folder of your Delphi installation.
//         If you want to make a backup before, do so, but you won't need that. This
//         unit has been tested with all Delphi versions from 2.0 upward and works
//         very well.
//         Since the DLLs OpenGL(32) and GLU(32) are linked dynamically with this unit
//         you have to initialize it by calling InitOpenGL or InitOpenGLFromLibrary from
//         anywhere in your project. The release of the DLLs happens automatically.
//         This kind of linkage provides a better means to control what's in memory
//         and prevents program crashes when the needed DLLs aren't available.
//         NOTE: If you're going to use the SGI OpenGL DLLs you must ensure a specific
//               order of Windows.pas and OpenGL.pas. This is a known problem with
//               these DLLs and not a bug in this unit. The function which is concerned
//               is SetPixelFormat. So always place Windows.pas in the uses clause
//               of those units, which also use OpenGL (even if you don't need
//               Windows.pas) and place it BEFORE OpenGL.pas! Since there are more
//               conflicts between Windows.pas and other units (e.g. Windows.TBitmap
//               and Graphics.TBitmap), you should always place Windows.pas at the
//               very first place in your uses clauses.
//
//         For your convenience I put some support routines in this unit, which are
//         NOT part of the standard header files (gl.h and glu.h). For my convenience
//         I've put the description of the other funtions also in the following list:
//
// function InitOpenGL: Boolean;
//   Needed to load the OpenGL DLLs and all addresses of the standard functions.
//   It first tries to load the SGI DLLs, since most of you won't have HW acceleration
//   and these DLLs are faster without HW accel. than the MS DLLs. If loading of
//   the SGI DLLs failed for some reason, the MS versions are used. If HW accel. is
//   available then the SGI DLL automatically link to the MS DLLs, which are able
//   to use this feature.
//   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 whether 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. Great if you want to
//   use totally different DLLs. This function closes eventually loaded DLLs
//   before it tries to open the newly given.
//   RESULT: True if successful, false otherwise
//
// procedure CloseOpenGL;
//   Unloads the OpenGL DLLs and sets all routine 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 from SGI to MS DLLs).
//
// function CreateRenderingContext(DC: HDC; Options: TRCOptions; ColorDepth: Integer; StencilBits: Byte): 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     - special options for the context, they correspond to the flags
//                   of the PIXELFORMATDESCRIPTOR
//     StencilBits - determines the size of the stencil buffer
//   You can specify 0 for color and depth bits. The function will then automatically
//   use the screen depth for both.
//   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. No
//   additional functionality to wglDeleteContext yet.
//
// 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 global properties of the OpenGL DLL (currently the versions only)
//   and needs to be used only once. It is called from CreateRenderingContext, when
//   it is the very first call to this function (after loading the DLLs).
//
//------------------------------------------------------------------------------
//
// This translation is based on different sources:
//
// - first translation from Artemis Alliance Inc.
// - previous versions from Mike Lischke
// - Alexander Staubo
// - Borland OpenGL.pas (from Delphi3)
// - Microsoft and SGI OpenGL header files
// - www.opengl.org, www.sgi.com/OpenGL
//
//  Contact:  Lischke@hotmail.com
//
//  last change : 09. July 1998
//
//  Download: Delphi Graphics Homepage <http://www.bigfoot.com/~ungerik/>
//------------------------------------------------------------------------------


{ ------ Original copyright notice by SGI -----

 Copyright 1996 Silicon Graphics, Inc.
 All Rights Reserved.

 This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
 the contents of this file may not be disclosed to third parties, copied or
 duplicated in any form, in whole or in part, without the prior written
 permission of Silicon Graphics, Inc.

 RESTRICTED RIGHTS LEGEND:
 Use, duplication or disclosure by the Government is subject to restrictions
 as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
 and Computer Software clause at DFARS 252.227-7013, and/or in similar or
 successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
 rights reserved under the Copyright Laws of the United States.}


interface

uses Windows, Geometry;

type TRCOptions = set of (opDoubleBuffered,opGDI,opStereo);

     GLenum      = UINT;      PGLenum     = ^GLenum;
     GLboolean   = UCHAR;     PGLboolean  = ^GLboolean;
     GLbitfield  = UINT;      PGLbitfield = ^GLbitfield;
     GLbyte      = ShortInt;  PGLbyte     = ^GLbyte;
     GLshort     = SHORT;     PGLshort    = ^GLshort;
     GLint       = Integer;   PGLint      = ^GLint;
     GLsizei     = Integer;   PGLsizei    = ^GLsizei;
     GLubyte     = UCHAR;     PGLubyte    = ^GLubyte;
     GLushort    = Word;      PGLushort   = ^GLushort;
     GLuint      = UINT;      PGLuint     = ^GLuint;
     GLfloat     = Single;    PGLfloat    = ^GLfloat;
     GLclampf    = Single;    PGLclampf   = ^GLclampf;
     GLdouble    = Double;    PGLdouble   = ^GLdouble;
     GLclampd    = Double;    PGLclampd   = ^GLclampd;

//------------------------------------------------------------------------------

var GL_VERSION_1_0,
    GL_VERSION_1_1,
    GL_VERSION_1_2,
    GLU_VERSION_1_1,
    GLU_VERSION_1_2 : Boolean;

    // Extensions (gl)
    GL_EXT_abgr,
    GL_EXT_bgra,
    GL_EXT_packed_pixels,
    GL_EXT_paletted_texture,
    GL_EXT_vertex_array,
    GL_SGI_compiled_vertex_array,
    GL_SGI_cull_vertex,
    GL_SGI_index_array_formats,
    GL_SGI_index_func,
    GL_SGI_index_material,
    GL_SGI_index_texture,
    GL_WIN_swap_hint,
    GL_EXT_blend_color,
    GL_EXT_blend_logic_op,
    GL_EXT_blend_minmax,
    GL_EXT_blend_subtract,
    GL_EXT_convolution,
    GL_EXT_copy_texture,
    GL_EXT_histogram,
    GL_EXT_polygon_offset,
    GL_EXT_subtexture,
    GL_EXT_texture,
    GL_EXT_texture_object,
    GL_EXT_texture3D,
    GL_EXT_cmyka,
    GL_EXT_rescale_normal,
    GL_SGI_color_matrix,
    GL_SGI_texture_color_table,
    GL_SGI_color_table,
    GL_EXT_clip_volume_hint,
    GL_EXT_misc_attribute,
    GL_EXT_scene_marker,
    GL_EXT_shared_texture_palette,

    // Extensions (glu)
    GLU_EXT_TEXTURE,
    GLU_EXT_object_space_tess,
    GLU_EXT_nurbs_tessellator     : Boolean;

//------------------------------------------------------------------------------

const // ********** GL generic constants **********

      // AttribMask
      GL_CURRENT_BIT                     = $00000001;
      GL_POINT_BIT                       = $00000002;
      GL_LINE_BIT                        = $00000004;
      GL_POLYGON_BIT                     = $00000008;
      GL_POLYGON_STIPPLE_BIT             = $00000010;
      GL_PIXEL_MODE_BIT                  = $00000020;
      GL_LIGHTING_BIT                    = $00000040;
      GL_FOG_BIT                         = $00000080;
      GL_DEPTH_BUFFER_BIT                = $00000100;
      GL_ACCUM_BUFFER_BIT                = $00000200;
      GL_STENCIL_BUFFER_BIT              = $00000400;
      GL_VIEWPORT_BIT                    = $00000800;
      GL_TRANSFORM_BIT                   = $00001000;
      GL_ENABLE_BIT                      = $00002000;
      GL_COLOR_BUFFER_BIT                = $00004000;
      GL_HINT_BIT                        = $00008000;
      GL_EVAL_BIT                        = $00010000;
      GL_LIST_BIT                        = $00020000;
      GL_TEXTURE_BIT                     = $00040000;
      GL_SCISSOR_BIT                     = $00080000;
      GL_ALL_ATTRIB_BITS                 = $000FFFFF;

      // ClientAttribMask
      GL_CLIENT_PIXEL_STORE_BIT          = $00000001;
      GL_CLIENT_VERTEX_ARRAY_BIT         = $00000002;
      GL_CLIENT_ALL_ATTRIB_BITS          = $FFFFFFFF;

      // Boolean
      GL_FALSE                           = 0;
      GL_TRUE                            = 1;

      // BeginMode
      GL_POINTS                          = $0000;
      GL_LINES                           = $0001;
      GL_LINE_LOOP                       = $0002;
      GL_LINE_STRIP                      = $0003;
      GL_TRIANGLES                       = $0004;
      GL_TRIANGLE_STRIP                  = $0005;
      GL_TRIANGLE_FAN                    = $0006;
      GL_QUADS                           = $0007;
      GL_QUAD_STRIP                      = $0008;
      GL_POLYGON                         = $0009;

      // AccumOp
      GL_ACCUM                           = $0100;
      GL_LOAD                            = $0101;
      GL_RETURN                          = $0102;
      GL_MULT                            = $0103;
      GL_ADD                             = $0104;

      // AlphaFunction
      GL_NEVER                           = $0200;
      GL_LESS                            = $0201;
      GL_EQUAL                           = $0202;
      GL_LEQUAL                          = $0203;
      GL_GREATER                         = $0204;
      GL_NOTEQUAL                        = $0205;
      GL_GEQUAL                          = $0206;
      GL_ALWAYS                          = $0207;

      // BlendingFactorDest
      GL_ZERO                            = 0;
      GL_ONE                             = 1;
      GL_SRC_COLOR                       = $0300;
      GL_ONE_MINUS_SRC_COLOR             = $0301;
      GL_SRC_ALPHA                       = $0302;
      GL_ONE_MINUS_SRC_ALPHA             = $0303;
      GL_DST_ALPHA                       = $0304;
      GL_ONE_MINUS_DST_ALPHA             = $0305;

      // BlendingFactorSrc
      GL_DST_COLOR                       = $0306;
      GL_ONE_MINUS_DST_COLOR             = $0307;
      GL_SRC_ALPHA_SATURATE              = $0308;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -