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

📄 114871.htm

📁 在天极网上发布的各类delphi原码及技巧文档
💻 HTM
📖 第 1 页 / 共 3 页
字号:
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>ExtCtrls,OpenGL;</p><p>type<br>TGLPanel = class(TCustomPanel)<br>private<br>{ Private declarations }<br>DC: HDC;<br>RC: HGLRC;<br>procedure initDC;<br>procedure initGL;<br>procedure PreparePixelFormat(var DC: HDC);</p><p> protected<br>{ Protected declarations }<br>FOnPaint:TNotifyEvent;<br>FOnInit:TNotifyEvent;<br>FOnPreInit:TNotifyEvent;<br>FOnResize:TNotifyEvent;</p><p> procedure Paint;override;<br>procedure Resize;override;<br>procedure WMDestroy(var Msg: TWMDestroy);message WM_DESTROY;<br>procedure WMCreate(var Msg:TWMCreate); message WM_CREATE;</p><p><br>public<br>{ Public declarations }<br>constructor Create(Owner:TComponent);override;</p><p> published<br>{ Published declarations }</p><p> property Alignment;<br>property Align;<br>property DragCursor;<br>property DragMode;<br>property Enabled;<br>property ParentFont;<br>property ParentShowHint;<br>property PopupMenu;<br>property ShowHint;<br>property TabOrder;<br>property TabStop;<br>property Visible;</p><p> property OnClick;<br>property OnDblClick;<br>property OnDragDrop;<br>property OnDragOver;<br>property OnEndDrag;<br>property OnEnter;<br>property OnExit;<br>property OnMouseDown;<br>property OnMouseMove;<br>property OnMouseUp;<br>property OnStartDrag;</p><p> property OnInit:TNotifyEvent read FOnInit write FOnInit;<br>property OnPreInit:TNotifyEvent read FOnPreInit write FOnPreInit;</p><p> property OnResize:TNotifyEvent read FOnResize write FOnResize;<br>property OnPaint:TNotifyEvent read FOnPaint write FOnPaint;</p><p>end;</p><p>procedure Register;</p><p>implementation</p><p>procedure Register;<br>begin<br>RegisterComponents(’Samples’, [TGLPanel]);<br>end;<br>//---------------------------------------------<br>constructor TGLPanel.Create;<br>begin<br>inherited;<br>end;<br>//---------------------------------------------<br>procedure TGLPanel.WMDestroy(var Msg: TWMDestroy);<br>begin<br>wglMakeCurrent(0, 0);<br>wglDeleteContext(RC);<br>ReleaseDC(Handle, DC);<br>end;<br>//---------------------------------------------------<br>procedure TGLPanel.initDC;<br>begin<br>DC := GetDC(Handle);<br>PreparePixelFormat(DC);<br>end;<br>//---------------------------------------------------<br>procedure TGLPanel.initGL;<br>begin<br>glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);<br>glMatrixMode(GL_PROJECTION);<br>glLoadIdentity;<br>glEnable(GL_LIGHTING);<br>glEnable(GL_LIGHT0);<br>glOrtho(-1, 1, -1, 1, -1, 50);<br>glMatrixMode(GL_MODELVIEW);<br>glLoadIdentity;<br>glEnable(GL_DEPTH_TEST);<br>//注意下面这一行是为了做练习程序时可以直接用glColor指定材质而加的,<br>// 可能使得光照或表面材质发生意想不到的变化,<br>// 如果不需要可以去掉或在程序中用glDisable(GL_COLOR_MATERIAL);关闭 <br>glEnable(GL_COLOR_MATERIAL);<br>glShadeModel(GL_SMOOTH);<br>gluLookAt(2, 4, 6, 0, 0, 0, 0, 1, 0);<br>SwapBuffers(DC);<br>end;<br>//---------------------------------------------<br>procedure TGLPanel.PreparePixelFormat(var DC: HDC);<br>var<br>PFD : TPixelFormatDescriptor;<br>ChosenPixelFormat : Integer;<br>begin<br>  FillChar(PFD, SizeOf(TPixelFormatDescriptor), 0);</p><p> with PFD do<br>begin<br>  nSize := SizeOf(TPixelFormatDescriptor);<br>  nVersion := 1;<br>  dwFlags := PFD_DRAW_TO_WINDOW or<br>  PFD_SUPPORT_OPENGL or<br>  PFD_DOUBLEBUFFER;<br>  iPixelType := PFD_TYPE_RGBA;<br>  cColorBits := 16; // 16位颜色<br>  cDepthBits := 32; // 32位深度缓冲<br>  iLayerType := PFD_MAIN_PLANE;<br>{ Should be 24, but we must allow for the clunky WKU boxes }<br>end;</p><p> ChosenPixelFormat := ChoosePixelFormat(DC, @PFD);<br>if ChosenPixelFormat = 0 then<br>  Raise Exception.Create(’ChoosePixelFormat failed!’);<br>  SetPixelFormat(DC, ChosenPixelFormat, @PFD);<br>end;</p><p>procedure TGLPanel.WMCreate(var Msg:TWMCreate);<br>begin<br>//在这里做初始化工作<br>//修改DC的象素格式,使之支持OpenGL绘制<br>initDC;<br>RC := wglCreateContext(DC);<br>

⌨️ 快捷键说明

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