在开发图形程序时,尤其是三维的图形程序,因为感觉opengl没有directx那么庞杂,所以选择了delphiopengl,凭感觉而言,delphi也没有c++那么繁杂而且更加人性化,于是选择delphi+opengl进行工作。在这过程中,碰到(肯定会)一些问题,在此提出希望和朋友们能够进行交流。
首先是初始化。初始化时,有几项工作需要进行:①创建设备描述表(device context)。(注:关于dc,各种资料译文不尽相同如设备环境、设备描述表、设备上下文等,但好象都不太贴切。要是能有李善兰这样的翻译就好了。下文中的rc情形相同)②设置相应的象素格式(pixelformat descriptor)。③创建着色描述表(rendering context)。 delphi中有好几种获得或创建设备描述表的方法。最简单的就是直接获得画布对象(tcanvas)的句柄属性(handle),如:
| dc:hdc; dc:=canvas.handle; |
| dc:=getdc(handle,dc); |
| function setuppixelformat(var dc:hdc):boolean; var ppfd:ppixelformatdescriptor; npixelformat:integer; begin new(ppfd); ppfd^.nsize:=sizeof(pixelformatdescriptor); ppfd^.nversion:=1; ppfd^.dwflags:=pfd_draw_to_window or pfd_support_opengl or pfd_doublebuffer; ppfd^.dwlayermask:=pfd_main_plane; ppfd^.ipixeltype:=pfd_type_colorindex; ppfd^.ccolorbits:=8; ppfd^.cdepthbits:=16; ppfd^.caccumbits:=0; ppfd^.cstencilbits:=0; npixelformat:=choosepixelformat(dc, ppfd); if (npixelformat=0) then begin messagebox(null, ’choosepixelformat failed’, ’error’, mb_ok); result:=false; exit; end; if (setpixelformat(dc, npixelformat, ppfd)= false) then begin messagebox(null, ’setpixelformat failed’, ’error’, mb_ok); result:=false; exit; end; result:=true; dispose(ppfd); end; |
| var pfd: pixelformatdescriptor; npixelformat : integer; begin fillchar(pfd,sizeof(pfd),0); with pfd do begin nsize:=sizeof(pfd); nversion:=1; dwflags:=pfd_support_opengl or pfd_draw_to_bitmap or pfd_doublebuffer; ipixeltype:=pfd_type_rgba; ccolorbits:=32; cdepthbits:=32; ilayertype:=byte(pfd_main_plane); end; npixelformat:=choosepixelformat(dc,@pfd); setpixelformat(dc,npixelformat,@pfd); { // 使用describepixelformat检查象素格式是否设置正确 describepixelformat(dc,npixelformat,sizeof(pfd),@pfd); if (pfd.dwflags and pfd_need_palette) < > 0 then setuppalette(dc,pfd); //setuppalette是自定义函数 }end; |
| rc:hglrc; rc:=wglcreatecontext(dc); wglmakecurrent(dc,rc); |
| wglmakecurrent(0,0); if rc< >null then wgldeletecontext(rc); if ghdc< >null then releasedc(handle,dc); |
| < a href=”061403-05.zip ”>程序代码 zip 3kb |
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器