File: capi.html

package info (click to toggle)
mgltools-opengltk 1.5.7-1
  • links: PTS, VCS
  • area: non-free
  • in suites: stretch
  • size: 8,592 kB
  • ctags: 38,393
  • sloc: ansic: 98,617; python: 3,818; cpp: 1,943; sh: 1,332; tcl: 1,127; makefile: 65
file content (577 lines) | stat: -rw-r--r-- 18,891 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
<html>
  <!-- vi:set sw=2: -->
  <!--
  Copyright (C) 1996-2002  Brian Paul and Ben Bederson
  Copyright (C) 2005-2008  Greg Couch
  See the LICENSE file for copyright details.
  -->

  <head>
    <title>Togl C API</title>
  </head>

  <body>
    <script language="javascript" src="header.js"></script>
    <script language="javascript">
      NavigationBar();
    </script>

    <h1 align="center">Togl C API</h1>

    <h2>Contents</h2>
    <ul>
      <li><a href="#compile">Compling and linking C Togl Functions</a>
      <li><a href="#setup">Setup and Initialization Functions</a>
      <ul>
	<li><code>Togl_Init</code>,
	<code>Togl_InitStubs</code>
      </ul>
      <li><a href="#drawing">Drawing-related Commands</a>
      <ul>
	<li><code>Togl_PostRedisplay</code>,
	<code>Togl_SwapBuffers</code>,
	<code>Togl_MakeCurrent</code>,
	<code>Togl_SwapInterval</code>
      </ul>
      <li><a href="#query">Query Functions</a>
      <ul>
	<li><code>Togl_Ident</code>,
	<code>Togl_Width</code>,
	<code>Togl_Height</code>,
	<code>Togl_Interp</code>,
	<code>Togl_TkWin</code>,
	<code>Togl_GetProcAddr</code>,
	<code>Togl_ContextTag</code>
	<code>Togl_UpdatePending</code>
      </ul>
      <li><a href="#index">Color Index Mode Functions</a>
      <ul>
	<li><code>Togl_AllocColor</code>,
	<code>Togl_FreeColor</code>,
	<code>Togl_SetColor</code>
      </ul>
      <li><a href="#font">Font Functions</a>
      <ul>
	<li><code>Togl_LoadBitmapFont</code>,
	<code>Togl_UnloadBitmapFont</code>,
	<code>Togl_WriteObj</code>,
	<code>Togl_WriteChars</code>
      </ul>
      <li><a href="#client">Client Data Functions</a>
      <ul>
	<li><code>Togl_SetClientData</code>,
	<code>Togl_GetClientData</code>
      </ul>
      <li><a href="#overlay">Overlay Functions</a>
      <ul>
	<li><code>Togl_UseLayer</code>,
	<code>Togl_ShowOverlay</code>,
	<code>Togl_HideOverlay</code>,
	<code>Togl_PostOveralyRedisplay</code>,
	<code>Togl_ExistsOverlay</code>,
	<code>Togl_GetOverlayTransparentValue</code>,
	<code>Togl_IsMappedOverlay</code>,
	<code>Togl_AllocColorOverlay</code>,
	<code>Togl_FreeColorOverlay</code>
      </ul>
      <li><a href="#stereo">Stereo Functions</a>
      <ul>
	<li><code>Togl_Drawbuffer</code>,
	<li><code>Togl_Clear</code>
	<li><code>Togl_Frustum</code>
	<li><code>Togl_Ortho</code>
	<li><code>Togl_NumEyes</code>
      </ul>
      <li><a href="#image">Image Functions</a>
      <ul>
	<li><code>Togl_TakePhoto</code>
      </ul>
      <li><a href="#convert">Conversion Functions</a>
      <ul>
	<li><code>Togl_GetToglFromObj</code>,
	<li><code>Togl_GetToglFromName</code>
      </ul>
    </ul>

    <hr>

    <h2><a name="compile">Compling and linking C Togl Functions</a></h2>

    <p>
    All Togl functions are found in the Togl header file.

    <blockquote>
      <code>
	#include "togl.h"
      </code>
    </blockquote>

    <p>
    For portability, you should include the <code>togl.h</code> header
    before any other OpenGL headers
    so it will compile on Microsoft Windows.

    <p>
    Before calling any Togl functions, you need to initialize it.
    Regardless if you're using stubs (by defining <code>USE_TOGL_STUBS</code>)
    or not, the following code will properly initialize togl:

    <blockquote><pre>
