glwin.h

来自「有限元学习研究用源代码(老外的),供科研人员参考」· C头文件 代码 · 共 1,032 行 · 第 1/3 页

H
1,032
字号
/*
% $Id: glwin.h,v 2.23 1998/09/04 15:25:48 fuhrmann Exp $

\section{glwin - A System Interface for OpenGL Applications}
$Revision: 2.23 $\\
$Date: 1998/09/04 15:25:48 $\\
Author: J\"urgen Fuhrmann\\
\bigskip
%--------------------------------------------------------------------

This  module provides   access   to basic   facilities as   X   window
management,  event handling, off  screen rendering  etc.   It has been
derived from the  OpenGL sample  {\em  tk} code by  putting all global
variables into a structure  called {\tt glWindow}.  Not everything has
been  checked, especially   not  the color  index   stuff.   I is  the
intention of the author  to keep track of  changes in the {\em  libtk}
toolkit. 
There are three   main difference to  the {\em libtk} kit:
 \begin{itemize}
 \item  {\em glwin} is able to  to manage more than  one window at one
   time. This  has been achieved by wrapping  all  global variables of
   {\em libtk} into  a (hidden) data type  {\tt glWindow} and  letting
   the user provide  data to all callback  routines via a  {\tt void*}
   parameter. 
 \item   The  event loop (called    by  {\tt glwProcess()})  knows  an
   application-controlled  and  an  event-controlled (user-controlled)
   mode. 
   
   In  application-controlled  mode it is   possible  to  attach a  GL
   window, let   it process any pending  events,  render user data and
   exit without  destroying   the window contents.    This enables the
   usage of  {\em glwin} under  the control  of the application during
   transient simulations etc. 
  
   In  event-controlled  mode,   the  event   loop  needs  some   user
   itervention (e.g. key press) to exit. 

 \item {\tt glwGrab()} grabs the actual window contents and dumps it
      into a ppm file. 
\begin{comment}
 \item  {\tt  glwDump()}  calls the user   redraw   function within an
   off-screen rendering context attached to a pixmap of user definable
   size. The  rendered data are read into  a buffer and  dumped into a
   tiff file.  To enable this  feature, TIFF support (using libtiff.a)
   has to be compiled in. 
\end{comment}
 \item {\tt glwStartRecording()/glwStopRecording} record an MPEG stream
 using mpeg\_encode version 1.5 or higher.

\end{itemize}
       

%--------------------------------------------------------------------
\subsection{Acknowledgements}

The kernel  of the code has been  derived from various versions of the
''tk nano window toolkit'' which comes  along as OpenGL demo software.
Namely, code comes from versions on SGI and Digital machines, and from
the MESA distribution. 


%--------------------------------------------------------------------
\subsection{Installation}
\label{glwin:subsect:Installation}
The installation should be fairly simple. You need an ANSI C compiler,
the headers and libraries of X11 and GL and.
Sorry for not providing Imakefiles and configure scripts - to me, these
are  a mess, and I try not to  use anyting non-portable in my code.


\subsubsection{Installation with vendor installed OpenGL}
Everything should be smooth, you don't need to define 
any preprocessor options. Link with ''{\tt -lGL -lXext -lX11}''.


\subsubsection{Installation with MESA}

Obtain MESA from 
{\tt http://www.ssec.wisc.edu/~brianp/Mesa.html}
and install it - the best way would be in {\tt /usr/local/{*}}.

Then compile {\tt glwin.c} with ''{\tt -I/usr/local/include}''
and link with\\ ''{\tt -L/usr/local/lib -lMesaGL -lXext -lX11}''
(or whatever you have called the MESA libraries).
*/


/*
%--------------------------------------------------------------------
\subsection{Imported packages}
*/
#ifndef GLW_HEADER
#define GLW_HEADER

#include <GL/gl.h>
#include <stdio.h>
/*
%--------------------------------------------------------------------
\subsection{Data Types}
*/


/*\func{glWindow}*/
typedef  struct glWindowStruct *glWindow;  
/* 
This is the basic handle
structure, all data in it are hidden from the user. 
*/

/*
%--------------------------------------------------------------------
\subsection{Constructors and Destructors}
*/

/*\func{glwInitDisplayMode}*/
void glwInitDisplayMode(
                        GLenum mode
                        );
/*

Set the display mode for next window to create.
The  default value is\\ \verb-GLW_RGB|GLW_DOUBLE|GLW_DIRECT|GLW_DEPTH-.
Possible values are combinations of the following bitmasks:

*/

#define GLW_RGB         0       /* RGB mode */
#define GLW_INDEX       1       /* Color index mode */
#define GLW_SINGLE      0       /* Single buffer mode */
#define GLW_DOUBLE      2       /* Double buffer mode */
#define GLW_DIRECT      0       /* Direct rendering */
#define GLW_INDIRECT    4       /* Indirect rendering */
#define GLW_ACCUM       8       /* Enable accumulation buffer  */
#define GLW_ALPHA       16      /* Enable alpha calculations */ 
#define GLW_DEPTH       32      /* Enable depth buffer */
#define GLW_OVERLAY     64      /* Create Window with overlay */
#define GLW_UNDERLAY    128
#define GLW_STENCIL     512    
#define GLW_PIXMAP     1024



