quick link: 1.2unit&console example OpenGL with Kylix Form
Kylix is borland's RAD tool on X-Window/Linux, or simply to say delphi for linux.
Delphi is a great development eviroment. With opengl supporting, it is powerful in 3d grachpic area. I have ever make a vcl component named TGLPanel for myself using. VCL is so beautiful and rational that I just spend a night on it although it is my first vcl component. TGLPanel is very tousy, not by a long sight to glscene.
Recently, I get kylix field test4(abbreviate to kylix in following text). It works fine on my linux box(XFree86 3.3.6/Redhat 7 on CII/600,128M memory). I find that there is no opengl unit in package. It discourage me a moment, how can borland desert opengl fans like me!
OK, Chairman mao ever said: do it yourselfery, have ample food and clothing. I examinned delphi-jedi's opengl 1.2 unit, free pascal compiler's opengl package(fpc) and delphi5's opengl unit. Jedi and fpc's opengl unit use function pointer to represent gl/glu/glx APIs, they fill these pointers at lib initialization section by ldopen and ldsym. I agree this method is fixable, but I do not like it. Delphi5's opengl.pas used "...external 'libname.so.verstion' name 'function'" syntax, it make me comfortable.
Because of SGI's license statement in delphi5's opengl.pas, I decide to make my opengl unit base on fpc's .pp.
Kylix online help said that we should declare function in .so like :
function printf(Format:PChar):Integer;cdecl;varargs;external 'stdlib.so' name 'printf';
vi's powerful regular expression is really helpful!
Now, you can download it here.
To test the unit, I write a normal x application ( consol application in kylix ), it works fine. I didn't like qt, gtk is my favor. Unfortrantely, kylix's standard forms are based on qt (in field test4). Maybe, I will write a clx component when I have enough time.
Pay attention:
1. there is none micro like RootWindow(), use XRootWindow() function instead.
2. there is none XSetStandardProperties(), use XSetWMName/XSetWMNormalHints etc.
3. kylix bring with a Xlib.pas, it define XID instead of fpc's TXID
4. type is a keyword in pascal, so that, kylix's Xlib.pas add a x prefix in xxxEvent's field name. fpc use _type instead.
5. bug report send to pinxue@hotmail.com
6. the opengl.pas unit and the sample program provide in AS IS way. Any result is your own risk.
7. you will need install mesa or glx on XFree86 3.3.6. In theory, the unit and sample work with 4.x.
I take a look at qt's source code, and try a little to make the xlib example rendering with clx form, but failed. QT didn't provide a method to create customized window for widget, and CLX can only support to customize a widget for a Control.
Then I try to get some information from gtk+ source code, because there is a gtk glarea support. GTK Widget can override ~realize method to do customize windows. I think the keypoint of rendering with a clx form in Opengl is : create a rendering context with the same visual of widget's window. So that, following code maybe the answer:
glwin:=QWidget_winid(Handle); { maybe need tet TopLevelWidget firstly }
XGetWindowAttributes(dpy,glwin,@winattr);
visual:=winattr.visual;
vitemp.visual:=visual;vitemp.visualid:=XVisualIDFromVisual(vitemp.visual);
vitemp.depth:=visual.depth;
vi:=XGetVisualContext(dpy,vi,nil,GL_TRUE);
glXMakeCurrent(dpy,glwin,cx);
This is just only a guesss yet, when I have time, I will test it. If it works or not in your program, drop me a line please.
the code does not work...
Thanks Matthias Thoma to point out that I should use ViewportHandle instead of Handle.
2001.4.2.
pinxue 2001.3.14.
Well, here is a working example:
OpenGL with Kylix Form
pinxue@hotmail.com
http://pinxue.yeah.net