if (Tcl_InitStubs(interp, "8.1", 0) == NULL
|| Togl_InitStubs(interp, "2.0", 0) == NULL) {
    /* fail */
}
</pre></blockquote>

    <p>
    If you are using a prebuilt binary distribution,
    you should be sure to define <code>USE_TOGL_STUBS</code> beforehand.

    <p>
    See the source for the demo programs in the Togl source distribution
    for working examples.

    <h3>Linking</h3>

    <p>
    If you are using a prebuilt binary,
    be sure to link against the stub library.
    On Microsoft Windows,
    link against <code>Toglstub20.lib opengl32.lib user32.lib gdi32.lib</code>,
    on Apple Mac OS X,
    link against <code>-lToglstub2.0 -framework OpenGL</code>,
    on other platforms,
    link against <code>-lToglstub2.0 -lGLU -lGL -lm</code>.

    <p>
    If building your own Togl package,
    you can use the stubs interface or link in the Tcl and Tk libraries as well.
    If using the stubs interface, link as shown above.
    Otherwise:
    on Microsoft Windows,
    link against <code>Togl20.lib tk84.lib tcl84.lib opengl32.lib user32.lib gdi32.lib</code>,
    on Apple Mac OS X,
    link against <code>-lTogl2.0 -framework Tk -framework Tcl -framework OpenGL</code>,
    on other platforms,
    link against <code>-lTogl2.0 -ltk8.4 -ltcl8.4 -lGLU -lGL -lm</code>.

    <h2><a name="setup">Setup and Initialization Functions</a></h2>

    <dl>
      <dt><code>int Togl_Init(Tcl_Interp *interp)</code>
      <dd>
      Initializes the Togl module.  This is typically called from the
      Tk_Main() function
      or other Tcl package initialization function that is directly linked
      to the Togl (shared) library.
      It is also indirectly called via
      Tcl's <code>package require Togl</code> command.
    </dl>

    <dl>
      <dt>
      <code>const char *Togl_InitStubs(Tcl_Interp *interp, const char *version, int exact)</code>
      <dd>
      Loads the Togl package into the given <code>interp</code>reter
      and initializes it.
      <code>version</code> should be <code>"2.0"</code> or higher.
      This is typically called from C/C++ code that accesses Togl's C API
      and has installed Togl into the standard TCL hierarchy.
      See the Tcl InitStubs(3) or the Tk TkInitStubs(3) manual pages for
      more information.
    </dl>

    <h2><a name="drawing">Drawing-related Commands</a></h2>

    <dl>
      <dt><code>void Togl_PostRedisplay(Togl *togl)</code>
      <dd>
      Signals that the widget should be redrawn.  When Tk is next idle,
      the <code>displaycommand</code> callback will be invoked.
    </dl>

    <dl>
      <dt><code>void Togl_SwapBuffers(const Togl *togl)</code>
      <dd>
      Swaps the front and back color buffers for a double-buffered widget.
      glFlush() is executed if the window is single-buffered.  So this call
      works for both single- and double-buffered contexts.  This is
      typically called in the <code>displaycommand</code> callback function.
    </dl>

    <dl>
      <dt><code>void Togl_MakeCurrent(const Togl *togl)</code>
      <dd>
      Sets the current rendering context to the given widget.  This is done
      automatically before any Togl callback functions is called.  So the
      call is only needed if you have multiple widgets with separate OpenGL
      contexts.  If the argument is NULL, then the rendering context is cleared
      and subsequent OpenGL commands will fail.
    </dl>

    <dl>
      <dt><code>Bool Togl_SwapInterval(const Togl *togl, int interval)</code>
      <dd>
      Returns 1 (true) if sucessful.
      Attempts to change the maximum refresh rate
      by setting the minimum number of cycles between successive swap buffers.
      For benchmarking purposes, you should set the swap interval to 0.
    </dl>

    <h2><a name="query">Query Functions</a></h2>

    <dl>
      <dt><code>char *Togl_Ident(const Togl *togl)</code>
      <dd>
      Returns a pointer to the identification string associated with a Togl
      widget or NULL if there's no identifier string.
    </dl>

    <dl>
      <dt><code>int Togl_Width(const Togl *togl)</code>
      <dd>
      Returns the width of the given Togl widget.  Typically called in the
      <code>reshapecommand</code> callback function.
    </dl>

    <dl>
      <dt><code>int Togl_Height(const Togl *togl)</code>
      <dd>
      Returns the height of the given Togl widget.  Typically called in the
      <code>reshapecommand</code> callback function.
    </dl>

    <dl>
      <dt><code>Tcl_Interp *Togl_Interp(const Togl *togl)</code>
      <dd>
      Returns the Tcl interpreter associated with the given Togl widget.
    </dl>
    <dl>
      <dt>
      <code>Tk_Window Togl_TkWin(const Togl *togl)</code>
      <dd>
      Returns the Tk window associated with the given Togl widget.
    </dl>

    <dl>
      <dt><code>Togl_FuncPtr Togl_GetProcAddr(const char *funcname)</code>
      <dd>
      Platform-independent way to get OpenGL function pointers from a
      function name.
      Note that in Windows (WGL) versions that
      "the extension function addresses are unique for each pixel format.
      All rendering contexts of a given pixel format
      share the same extension function addresses."
      And on *nix (GLX/X11) platforms, 
      "the function pointers returned are context independent"
      (Linux ABI documentation).
      The Mac OS X (AGL) platform acts like a *nix platform.
    </dl>

    <dl>
      <dt><code>int Togl_ContextTag(const Togl *t)</code>
      <dd>
      Returns an integer that represents the context tag.
      All Togl widgets with the same context tag share display lists.
    </dl>

    <dl>
      <dt><code>Bool Togl_UpdatePending(const Togl *t)</code>
      <dd>
      Returns 1 (true) if the window should be redrawn.  See Togl_PostRedisplay.
    </dl>

    <h2><a name="index">Color Index Mode Functions</a></h2>

    <p>
    These functions are only used for color index mode.

    <dl>
      <dt><code>unsigned long Togl_AllocColor(Togl *togl, float red, float green, float blue)</code>
      <dd>
      Allocate a color from a read-only colormap.  Given a color specified
      by red, green, and blue return a colormap index (aka pixel value)
      whose entry most closely matches the red, green, blue color.  Red,
      green, and blue are values in [0,1].  This function is only used in
      color index mode when the <code>-privatecmap</code> option is false.
    </dl>

    <dl>
      <dt><code>void Togl_FreeColor(Togl *togl, unsigned long index)</code>
      <dd>
      Free a color in a read-only colormap.  Index is a value which was
      returned by the Togl_AllocColor() function.  This function is only
      used in color index mode when the <code>-privatecmap</code> option
      is false.
    </dl>

    <dl>
      <dt><code>void Togl_SetColor(Togl *togl,
	int index, float red, float green, float blue)</code>
      <dd>
      Load the colormap entry specified by index with the given red, green
      and blue values.  Red, green, and blue are values in [0,1].  This
      function is only used in color index mode when the
      <code>-privatecmap</code> option is true.
    </dl>


    <h2><a name="font">Font Functions</a></h2>

    <p>
    These functions provide an interface to the simple bitmap font capabilities
    that every OpenGL implementation provides.
    Better font support is found in other C APIs, <i>e.g.</i>,
    <a href="http://quesoglc.sourceforge.net/">QuesoGLC</a>
    or <a href="http://sourceforge.net/projects/ftgl">FTGL</a>.

    <dl>
      <dt><code>GLuint Togl_LoadBitmapFont(Togl *togl,
	const char *fontname)</code>
      <dd>
      Load the named font as a set of glBitmap display lists.
      <var>fontname</var> may be any of the font description styles
      accepted by the Tk font command.
      For maximum portability, one of the standard Tk fonts,
      <b>Courier</b>, <b>Times</b>, and <b>Helvetica</b>, should be used.
      Unicode fonts are treated as if they have only have an 8-bit index
      (so poorly).
      After Togl_LoadBitmapFont() has been called, returning <var>fontbase</var>,
      you can render a string <em>s</em> with:
      <blockquote>
	<code>
	  glListBase(fontbase);<br>
	  glCallLists(strlen(s), GL_BYTE, s);
	</code>
      </blockquote>
      Zero is returned if this function fails.
    </dl>

    <dl>
      <dt><code>int Togl_UnloadBitmapFont(Togl *togl, Tcl_Obj *toglfont)
      </code>
      <dd>
      Destroys the bitmap display lists created by by Togl_LoadBitmapFont().
    </dl>

    <dl>
      <dt><code>int Togl_WriteChars(const Togl *togl, const Tcl_Obj *toglfont, const char *str, int len)
      </code>
      <dd>
    </dl>

    <dl>
      <dt><code>int Togl_WriteObj(const Togl *togl, const Tcl_Obj *toglfont, Tcl_Obj *obj)
      </code>
      <dd>
      Tcl_Obj interface to <code>Tcl_WriteChars</code>.
    </dl>

    <h2><a name="client">Client Data Functions</a></h2>

    <dl>
      <dt><code>void Togl_SetClientData(Togl *togl, ClientData clientData)</code>
      <dd>
      <em>clientData</em> is a pointer to an arbitrary user data structure.
      Each Togl struct has such a pointer.
      This function sets the Togl widget's client data pointer.
    </dl>

    <dl>
      <dt><code>ClientData Togl_GetClientData(const Togl *togl)</code>
      <dd>
      <em>clientData</em> is a pointer to an arbitrary user data structure.
      Each Togl struct has such a pointer.
      This function returns the Togl widget's client data pointer.
    </dl>


    <h2><a name="overlay">Overlay Functions</a></h2>

    <p>
    These functions are modelled after GLUT's overlay sub-API.

    <dl>
      <dt><code>void Togl_UseLayer(Togl *togl, int layer)</code>
      <dd>
      Select the layer into which subsequent OpenGL rendering will be
      directed.  <em>layer</em> may be either <em>TOGL_OVERLAY</em> or
      <em>TOGL_NORMAL</em>.
    </dl>

    <dl>
      <dt><code>void Togl_ShowOverlay(Togl *togl)</code>
      <dd>
      Display the overlay planes, if any.
    </dl>

    <dl>
      <dt><code>void Togl_HideOverlay(Togl *togl)</code>
      <dd>
      Hide the overlay planes, if any.
    </dl>

    <dl>
      <dt><code>void Togl_PostOverlayRedisplay(Togl *togl)</code>
      <dd>
      Signal that the overlay planes should be redraw.  
      When Tk is next idle,
      the <code>overlaydisplaycommand</code> callback will be invoked.
    </dl>

    <dl>
      <dt><code>int Togl_ExistsOverlay(Togl *togl)</code>
      <dd>
      Returns 1 if overlay planes exist, 0 otherwise.
    </dl>

    <dl>
      <dt><code>int Togl_GetOverlayTransparentValue(const Togl *togl)</code>
      <dd>
      Returns the color index of the overlay's transparent pixel value.
    </dl>

    <dl>
      <dt><code>int Togl_IsMappedOverlay(const Togl *togl)</code>
      <dd>
      Returns 1 if the overlay planes are currently displayed, 0 otherwise.
    </dl>

    <dl>
      <dt><code>unsigned long Togl_AllocColorOverlay(const Togl *togl,
	float red, float green, float blue)</code>
      <dd>
      Allocate a color in the overlay planes.  Red, green, and blue are
      values in [0,1].  Return the color index or -1 if the allocation
      fails.
    </dl>

    <dl>
      <dt><code>void Togl_FreeColorOverlay(const Togl *togl, unsigned long index)</code>
      <dd>
      Free a color which was allocated with Togl_AllocColorOverlay().
    </dl>

    <h2><a name="stereo">Stereo Functions</a></h2>

    <p>
    Togl abstracts part of the stereo drawing process to seamlessly
    support quad-buffered stereo as well as various alternative stereo
    formats.

    <dl>
      <dt><code>void Togl_DrawBuffer(Togl *togl, GLenum mode)</code>
      <dd>
      Switch to OpenGL draw buffer.
      Should be one of GL_BACK_LEFT, GL_BACK_RIGHT, GL_FRONT_LEFT, or
      GL_FRONT_RIGHT.
      It is not possible to draw in the left and right buffers at the same
      time in the alternate stereo modes.
    </dl>

    <dl>
      <dt><code>void Togl_Clear(const Togl *togl, GLbitfield mask)</code>
      <dd>
      Replacement for OpenGL's glClear that takes into account
      the alternate stereo mode.
    </dl>

    <dl>
      <dt><code>void Togl_Frustum(const Togl *togl, GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far)</code>
      <dd>
      eyeOffset is the distance from the center line and is negative for the
      left eye and positive for right eye.
      eyeDist and eyeOffset need to be in the same units as your model space.
      In physical space, eyeDist might be 30 inches from the screen
      and eyeDist would be +/- 1.25 inch (for a total interocular distance
      of 2.5 inches).  So you need to convert those values.
    </dl>

    <dl>
      <dt><code>void Togl_Ortho(const Togl *togl, GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat near, GLfloat far)</code>
      <dd>
      eyeOffset is the distance from the center line and is negative for the
      left eye and positive for right eye.
      eyeDist and eyeOffset need to be in the same units as your model space.
      In physical space, eyeDist might be 30 inches from the screen
      and eyeDist would be +/- 1.25 inch (for a total interocular distance
      of 2.5 inches).  So you need to convert those values.
    </dl>

    <dl>
      <dt><code>int Togl_NumEyes(const Togl *togl)</code>
      <dd>
    </dl>

    <h3>Stereo Example</h3>

    <p>
    This code works for quad-buffered stereo,
    as well as the other stereo modes.

    <blockquote><pre>