/*


At startup    and after creating   a window,  all  values  are reset to
the defaults.  The values  set are used  only for the next window
created. 
%-----------------------------------------------------------------*/

/*\func{glwInitPos}*/
void glwInitPos(
                     int x,
                     int y
                     );
/*
Set the   initial position of  the upper left corner of the
window on  the screen.
Default: $(0,0)$ (Upper left corner of the screen). 


%-----------------------------------------------------------------*/

/*\func{glwInitSize}*/
void glwInitPos(
                     int x,
                     int y
                     );
#define GLW_SIZE_MPEG1_PAL  352,288 
#define GLW_SIZE_MPEG2_PAL  704,576
#define GLW_SIZE_MPEG1_NTSC 352,240 
#define GLW_SIZE_MPEG2_NTSC 704,480

#define GLW_SIZE_1 1024,768
#define GLW_SIZE_2 1280,1024
#define GLW_SIZE_3 1600,1200

/*
Set the   size  of the window  on  the screen.

Default: GLW\_PAL\_HALF.
The sizes are not mandatory.
The MPEG-1 standard does not demand any frame size, the MPEG-2 standard
demans a multiple of 16 in the frame size.

However it is useful to stick to the MPEG sizes given here if one
wants to use MPEG in connection with hardware. 


%-----------------------------------------------------------------*/
/*\func{glwInitTitle}*/
void glwInitTitle(
                  char * title
                  );
/*
  
Set the title of the window to be created.
Default: ''gltools-1.0''
  
At startup and after  creating a window, all values  are reset to  the
defaults.  The values set are used only for the next window created. 

The maximum length of a name is defined here:
*/
#define GLW_NAMELEN 128


/*\func{ glwInitDisplayModePolicy}*/
void glwInitDisplayModePolicy(
                              GLenum type
                              );
/*
   Set visual match mode.
   Default: \verb|GLW_MINIMUM_CRITERIA|.

   Possible values:

*/

enum {
    GLW_USE_ID = 1,
    GLW_EXACT_MATCH,
    GLW_MINIMUM_CRITERIA
};

/*

At startup and  after creating a window,  all values are  reset to the
defaults.  The values set are used only for the next window created. 

*/

/*\func{glwInitOffscreen}*/

void glwInitOffscreen(void);
/* 

Declare window to be created to be an offscreen window. This could
be used for e.g. for creating frames in batch mode. The corresponding
code is in beta status.

At startup and  after creating a window,  all values are  reset to the
defaults.  The values set are used only for the next window created. 
*/


/*\func{glwInitAspectKeeping}*/
void glwInitAspectKeeping(
                          int yesno
                          );
/* 
   Keep aspect ratio of window when resizing.
   Default: 1 (yes).

At startup and after  creating a window, all values  are reset to  the
defaults.  The values set are used only for the next window created. 

\func{glwGetDefault}
*/

char * glwGetDefault(glWindow w, char * resource, char *dflt);
/*

Read resource from resource database, e.g. reads
gltools*printerCommand from your .Xdefaults.
Returns default if resource has not been found in database.

\func{glwCreate}

*/
glWindow  glwCreate(
                    void
                    );
/*
   Create a window.
   Multiple windows may be created. 
   OpenGL renders into the window freshly created or the window
   defined by \xref{glwAttach}.


\func{glwDestroy}

*/
void      glwDestroy(
                     glWindow win
                     );
/*
   Destroy the window. 

*/

/*
%--------------------------------------------------------
\subsection{Control}
*/

/*\func{glwAttach}
*/

int       glwAttach(
                    glWindow win
                    );
/*

   ''Attach'' the window, i.e. make the corresponding OpenGL context
current.

%-----------------------------------------------------------------*/
/*\func{glwFlush}
*/

void       glwFlush(
                    glWindow win
                    );
/*

   Flush the window. 

%-----------------------------------------------------------------*/
/*\func{glwProcess}
*/
void      glwProcess(
                     glWindow win,
                     void *user_data
                     );
/* 
   Process event loop. User data are rendered by calling the
   redraw function set by \xref{glwSetRedrawFunc}. 
The event loop is exited 
   \begin{itemize}
  \item after  {\tt glwQuit()} call (user intervention) in 
     event driven mode 
   \item after processing pending events, {\em one} redraw and {\tt glwQuit()} 
      in 
     application driven mode.
   \end{itemize}
   The parameter {\tt info} is used to pass user data to the callback routines.

  Thus, gltools can be used for rendering under control of the user code.

%-----------------------------------------------------------------*/
/*\func{glwSetControlMode} */
void glwSetControlMode(
                       glWindow w, 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?