Get full path of argv[0] before we change directories.
[wine.git] / documentation / opengl
blob49df0b80470cf2c0fbef4b2d8168f0d887b31bda
1 I What is needed to have OpenGL support in Wine
2 ===============================================
4 Basically, if you have a Linux OpenGL ABI compliant libGL
5 (http://oss.sgi.com/projects/ogl-sample/ABI/) installed on your
6 computer, you should everything that is needed.
8 To be more clear, I will detail one step after another what the
9 configure script checks.
11 If, after Wine compiles, OpenGL support is not compiled in, you can
12 always check 'config.log' to see which of the following points failed.
14 I.1 Header files
15 ----------------
17 The needed header files to build OpenGL support in Wine are :
19  - gl.h : the definition of all OpenGL core functions, types and
20    enumerants
22  - glx.h : how OpenGL integrates in the X Window environment
24  - glext.h : the list of all registered OpenGL extensions
26 The latter file (glext.h) is, as of now, not necessary to build
27 Wine. But as this file can be easily obtained from SGI
28 (http://oss.sgi.com/projects/ogl-sample/ABI/glext.h), and that all
29 OpenGL should provide one, I decided to keep it here.
32 I.2 OpenGL library thread-safety
33 --------------------------------
35 After that, the script checks if the OpenGL library relies or not on
36 the pthread library to provide thread safety (most 'modern' OpenGL
37 libraries do).
39 If the OpenGL library explicitely links in libpthread (you can check
40 it with a 'ldd libGL.so'), you need to force OpenGL support by
41 starting configure with the '--enable-opengl' flag.
43 The reason to this is that Wine contains some hacks done by Ove to
44 cohabit with pthread that are known to work well in most of the cases
45 (glibc 2.1.x). On the other hand, we never got Wine to work with glibc
46 2.0.6. Thus, I deemed preferable to play it safe : by default, I
47 suppose that the hack won't work and that it's the user's
48 responsability to enable it.
50 Anyway, it should be pretty safe to build with '--enable-opengl'.
53 I.3 OpenGL library itself
54 -------------------------
56 To check for the presence of 'libGL' on the system, the script checks
57 if it defines the 'glXCreateContext' function. There should be no
58 problem here.
61 I.4 glXGetProcAddressARB function
62 ---------------------------------
64 The core of Wine's OpenGL implementation (at least for all extensions)
65 is the glXGetProcAddressARB function. Your OpenGL library needs to
66 have this function defined for Wine to be able to support OpenGL.
68 If your library does not provide it, you are out of luck.
70 (Note: this is not completely true as one could rewrite a
71        glXGetProcAddressARB replacement using 'dlopen' and friends,
72        but well, telling people to upgrade is easier :-) ).
76 II How to configure
77 ===================
79 Configuration is quite easy : once OpenGL support has been built in
80 Wine, this internal OpenGL driver will be used each time an
81 application tries to load 'opengl32.dll'.
83 Due to restrictions (that do not exist in Windows) on OpenGL contexts,
84 if you want to prevent the screen to flicker when using OpenGL
85 applications (all games are using double-buffered contexts), you need
86 to set the following option in your .winerc / wine.ini in the [x11drv]
87 section :
89 DesktopDoubleBuffered = Y
91 and to run Wine with the '--desktop' option.
95 III How it all works
96 ====================
98 The core OpenGL function calls are the same between Windows and
99 Linux. So what is the difficulty to support it in Wine ? Well, there
100 is two different problems :
102  - the interface to the windowing system is different for each
103    OS. It's called 'GLX' for Linux (well, for X Window) and 'wgl' for
104    Windows. Thus, one need first to emulate one (wgl) with the other
105    (GLX).
107  - the calling convention between Windows (the 'Pascal' convention or
108    'stdcall') is different from the one used on Linux (the 'C'
109    convention or 'cdecl'). This means that each call to an OpenGL
110    function must be 'translated' and cannot be used directly by the
111    Windows program.
113 Add to this some braindead programs (using GL calls without setting-up
114 a context or deleting three time the same context) and you have still
115 some work to do :-)
118 III.1 The Windowing system integration
119 --------------------------------------
121 This integration is done at two levels : 
123  - at GDI level for all pixel format selection routines (ie choosing
124    if one wants a depth / alpha buffer, the size of these buffers,
125    ...) and to do the 'page flipping' in double buffer mode. This is
126    implemented in 'graphics/x11drv/opengl.c' (all these functions are
127    part of Wine's graphic driver function pointer table and thus could
128    be reimplented if ever Wine works on another Windowing system than
129    X).
131  - in the OpenGL32.DLL itself for all other functionalities (context
132    creation / deletion, querying of extension functions, ...). This is
133    done in 'dlls/opengl32/wgl.c'.
136 III.2 The thunks
137 ----------------
139 The thunks are the Wine code that does the calling convention
140 translation and they are auto-generated by a Perl script. In Wine's
141 CVS tree, these thunks are already generated for you. Now, if you want
142 to do it yourself, there is how it all works....
144 The script is located in dlls/opengl32 and is called 'make_opengl'. It
145 requires Perl5 to work and takes two arguments :
147  - the first is the path to the OpenGL registry. Now, you will all ask
148    'but what is the OpenGL registry ?' :-) Well, it's part of the
149    OpenGL sample implementation source tree from SGI (more
150    informations at this URL : http://oss.sgi.com/projects/ogl-sample/). 
152    To summarize, these files contains human-readable but easily parsed
153    informations on ALL OpenGL core functions and ALL registered
154    extensions (for example the prototype, the OpenGL version, ...).
156  - the second is the OpenGL version to 'simulate'. This fixes the list
157    of functions that the Windows application can link directly to
158    without having to query them from the OpenGL driver. Windows is
159    based, for now, on OpenGL 1.1, but the thunks that are in the CVS
160    tree are generated for OpenGL 1.2.
162    This option can have three values '1.0', '1.1' and '1.2'.
164 This script generates three files :
166  - opengl32.spec gives Wine's linker the signature of all function in
167    the OpenGL32.DLL library so that the application can link
168    them. Only 'core' functions are listed here.
170  - opengl_norm.c contains all the thunks for the 'core'
171    functions. Your OpenGL library must provide ALL the function used
172    in this file as these are not queried at run time.
174  - opengl_ext.c contains all the functions that are not part of the
175    'core' functions. Contrary to the thunks in opengl_norm.c, these
176    functions do not depend at all on what your libGL provides. 
178    In fact, before using one of these thunks, the Windows program
179    first needs to 'query' the function pointer. At this point, the
180    corresponding thunk is useless. But as we first query the same
181    function in libGL and store the returned function pointer in the
182    thunk, the latter becomes functional.
186 IV  Known problems - shortcomings
187 =================================
189 IV.1 Missing GLU32.DLL
190 ----------------------
192 GLU is a library that is layered upon OpenGL. There is a 100 %
193 corespondance between the libGLU.so that is used on Linux and
194 GLU32.DLL.
196 As for the moment, I did not create a set of thunks to support this
197 library natively in Wine (it would easy to do, but I am waiting for a
198 better solution than adding another autogenerated thunk file), you can
199 always download anywhere on the net (it's free) a GLU32.DLL file (by
200 browsing, for example, http://ftpsearch.lycos.com/).
203 IV.2 OpenGL not detected at configure time
204 ------------------------------------------
206 See section (I) for a detailed explanation of the configure
207 requirements.
210 IV.3 When running an OpenGL application, the screen flickers
211 ------------------------------------------------------------
213 See section (II) for how to create the context double-buffered and
214 thus preventing this flicker effect.
217 IV.4 Wine gives me the following error message : 
218 ------------------------------------------------
219     Extension defined in the OpenGL library but NOT in opengl_ext.c... Please report
220     (lionel.ulmer@free.fr) !
222 This means that the extension requested by the application is found in
223 the libGL used by Linux (ie the call to glXGetProcAddressARB returns a
224 non NULL pointer) but that this string was NOT found in Wine's
225 extension registry.
227 This can come from two causes :
229  - the opengl_ext.c file is too old and need to be generated again.
231  - use of obsolete extensions that are not supported anymore by SGI or
232    of 'private' extensions that are not registered. An example of the
233    former are 'glMTexCoord2fSGIS' and 'glSelectTextureSGIS' as used by
234    Quake 2 (and apparently also by old versions of Half Life). If
235    documentation can be found on these functions, they can be added to
236    Wine's extension set.
238 If you have this, run with --debugmsg +opengl and send me
239 (lionel.ulmer@free.fr) the TRACE.
242 IV.5 libopengl32.so is built but it is still not working
243 --------------------------------------------------------
245 This may be caused by some missing functions required by opengl_norm.c
246 but that your Linux OpenGL library does not provide.
248 To check for this, do the following steps :
250  - create a dummy .c file :
252 int main(void) {
253     return 0;
256  - try to compile it by linking both libwine and libopengl32 (this
257    command line supposes that you installed the Wine libraries in
258    /usr/local/lib, YMMV) :
260 gcc dummy.c -L/usr/local/lib -lwine -lopengl32
262  - if it works, the problem is somewhere else (and you can send me an
263    email). If not, you could re-generate the thunk files for OpenGL
264    1.1 for example (and send me your OpenGL version so that this
265    problem can be detected at configure time).
269                          Lionel Ulmer (lionel.ulmer@free.fr)
270                          last modification : 2000/06/13