File: using.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 (165 lines) | stat: -rw-r--r-- 4,883 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
<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>Using the Togl Widget</title>
  </head>

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

    <h1 align="center">Using the Togl Widget</h1>

    <h2>Contents</h2>
    <ul>
      <li><a href="#using">Using Togl With Your Application</a>
      <li><a href="#examples">Examples</a>
      <li><a href="tclapi.html">Tcl API</a>
      <li><a href="capi.html">C API</a>
    </ul>

    <hr>

    <h2><a name="using">Using Togl With Your Application</a></h2>

    <p>
    First, double check that you have all of the
    <a href="download.html#prereq">prerequisites</a>
    and that you have
    <a href="download.html#building">compiled and installed</a> Togl.
    <p>
    Then, Togl acts like any other extension package &mdash;
    to load it, you use the Tcl <code>package</code> command:
    <blockquote>
      <code>package require Togl 2.0</code>
    </blockquote>
    After that, you can create a Togl widget just like any other Tk widget.

    <h2><a name="examples">Examples</a></h2>

    <p>
    There are six working examples:

    <blockquote>
      <table border="0">
	<tr>
	  <td>double.tcl</td>
	  <td>&mdash; compares single vs double buffering with two Togl widgets</td>
	</tr>
	<tr>
	  <td>texture.tcl</td>
	  <td>&mdash; lets you play with texture mapping options</td>
	</tr>
	<tr>
	  <td>index.tcl</td>
	  <td>&mdash; example of using color index mode</td>
	</tr>
	<tr>
	  <td>overlay.tcl</td>
	  <td>&mdash; example of using overlay planes (requires overlay hardware)</td>
	</tr>
	<tr>
	  <td>stereo.tcl</td>
	  <td>&mdash; stereo example</td>
	</tr>
	<tr>
	  <td>gears.tcl</td>
	  <td>&mdash; spinning gears example</td>
	</tr>
      </table>
    </blockquote>

    <p>
    Each example consists of two files: a Tcl script for the user interface,
    and a Tcl C package that does the OpenGL drawing.
    To compile the examples, type <code>make examples</code>
    in the Togl source directory.
    The C packages are compiled into shared libraries
    that are loaded into the Tcl interpreter as Tcl/Tk-extensions.
    The examples are started by running the corrsponding Tcl script:
    just type <code>./double.tcl</code>
    (or <code>./texture.tcl</code> <i>etc.</i>)
    or run under one of the Tcl interpreters, <i>i.e.</i>,
    <code>tclsh</code> or <code>wish</code>.
    For example:
    <blockquote>
      <code>tclsh84 double.tcl</code>.
    </blockquote>

    <p>
    Other examples that use Tcl for OpenGL drawing can be found in the
    <a href="http://tcl3d.org/html/demos.html">Tcl3D demos</a>.

    <h3><a name="callbacks">Togl callbacks</a></h3>
    <p>
    All of the examples have similar structure.
    First they create the user interface with one or more Togl widgets.
    Each Togl widget is configured with the desired pixel format
    and several callback commands (not all are needed):
    <table>
      <tr>
	<td><code>-createcommand</code></td>
	<td>
	  Called when Togl widget is mapped &mdash;
	  when it is safe to initialize the OpenGL context.
	</td>
      </tr>
      <tr>
	<td><code>-reshapecommand</code></td>
	<td>
	  Called when the Togl widget is resized &mdash;
	  when the OpenGL context's viewport needs to be changed.
	</td>
      </tr>
      <tr>
	<td><code>-displaycommand</code></td>
	<td>
	  Called when the contents of the Togl widget needs to be redrawn.
	  Redraws are normally delayed to be when the Tcl event loop is idle
	  (see the togl widget's <code>postredisplay</code> command),
	  or as the result of an explict call to the togl's widgets
	  <code>render</code> command.
	</td>
      </tr>
      <tr>
	<td><code>-destroycommand</code></td>
	<td>
	  Called when the Togl widget is destroyed.
	  While OpenGL frees display lists and other resources,
	  sometimes there's some associated state that is no longer needed.
	</td>
      </tr>
      <tr>
	<td><code>-timercommand</code></td>
	<td>
	  Called every <i>n</i> milliseconds
	  as given by the <code>-time</code> option.
	</td>
      </tr>
      <tr>
	<td><code>-overlaydisplaycommand</code></td>
	<td>
	  Called when the overlay planes needs to be redrawn.
	  The overlay planes are created and reshaped
	  at the same time as the main OpenGL context.
	</td>
      </tr>
    </table>

    Typically, only <code>-createcommand</code>, <code>-reshapecommand</code>
    and <code>-displaycommand</code> are used.

    <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>