diff options
| author | Michael R Sweet <michael.r.sweet@gmail.com> | 2001-11-29 19:24:00 +0000 |
|---|---|---|
| committer | Michael R Sweet <michael.r.sweet@gmail.com> | 2001-11-29 19:24:00 +0000 |
| commit | 09daf20b81cdae78772f07c0af22a571d7cc73eb (patch) | |
| tree | 1641f788cafe20b505355b0479ba0d528297eb30 /documentation/opengl.html | |
| parent | b105ab8b7fb6281635076559aae96f2b3b12fc51 (diff) | |
Documentation updates galore (up to chapter 7, still need to do chapter
8 and 9, tweek the appendices, and recapture the screenshots...)
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1786 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'documentation/opengl.html')
| -rw-r--r-- | documentation/opengl.html | 144 |
1 files changed, 72 insertions, 72 deletions
diff --git a/documentation/opengl.html b/documentation/opengl.html index a5336af42..b390e46b9 100644 --- a/documentation/opengl.html +++ b/documentation/opengl.html @@ -1,27 +1,27 @@ <HTML><BODY> <H1 ALIGN=RIGHT><A NAME=opengl>9 - Using OpenGL</A></H1> - This chapter discusses using FLTK for your OpenGL applications. + This chapter discusses using FLTK for your OpenGL applications. <H2>Using OpenGL in FLTK</H2> The easiest way to make an OpenGL display is to subclass <A href=Fl_Gl_Window.html#Fl_Gl_Window> <TT>Fl_Gl_Window</TT></A>. Your subclass must implement a <TT>draw()</TT> -method which uses OpenGL calls to draw the display. Your main program -should call <TT>redraw()</TT> when the display needs to change, and -(somewhat later) FLTK will call <TT>draw()</TT>. -<P>With a bit of care you can also use OpenGL to draw into normal FLTK -windows. This allows you to use Gouraud shading for +method which uses OpenGL calls to draw the display. Your main program +should call <TT>redraw()</TT> when the display needs to change, and +(somewhat later) FLTK will call <TT>draw()</TT>. +<P>With a bit of care you can also use OpenGL to draw into normal FLTK +windows. This allows you to use Gouraud shading for drawing your widgets. To do this you use the <A href=#gl_start><TT> gl_start()</TT></A> and <A href=#gl_finish><TT>gl_finish()</TT></A> functions around your OpenGL code. </P> -<P>You must include FLTK's <TT><FL/gl.h></TT> header file. It will -include the file <TT><GL/gl.h></TT>, define some extra drawing -functions provided by FLTK, and include the <TT><windows.h></TT> header +<P>You must include FLTK's <TT><FL/gl.h></TT> header file. It will +include the file <TT><GL/gl.h></TT>, define some extra drawing +functions provided by FLTK, and include the <TT><windows.h></TT> header file needed by WIN32 applications. </P> <H2>Making a Subclass of Fl_Gl_Window</H2> -To make a subclass of Fl_Gl_Window, you must provide: +To make a subclass of Fl_Gl_Window, you must provide: <UL> <LI>A class definition. </LI> <LI>A <TT>draw()</TT> method. </LI> -<LI>A <TT>handle()</TT> method (if you need to receive input from the +<LI>A <TT>handle()</TT> method (if you need to receive input from the user). </LI> </UL> If your subclass provides static controls in the window, they must be @@ -43,7 +43,7 @@ glDrawBuffer(GL_BACK); considerably. The preprocessor instructions shown above will optimize your code based upon the graphics library used. <H3>Defining the Subclass</H3> -To define the subclass you just subclass the <TT>Fl_Gl_Window</TT> class: +To define the subclass you just subclass the <TT>Fl_Gl_Window</TT> class: <UL> <PRE> class MyWindow : public Fl_Gl_Window { @@ -56,12 +56,12 @@ public: }; </PRE> </UL> - The <TT>draw()</TT> and <TT>handle()</TT> methods are described below. - Like any widget, you can include additional private and public data in -your class (such as scene graph information, etc.) + The <TT>draw()</TT> and <TT>handle()</TT> methods are described below. + Like any widget, you can include additional private and public data in +your class (such as scene graph information, etc.) <H3>The draw() Method</H3> - The <TT>draw()</TT> method is where you actually do your OpenGL -drawing: + The <TT>draw()</TT> method is where you actually do your OpenGL +drawing: <UL> <PRE> void MyWindow::draw() { @@ -75,8 +75,8 @@ void MyWindow::draw() { </PRE> </UL> <H3>The handle() Method</H3> - The <TT>handle()</TT> method handles mouse and keyboard events for the -window: + The <TT>handle()</TT> method handles mouse and keyboard events for the +window: <UL> <PRE> int MyWindow::handle(int event) { @@ -88,7 +88,7 @@ int MyWindow::handle(int event) { case FL_DRAG: ... mouse moved while down event ... return 1; - case FL_RELEASE: + case FL_RELEASE: ... mouse up event ... return 1; case FL_FOCUS : @@ -110,11 +110,11 @@ int MyWindow::handle(int event) { } </PRE> </UL> -When <TT>handle()</TT> is called, the OpenGL context is not set up! +When <TT>handle()</TT> is called, the OpenGL context is not set up! If your display changes, you should call <TT>redraw()</TT> and let <TT> -draw()</TT> do the work. Don't call any OpenGL drawing functions from -inside <TT>handle()</TT>! -<P>You can call <I>some</I> OpenGL stuff like hit detection and texture +draw()</TT> do the work. Don't call any OpenGL drawing functions from +inside <TT>handle()</TT>! +<P>You can call <I>some</I> OpenGL stuff like hit detection and texture loading functions by doing: </P> <UL> <PRE> @@ -128,26 +128,26 @@ loading functions by doing: </P> detection, loading textures, etc... </PRE> </UL> -Your main program can now create one of your windows by doing <TT>new +Your main program can now create one of your windows by doing <TT>new MyWindow(...)</TT>. You can also use <A href=FLUID.html#FLUID>FLUID</A> -by: +by: <OL> <LI>Putting your class definition in a <tt>MyWindow.H</tt> file. </LI> <LI>Creating a <tt>Fl_Box</tt> widget in FLUID.</LI> -<LI>In the widget panel fill in the "class" field with <tt>MyWindow</tt>. +<LI>In the widget panel fill in the "class" field with <tt>MyWindow</tt>. This will make FLUID produce constructors for your new class. </LI> -<LI>In the "Extra Code" field put <TT>#include "MyWindow.H"</TT>, so that +<LI>In the "Extra Code" field put <TT>#include "MyWindow.H"</TT>, so that the FLUID output file will compile. </LI> </OL> You must put <TT>glwindow->show()</TT> in your main code after calling <TT> -show()</TT> on the window containing the OpenGL window. +show()</TT> on the window containing the OpenGL window. <H2>Using OpenGL in Normal FLTK Windows</H2> You can put OpenGL code into an <A href="subclassing.html#draw"><TT>Fl_Widget::draw()</TT> </A> method or into the code for a <A href=common.html#boxtypes>boxtype</A> -or other places with some care. -<P>Most importantly, before you show <I>any</I> windows (including those -that don't have OpenGL drawing) you <B>must</B> initialize FLTK so that it -knows it is going to use OpenGL. You may use any of the symbols +or other places with some care. +<P>Most importantly, before you show <I>any</I> windows (including those +that don't have OpenGL drawing) you <B>must</B> initialize FLTK so that it +knows it is going to use OpenGL. You may use any of the symbols described for <A href=Fl_Gl_Window.html#Fl_Gl_Window.mode><TT> Fl_Gl_Window::mode()</TT></A> to describe how you intend to use OpenGL: </P> <UL> @@ -155,8 +155,8 @@ Fl_Gl_Window::mode()</TT></A> to describe how you intend to use OpenGL: </P> Fl::gl_visual(FL_RGB); </PRE> </UL> -You can then put OpenGL drawing code anywhere you can draw normally by -surrounding it with: +You can then put OpenGL drawing code anywhere you can draw normally by +surrounding it with: <UL> <PRE> gl_start(); @@ -165,18 +165,18 @@ gl_finish(); </PRE> </UL> <A name=gl_start><TT>gl_start()</TT></A> and <A name=gl_finish><TT> -gl_finish()</TT></A> set up an OpenGL context with an orthographic -projection so that 0,0 is the lower-left corner of the window and each +gl_finish()</TT></A> set up an OpenGL context with an orthographic +projection so that 0,0 is the lower-left corner of the window and each pixel is one unit. The current clipping is reproduced with OpenGL <TT> -glScissor()</TT> commands. These also synchronize the OpenGL graphics -stream with the drawing done by other X, WIN32, or FLTK functions. -<P>The same context is reused each time. If your code changes the +glScissor()</TT> commands. These also synchronize the OpenGL graphics +stream with the drawing done by other X, WIN32, or FLTK functions. +<P>The same context is reused each time. If your code changes the projection transformation or anything else you should use <TT> -glPushMatrix()</TT> and <TT>glPopMatrix()</TT> functions to put the +glPushMatrix()</TT> and <TT>glPopMatrix()</TT> functions to put the state back before calling <TT>gl_finish()</TT>. </P> -<P>You may want to use <TT>Fl_Window::current()->h()</TT> to get the +<P>You may want to use <TT>Fl_Window::current()->h()</TT> to get the drawable height so that you can flip the Y coordinates. </P> -<P>Unfortunately, there are a bunch of limitations you must adhere to +<P>Unfortunately, there are a bunch of limitations you must adhere to for maximum portability: </P> <UL> <LI>You must choose a default visual with <A href=functions.html#gl_visual> @@ -184,47 +184,47 @@ for maximum portability: </P> <LI>You cannot pass <TT>FL_DOUBLE</TT> to <TT>Fl::gl_visual()</TT>.</LI> <LI>You cannot use <TT>Fl_Double_Window</TT> or <TT>Fl_Overlay_Window</TT>.</LI> </UL> -Do <I>not</I> call <TT>gl_start()</TT> or <TT>gl_finish()</TT> when +Do <I>not</I> call <TT>gl_start()</TT> or <TT>gl_finish()</TT> when drawing into an <TT>Fl_Gl_Window</TT>! <H2>OpenGL Drawing Functions</H2> -FLTK provides some useful OpenGL drawing functions. They can be +FLTK provides some useful OpenGL drawing functions. They can be freely mixed with any OpenGL calls, and are defined by including <TT> <FL/gl.H></TT> (which you should include instead of the OpenGL header <TT> -<GL/gl.h></TT>). +<GL/gl.h></TT>). <H4>void gl_color(Fl_Color)</H4> -Set the current color to a FLTK color. <I>For color-index modes -it will use <TT>fl_xpixel(c)</TT>, which is only right if this window +Set the current color to a FLTK color. <I>For color-index modes +it will use <TT>fl_xpixel(c)</TT>, which is only right if this window uses the default colormap!</I> <H4>void gl_rect(int x, int y, int w, int h) <BR> void gl_rectf(int x, int y, int w, int h)</H4> Outline or fill a rectangle with the current color. If <A HREF="Fl_Gl_Window.html#Fl_Gl_Window.ortho"><TT>Fl_Gl_Window::ortho()</TT></A> -has been called, then the rectangle will exactly fill the pixel -rectangle passed. +has been called, then the rectangle will exactly fill the pixel +rectangle passed. <H4>void gl_font(Fl_Font fontid, int size)</H4> Set the current OpenGL font to the same font you get by calling <A href=drawing.html#fl_font> -<TT>fl_font()</TT></A>. +<TT>fl_font()</TT></A>. <H4>int gl_height() <BR> int gl_descent() <BR> float gl_width(const char *) <BR> float gl_width(const char *, int n) <BR> float gl_width(uchar)</H4> - Return information about the current OpenGL font. + Return information about the current OpenGL font. <H4>void gl_draw(const char *) <BR> void gl_draw(const char *, int n)</H4> -Draw a nul-terminated string or an array of <TT>n</TT> characters in +Draw a nul-terminated string or an array of <TT>n</TT> characters in the current OpenGL font at the current raster position. <H4>void gl_draw(const char *, int x, int y) <BR> void gl_draw(const char *, int n, int x, int y) <BR> void gl_draw(const char *, float x, float y) <BR> void gl_draw(const char *, int n, float x, float y)</H4> - Draw a nul-terminated string or an array of <TT>n</TT> characters in -the current OpenGL font at the given position. + Draw a nul-terminated string or an array of <TT>n</TT> characters in +the current OpenGL font at the given position. <H4>void gl_draw(const char *, int x, int y, int w, int h, Fl_Align)</H4> - Draw a string formatted into a box, with newlines and tabs expanded, -other control characters changed to ^X, and aligned with the edges or + Draw a string formatted into a box, with newlines and tabs expanded, +other control characters changed to ^X, and aligned with the edges or center. Exactly the same output as <A href="drawing.html#text"><TT>fl_draw()</TT></A> -. +. <h2>Speeding up OpenGL</h2> @@ -265,14 +265,14 @@ exit and run the program again for it to see any changes to the environment variable. <H2>Using OpenGL Optimizer with FLTK</H2> -<A href=http://www.sgi.com/software/optimizer>OpenGL Optimizer</A> is a -scene graph toolkit for OpenGL available from Silicon Graphics for IRIX -and Microsoft Windows. Versions are in the works for Solaris and -HP-UX. It allows you to view large scenes without writing a lot of -OpenGL code. +<A href=http://www.sgi.com/software/optimizer>OpenGL Optimizer</A> is a +scene graph toolkit for OpenGL available from Silicon Graphics for IRIX +and Microsoft Windows. Versions are in the works for Solaris and +HP-UX. It allows you to view large scenes without writing a lot of +OpenGL code. <H4>OptimizerWindow Class Definition</H4> To use OpenGL Optimizer with FLTK you'll need to create a subclass of <TT> -Fl_Gl_Widget</TT> that includes several state variables: +Fl_Gl_Widget</TT> that includes several state variables: <UL> <PRE> class OptimizerWindow : public Fl_Gl_Window { @@ -307,12 +307,12 @@ public: </UL> <H4>The camera() Method</H4> - The <TT>camera()</TT> method sets the camera (projection and -viewpoint) to use when drawing the scene. The scene is redrawn after -this call. + The <TT>camera()</TT> method sets the camera (projection and +viewpoint) to use when drawing the scene. The scene is redrawn after +this call. <H4>The draw() Method</H4> - The <TT>draw()</TT> method performs the needed initialization and does -the actual drawing: + The <TT>draw()</TT> method performs the needed initialization and does +the actual drawing: <UL> <PRE> void OptimizerWindow::draw() { @@ -330,7 +330,7 @@ void OptimizerWindow::draw() { context_->makeCurrent(fl_display, fl_window); #endif // WIN32 - ... perform other context setup as desired ... + ... perform other context setup as desired ... // Then create the draw action to handle drawing things... @@ -368,6 +368,6 @@ void OptimizerWindow::draw() { </PRE> </UL> <H4>The scene() Method</H4> - The <TT>scene()</TT> method sets the scene to be drawn. The scene is -a collection of 3D objects in a <TT>csGroup</TT>. The scene is redrawn + The <TT>scene()</TT> method sets the scene to be drawn. The scene is +a collection of 3D objects in a <TT>csGroup</TT>. The scene is redrawn after this call. </BODY></HTML> |