if (Togl_NumEyes(togl) == 1) {
    Togl_DrawBuffer(togl, GL_BACK);
    Togl_Clear(togl);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    Togl_Frustum(togl, left, right, bottom, top, near, far);
    glMatrixMode(GL_MODELVIEW);
    <b><i>draw image</i></b>
} else {
    Togl_DrawBuffer(togl, GL_BACK_LEFT);
    Togl_Clear(togl);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    Togl_Frustum(togl, left, right, bottom, top, near, far);
    glMatrixMode(GL_MODELVIEW);
    <b><i>draw left-eye image</i></b>
    Togl_DrawBuffer(togl, GL_BACK_RIGHT);
    Togl_Clear(togl);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    Togl_Frustum(togl, left, right, bottom, top, near, far);
    glMatrixMode(GL_MODELVIEW);
    <b><i>draw right-eye image</i></b>
}
Togl_SwapBuffers(togl);
</pre></blockquote>

    <h2><a name="image">Image Functions</a></h2>

    <p>
    <!--description-->

    <dl>
      <dt><code>int Togl_TakePhoto(Togl *togl, Tk_PhotoHandle photo)</code>
      <dd>
      Take a photo image of the current Togl window and place it in the
      given <code>photo</code> object.
      If the window is partially obscured,
      either by other windows or by the edges of the display,
      the results are undefined in the obscured region. 
    </dl>

    <h2><a name="convert">Conversion Functions</a></h2>

    <p>
    These functions aid the programmer when writing Togl callback functions.

    <dl>
      <dt><code>int Togl_GetToglFromObj(Tcl_Interp *interp, Tcl_Obj *obj, Togl **toglPtr)</code>
      <dd>
      Attempt to return a Togl structure "toglPtr" from the Tcl object "obj".
    </dl>

    <dl>
      <dt><code>int Togl_GetToglFromName(Tcl_Interp *interp, const char *cmdName, Togl **toglPtr)</code>
      <dd>
      Attempt to return a Togl structure "toglPtr" from the Tcl command name "cmdName".
    </dl>

    <hr>
    Hosted by <a href="http://sourceforge.net/">
      <img src="http://sflogo.sourceforge.net/sflogo.php?group_id=519&amp;type=1" width="88" height="31" border="0" alt="SourceForge.net Logo" align="middle"/>
    </a>
  </body>
</html>