template.c

Go to the documentation of this file.
00001 /* --
00002 OpenFX version 1.0 - Modelling, Animation and Rendering Package
00003 Copyright (C) 2000 OpenFX Development Team
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019 You may contact the OpenFX development team via elecronic mail
00020 at core@openfx.org, or visit our website at http://openfx.org for
00021 further information and support details.
00022 -- */
00023 
00024 /* TEMPLATE.C     External shader template                                */
00025 /*                                                                        */
00026 /*  It should be possible to quickly build an external shader DLL for     */
00027 /*  using this template file. Watcom C++32 is the recommended             */
00028 /*  compiler. Check the example shader codes to see how some simple       */
00029 /*  shaders are implemented.                                              */
00030 /*                                                                        */
00031 
00032 #include <stdlib.h>
00033 #include <stdio.h>
00034 #include <math.h>
00035 #include <float.h>
00036 #include <windows.h>
00037 
00038 #if __X__MIPS__
00039 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00040 #endif
00041 
00042 #if __ZTC__ || __SC__
00043 #ifndef max
00044 #define max(a,b)  ( ((a) > (b)) ? (a) : (b) )
00045 #endif
00046 #endif
00047 
00048 #ifndef PI
00049 #define PI 3.1415926
00050 #endif
00051 
00052 static HINSTANCE hDLLinstance=NULL; /* use to pick up resources from DLL   */
00053 
00054 /*********************** definitions needed ********************************/
00055 
00056 #include "..\animate\memory.h" /* for memory definition */
00057 #include "..\animate\memdef.h" /* local names           */
00058 #include "defines.h"    /* define names for callback functions             */
00059 #include "rstruct.h"    /* define struct with callback functions etc.      */
00060 #include "template.h"   /* shader specific header file                     */
00061 
00062 /************************** DLL entry point ********************************/
00063 
00064 #if __WATCOMC__
00065 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00066 #else
00067 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00068 #endif
00069   HANDLE ghMod;
00070   switch (dwReason) {
00071     case DLL_PROCESS_ATTACH:
00072 #if __X__MIPS__
00073       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00074 #endif
00075       hDLLinstance = hDLL;  /* handle to DLL file */
00076       break;
00077     case DLL_PROCESS_DETACH:
00078 #if __X__MIPS__
00079       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00080 #endif
00081       break;
00082   }
00083   return (int)TRUE;
00084 }
00085 
00086 #if __SC__
00087 #pragma startaddress(DllMain)
00088 #endif
00089 
00090 /*******************************************************************\
00091 |                Code that define the textures                       |
00092 \*******************************************************************/
00093 
00094 long _ExternalTextureStartup(
00095   long frame,  /* identify the frame in the animation                     */
00096   long nframes,/* number of frames in the animation                       */
00097   char *parameter_list){
00098  if(parameter_list[0] != '#'){
00099    MessageBox ( GetFocus(),
00100                 (LPCTSTR) "External texture: Startup",
00101                 (LPCTSTR) "Parameter list missing",
00102                 MB_OK | MB_SYSTEMMODAL );
00103  }
00104  else { /* use parameters as required */
00105    parameter_list++; /* skip over the idetifying # symbol and read any
00106                         parameters that may be required for this shader
00107                      */
00108  /* extract the shader parameters from the parameter string  */
00109  /* sscanf(parameter_list,"....",&....);  */
00110  }
00111  return 1;
00112 }
00113 
00114 long _ExternalTextureMorph(char *parameter_list, double mr){
00115 /*  mr is 0.0 -> 1.0 morph ratio - if object is being morphed           */
00116 /*  this function is called to allow internal parameters to be adjusted */
00117 /*  so that they may change over the duration of the morph              */
00118  double ground_range1;
00119  parameter_list++; /* skip over the idetifying # symbol and read any
00120                       parameters that may be required for this shader
00121                    */
00122 
00123  /* extract the shader parameters from the parameter string  */
00124  /* sscanf(parameter_list,"....",&....);  */
00125 
00126  /* morph to the original parametes with a statement of the form        */
00127  /* original_value = morph_value+(original_value - morph_value)*mr;     */
00128 
00129  return 1;
00130 }
00131 
00132 long _ExternalTextureProcedure(
00133   long coord_type, /* 0 if alpha/beta/gamma must be used 1 if map-coords available */
00134   vector p,    /* point in World co-ordinates of the suface point to be mapped */
00135   vector n,    /* normal to surface at point to be mapped                  */
00136   double alpha,/* co-ordinates relative to the texture axes  0.0 -> 1.0 is */
00137   double beta, /* inside the parallipiped formed from the texture axes     */
00138   double gamma,
00139   double bump, /* parameter relative to height set for bumps               */
00140   double map_x,/* surface mapping co-ordinates over the face to which the  */
00141   double map_y,/* texture is to be applied                                 */
00142   double *alpha_channel, /* pointer to texture alpha channel        */
00143   unsigned char sc[3], /* original texture/secondary colour as set by user */
00144   double colour[3],    /* return the RGB value in floating point  0-255    */
00145                        /* On calling, the colour contains the colour that  */
00146                        /* has been calculated by any previous shader or    */
00147                        /* the original color                               */
00148   double *reflectivity, /* not used at present  */
00149   double *transparency, /* not used at present  */
00150   X__SHADER *lpEVI     /* pointer to structure */
00151 ){
00152 
00153  /* Execute here the code that creates the shader */
00154 
00155  return 1;
00156 }
00157 
00158 void _ExternalTextureClose(void){
00159 /* This function is called when the frame has been rendered and the texture
00160    DLL is being detached. Use it for freeing any memory allocated during
00161    startup
00162 */
00163 }
00164 
00165 /*********************** Functions used to set up shader ******************/
00166 
00167 /* Dialog box callback  */
00168 
00169 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
00170 
00171 /* Set defaults for the parameter variables, declare them as static so that
00172    they are available to the dialog function. They are here only for the
00173    function that edits the parameter list and must not be used in the
00174    code that is called from the renderer to execute the shader             */
00175 
00176 /************ Functions called by the modeler to set up shader *************/
00177 
00178 char * _SetExternalParameters(
00179   char *Op,                 /* string for the parameters                  */
00180   HWND hWnd,                /* parent window                              */
00181   X__MEMORY_MANAGER *lpEVI /* pointer to structure with memory functions */
00182                              ){
00183 /* output name and buffer should be as long as necessary to hold full string */
00184  char szbuf[128],*Op1;
00185  if(Op != NULL){  /* parameters exist so read them off the list */
00186    Op1=Op;
00187    Op1++; /* skip over the idetifying # symbol and read any
00188              parameters that may be required for this shader
00189            */
00190  /* extract the shader parameters from the parameter string  */
00191  /* sscanf(Op1,"....",&....);  */
00192  }
00193 /*   Do the user interface as required to set up the effect, may use a  */
00194 /*   dialog box etc. Return old string if effect is cancelled           */
00195  if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG_TEMPLATE),hWnd,
00196               (DLGPROC)DlgProc) == FALSE)return Op;
00197  if(Op != NULL)CALL_FREE(Op);  /* free the old string */
00198 /* print the parameters into the buffer       */
00199 /* sprintf(szbuf,"# ....", .......);          */
00200 
00201  sprintf(szbif,"#"); /* just in case this template is compiled ! */
00202 
00203 /* Prepare the output buffer to take copy of parameter list */
00204  if((Op=(char *)CALL_MALLOC(strlen(szbuf)+1)) == NULL){
00205   MessageBox (GetFocus(),"External shader: Out of memory","Error",
00206                 MB_OK|MB_TASKMODAL|MB_ICONSTOP);
00207    return NULL;
00208  }
00209  /* Copy the parameter string to the output buffer */
00210  strcpy(Op,szbuf);
00211  return Op;
00212 }
00213 
00214 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
00215  char str[16];
00216  switch( msg ) {
00217    case WM_INITDIALOG:
00218      return TRUE;
00219    case WM_COMMAND:
00220      switch(LOWORD(wparam)){
00221 
00222         case IDCANCEL:
00223           EndDialog(hwnd,FALSE);
00224           return(TRUE);
00225 
00226         case IDOK:
00227 
00228           /* acquire the parameter values from Edit controls etc. */
00229 
00230           EndDialog(hwnd,TRUE);
00231           return(TRUE);
00232         default:
00233           break;
00234       }
00235       break;
00236     default: break;
00237  }
00238  return FALSE;
00239 }
Generated on Tue Jan 28 06:18:30 2014 for OpenFX by  doxygen 1.6.3