checks.c

Go to the documentation of this file.
00001 /* --
00002 OpenFX version 2.0 - Modelling, Animation and Rendering Package
00003 Copyright (C) 2000 - 2007 OpenFX Development Team
00004 -- */
00005 
00006 // checks.c
00007 
00008 #include <stdlib.h>
00009 #include <stdio.h>
00010 #include <math.h>
00011 #include <float.h>
00012 #include <windows.h>
00013 #include <gl/gl.h>
00014 
00015 #if __ZTC__ || __SC__
00016 #ifndef max
00017 #define max(a,b)  ( ((a) > (b)) ? (a) : (b) )
00018 #endif
00019 #endif
00020 
00021 #if __WATCOMC__
00022 #define PI 3.1415926
00023 #endif
00024 
00025 #if __X__MIPS__
00026 BOOL WINAPI _CRT_INIT(HINSTANCE ,DWORD , LPVOID );
00027 #endif
00028 
00029 static HINSTANCE hDLLinstance=NULL;
00030 
00031 #include "..\animate\memory.h" /* for memory definition */
00032 #include "..\animate\memdef.h" /* local names           */
00033 #include "defines.h"
00034 #include "rstruct.h"
00035 #include "checks.h"
00036 
00037 #define FLOOR(x) ((x) >= 0.0 ? floor(x) : (0.0 - floor(0.0 - (x)) - 1.0))
00038 #define FMOD(x,a) ((x) >= 0.0 ? fmod(x,a) :(a - fmod(-(x),a)))
00039 
00040 #if __WATCOMC__
00041 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00042 #else
00043 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00044 #endif
00045   HANDLE ghMod;
00046   switch (dwReason) {
00047     case DLL_PROCESS_ATTACH:
00048 #if __X__MIPS__
00049       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00050 #endif
00051       hDLLinstance = hDLL;  /* handle to DLL file */
00052       break;
00053     case DLL_PROCESS_DETACH:
00054 #if __X__MIPS__
00055       if(!_CRT_INIT(hDLL,dwReason,lpReserved))return(int)FALSE;
00056 #endif
00057       break;
00058   }
00059   return (int)TRUE;
00060 }
00061 
00062 #if __SC__
00063 #pragma startaddress(DllMain)
00064 #endif
00065 
00066 static double x=1.0,y=1.0,z=1.0;
00067 
00068 #if 0
00069 long CALLBACK ExternalTextureStartup(
00070 #else
00071 long _ExternalTextureStartup(
00072 #endif
00073   long frame,long nframes,char *parameter_list, X__SHADER *lpEVI){
00074  if(parameter_list[0] != '#'){
00075    MessageBox ( GetFocus(),
00076                 (LPCTSTR) "External texture: Startup",
00077                 (LPCTSTR) "Parameter list missing",
00078                 MB_OK | MB_SYSTEMMODAL );
00079  }
00080  else {
00081   parameter_list++;
00082   sscanf(parameter_list,"%f %f %f",
00083          &x,&y,&z);
00084  }
00085  return LoadAndCompileShader("checks");
00086 }
00087 
00088 #if 0
00089 long CALLBACK ExternalTextureMorph(
00090 #else
00091 long _ExternalTextureMorph(
00092 #endif
00093  char *parameter_list, double mr){
00094  double x_m,y_m,z_m;
00095  parameter_list++;
00096  sscanf(parameter_list,"%f %f %f",
00097         &x_m,&y_m,&z_m);
00098  x=x_m+(x-x_m)*mr;
00099  y=y_m+(y-y_m)*mr;
00100  z=z_m+(z-z_m)*mr;
00101  return 1;
00102 }
00103 
00104 #if 0
00105 long CALLBACK ExternalTextureProcedure(
00106 #else
00107 long _ExternalTextureProcedure(
00108 #endif
00109   long coord_type,  vector p, vector n,
00110   double alpha, double beta, double gamma,
00111   double bump,  double map_x,  double map_y,
00112   double *alpha_channel, unsigned char sc[3], double colour[3],
00113   double *reflectivity, double *transparency,
00114   X__SHADER *lpEVI
00115 ){
00116  long id;
00117  double xx,yy,zz,noise;
00118  double xr,xl,yr,yl,zr,zl;
00119  xx=alpha / x;
00120  yy=beta  / y;
00121  zz=gamma / z;
00122  id = (long)FLOOR(xx) + (long)FLOOR(yy) + (long)FLOOR(zz);
00123  if(id & 1){
00124    colour[0]=(double)sc[0];
00125    colour[1]=(double)sc[1];
00126    colour[2]=(double)sc[2];
00127  }
00128  return 1;
00129 }
00130 
00131 
00132 
00133 void _ExternalTextureClose(X__SHADER *lpEVI){
00134  UnloadCompiledShader(tGLshaderID);
00135 }
00136 
00137 long _ExternalTextureProcedureGL(
00138   double bump_scale,
00139   unsigned char sc[3],
00140   unsigned char ac[3],
00141   X__SHADER *lpEVI
00142 ){
00143  // Set any shader specific uniform variables here.
00144  SetUniformVector(tGLshaderID,"MaterialC",(GLfloat)ac[0]/255.0,(GLfloat)ac[1]/255.0,(GLfloat)ac[2]/255.0);
00145  SetUniformVector(tGLshaderID,"ScalingV",1.0/x,1.0/z,1.0/y);
00146  // Callback to Render the Polygons - this allows for multiple passes - through same shaders
00147  // possibly with different parameters - including vertex offset - blending depth enabling 
00148  // to allow for multipass textures e.g. hair and fur (shell model) it's arguments must not be altered!!!
00149  DrawShadedPolygons(tmatpass,tpass,tprogID,tattrloc,tNface,tMainFp,tNvert,tMainVp);
00150  return 1;
00151 }
00153 
00154 void CentreDialogOnScreen(HWND hwnd){
00155  RECT rcDlg;
00156  long Xres,Yres;
00157  Yres=GetSystemMetrics(SM_CYSCREEN);
00158  Xres=GetSystemMetrics(SM_CXSCREEN);
00159  GetWindowRect(hwnd,&rcDlg);
00160  OffsetRect(&rcDlg,-rcDlg.left,-rcDlg.top);
00161  OffsetRect(&rcDlg,(Xres-rcDlg.right)/2,(Yres-rcDlg.bottom)/2);
00162  SetWindowPos(hwnd,HWND_TOP,rcDlg.left,rcDlg.top,0,0,SWP_NOSIZE);
00163  return;
00164 }
00165 
00166 static void SetColour(double *colour, HWND parent){
00167  CHOOSECOLOR cc;
00168  static COLORREF CustColours[16]={
00169    RGB(255,255,255), RGB(239,239,239), RGB(223,223,223), RGB(207,207,207),
00170    RGB(191,191,191), RGB(175,175,175), RGB(159,159,159), RGB(143,143,143),
00171    RGB(127,127,127), RGB(111,111,111), RGB( 95, 95, 95), RGB( 79, 79, 79),
00172    RGB( 63, 63, 63), RGB( 47, 47, 47), RGB( 31, 31, 31), RGB( 15, 15, 15) };
00173  cc.lStructSize=sizeof(CHOOSECOLOR);
00174  cc.hwndOwner=parent;
00175  cc.rgbResult=RGB((BYTE)colour[0],(BYTE)colour[1],(BYTE)colour[2]);
00176  cc.lpCustColors=(LPDWORD)CustColours;
00177  cc.Flags= CC_RGBINIT;
00178  cc.lCustData=(DWORD)0;
00179  if(ChooseColor(&cc)){
00180    colour[0]=(double)GetRValue(cc.rgbResult);
00181    colour[1]=(double)GetGValue(cc.rgbResult);
00182    colour[2]=(double)GetBValue(cc.rgbResult);
00183  }
00184 }
00185 
00186 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam);
00187 
00188 #if 0
00189 char * CALLBACK SetExternalParameters(
00190 #else
00191 char * _SetExternalParameters(
00192 #endif
00193   char *Op,                 /* string for the parameters                  */
00194   HWND hWnd,                /* parent window                              */
00195   X__MEMORY_MANAGER *lpEVI /* pointer to structure with memory functions */
00196                              ){
00197  char szbuf[255],*Op1;
00198  if(Op != NULL){  /* parameters exist so read them off the list */
00199    Op1=Op;
00200    Op1++;
00201    sscanf(Op1,"%f %f %f",
00202          &x,&y,&z);
00203  }
00204  if(DialogBox(hDLLinstance,MAKEINTRESOURCE(DLG),hWnd,
00205               (DLGPROC)DlgProc) == FALSE)return Op;
00206  if(Op != NULL)CALL_FREE(Op);  /* free the old string */
00207  sprintf(szbuf,"# %.3f %.3f %.3f",
00208          x,y,z);
00209  if((Op=(char *)CALL_MALLOC(strlen(szbuf)+1)) == NULL){
00210   MessageBox (GetFocus(),"External shader: Out of memory","Error",
00211                 MB_OK|MB_TASKMODAL|MB_ICONSTOP);
00212    return NULL;
00213  }
00214  strcpy(Op,szbuf);
00215  return Op;
00216 }
00217 
00218 BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wparam,LPARAM lparam){
00219  char str[16];
00220  switch( msg ) {
00221    case WM_INITDIALOG:
00222      sprintf(str,"%.2f",x);
00223      SendDlgItemMessage(hwnd,DLG_XSCALE,WM_SETTEXT,0,(LPARAM)str);
00224      SendDlgItemMessage(hwnd,DLG_XSCALE,EM_LIMITTEXT,(WPARAM)12,0);
00225      sprintf(str,"%.2f",y);
00226      SendDlgItemMessage(hwnd,DLG_YSCALE,WM_SETTEXT,0,(LPARAM)str);
00227      SendDlgItemMessage(hwnd,DLG_YSCALE,EM_LIMITTEXT,(WPARAM)12,0);
00228      sprintf(str,"%.2f",z);
00229      SendDlgItemMessage(hwnd,DLG_ZSCALE,WM_SETTEXT,0,(LPARAM)str);
00230      SendDlgItemMessage(hwnd,DLG_ZSCALE,EM_LIMITTEXT,(WPARAM)12,0);
00231      CentreDialogOnScreen(hwnd);
00232      return TRUE;
00233    case WM_COMMAND:
00234      switch(LOWORD(wparam)){
00235         case IDCANCEL:
00236           EndDialog(hwnd,FALSE);
00237           return(TRUE);
00238         case IDOK:
00239           if(GetDlgItemText(hwnd,DLG_XSCALE,str,10) == 0)
00240              EndDialog(hwnd,FALSE);
00241           if((x=atof(str)) == 0)EndDialog(hwnd,FALSE);
00242           if(GetDlgItemText(hwnd,DLG_YSCALE,str,10) == 0)
00243              EndDialog(hwnd,FALSE);
00244           if((y=atof(str)) == 0)EndDialog(hwnd,FALSE);
00245           if(GetDlgItemText(hwnd,DLG_ZSCALE,str,10) == 0)
00246              EndDialog(hwnd,FALSE);
00247           if((z=atof(str)) == 0)EndDialog(hwnd,FALSE);
00248           EndDialog(hwnd,TRUE);
00249           return(TRUE);
00250         default:
00251           break;
00252       }
00253       break;
00254     default: break;
00255  }
00256  return FALSE;
00257 }
Generated on Tue Jan 28 06:18:32 2014 for OpenFX by  doxygen 1.6.3