00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #define _DSTRUCT_MAIN 1
00013
00014 #include "gldesign1.h"
00015 extern void Make3dDisplayList(void);
00016 extern void Make3dDisplayListProg(void);
00017 extern SetMappingQuality(void);
00018 extern GLvoid initialize(HWND);
00019 extern GLvoid drawScene(HWND,BOOL);
00020 extern GLvoid resize(HWND);
00021 extern BOOL bSetupPixelFormat(HDC);
00022 extern void SelectVertexInRectGL(void);
00023 extern void MoveInPerspectiveGL(double dx, double dy);
00024 extern void RotateInPerspectiveGL(double dx, double dy);
00025 extern void ShapeInPerspectiveGL(double dx, double dy);
00026 extern BOOL CheckGPUhardware(HWND hwnd);
00027
00028 void RegisterOpenGL(HINSTANCE);
00029 void UnregisterOpenGL(HINSTANCE);
00030 void BuildMapList(void);
00031 void FreeMapList(void);
00032
00033 static LONG WINAPI OpenGLWndProc(HWND, UINT, WPARAM, LPARAM);
00034 static void LoadPrefs(void);
00035 static PSTR FileInPath(PSTR pstrPath);
00036 static BOOL CALLBACK PrefsDlgProc(HWND hdlg,UINT msg,
00037 WPARAM wparam,LPARAM lparam);
00038 static void GluCommands(WORD, HWND);
00039 unsigned char *MakeImageFromFile(char *temp, long *x, long *y, long type);
00040
00041 extern RECT oldrect;
00042
00043
00044 char IniFilename[256],
00045 IniSection[] = "GLPREFERENCES";
00046 int *Tool;
00047 int SelXs,SelYs,SelXc,SelYc;
00048 GLMAP *glMapList=NULL;
00049 long NglMapList=0;
00050 double *PerspTheta,*PerspFi;
00051 GLfloat up_angle=0.0,round_angle=0.0;
00052 GLfloat gbRed=0.0,gbGreen=0.1,gbBlue=0.3;
00053 GLfloat gwRed=1.0,gwGreen=1.0,gwBlue=1.0;
00054 GLfloat near_plane,far_plane,vertex_scale=4.0,ortho_width=4.0;
00055 GLint listID=0,mode=1,bounding_box=0,current_map=0;
00056 BOOL Mapped=FALSE,Update=TRUE,Fastest=FALSE,Clamped=FALSE,
00057 Cmaterial=TRUE,AttenuateLight=TRUE,TwoSided=TRUE,
00058 ScrollBars=FALSE,bDrawMapping=FALSE,bOverlayWire=FALSE,bOverlayWireHidden=FALSE,bSelectOnlyInView=FALSE,
00059 bThickWire=FALSE,bNurbsWireOnly=FALSE,
00060 bStereo=FALSE,bStereoDraw=FALSE,bShaders=FALSE,
00061 bOrtho=TRUE,bDrawSelection=FALSE;
00062 char gszBMPfile[MAX_FILE],gszBMPdir[MAX_DIR],gszRootDir[MAX_DIR];
00063
00064 BOOL bCanUseShaders=FALSE;
00065
00066 GLuint g_check_texture;
00067 GLuint g_map_texture;
00068 GLuint g_ref_texture;
00069 GLuint g_bump_texture;
00070 GLuint g_tran_texture;
00071 GLuint g_movie_texture;
00072 GLuint g_env_texture;
00073 GLuint g_envB_texture;
00074 GLuint g_noise_texture;
00075 GLubyte checkImage[checkImageWidth][checkImageHeight][3];
00076
00077 static HMENU glMenu=NULL;
00078 static HWND glWnd=NULL,glWndParent;
00079 static HINSTANCE glInstance;
00080 static CHAR szAppName[]="OFX:OpenGL";
00081 static HGLRC hRC;
00082 static HCURSOR hcurSave=NULL;
00083 static DWORD fdwStyle = WS_CHILD | !WS_CAPTION | !WS_SYSMENU |
00084 !WS_MAXIMIZEBOX | !WS_THICKFRAME | WS_BORDER |
00085 WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
00086
00087 static char WIN32_environment[512];
00088
00089 char *G_GetEnv(char const *aa){
00090 if(GetEnvironmentVariable((LPTSTR)aa,(LPTSTR)WIN32_environment,256) == 0)return NULL;
00091 return WIN32_environment;
00092 }
00093
00094 #if __WATCOMC__
00095 int APIENTRY LibMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00096 #else
00097 BOOL WINAPI DllMain(HANDLE hDLL, DWORD dwReason, LPVOID lpReserved){
00098 #endif
00099 switch (dwReason) {
00100 case DLL_PROCESS_ATTACH:
00101 RegisterOpenGL(hDLL);
00102 break;
00103 case DLL_PROCESS_DETACH:
00104 UnregisterOpenGL(hDLL);
00105 break;
00106 }
00107 return TRUE;
00108 }
00109
00110 void UnregisterOpenGL(HINSTANCE hInstance){
00111 if(glWnd != NULL)DestroyWindow(glWnd);
00112 UnregisterClass(szAppName,hInstance);
00113 }
00114
00115 void RegisterOpenGL(HINSTANCE hInstance){
00116 WNDCLASS wc;
00117 wc.style = 0;
00118 wc.lpfnWndProc = (WNDPROC)OpenGLWndProc;
00119 wc.cbClsExtra = 0;
00120 wc.cbWndExtra = 0;
00121 wc.hInstance = hInstance;
00122 wc.hIcon = LoadIcon(hInstance,"GLVIEW_ICON");
00123
00124 wc.hCursor = LoadCursor(hInstance,MAKEINTRESOURCE(IDC_HAND));
00125 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
00126 wc.lpszMenuName = NULL;
00127 wc.lpszClassName = szAppName;
00128 glInstance=hInstance;
00129 if (!RegisterClass (&wc) )return;
00130 return;
00131 }
00132
00133 HWND _AttachViewOpenGL(
00134 HWND parent,
00135 char *tt,
00136 LPRECT pr,
00137 double *lpPerspTheta,
00138 double *lpPerspFi,
00139 int *lpTool,
00140 X__STRUCTURE *lpevi
00141 ){
00142 RECT rc;
00143 HWND hWnd;
00144 lpEVI=lpevi;
00145 glWndParent=parent;
00146 PerspTheta=lpPerspTheta;
00147 PerspFi=lpPerspFi;
00148 Tool=lpTool;
00149 GetModuleFileName(glInstance,gszBMPdir,MAX_DIR);
00150 *FileInPath(gszBMPdir) = '\0';
00151 strcpy(gszRootDir,gszBMPdir);
00152 gszBMPfile[0]='\0'; strcat(gszBMPdir,"maps");
00153
00154
00155 {
00156 FILE *fini=NULL; int ix;
00157 char TempPath[256];
00158 GetModuleFileName(glInstance,IniFilename,256);
00159 *FileInPath(IniFilename) = '\0';
00160 strcpy(TempPath,IniFilename);
00161 strcat(IniFilename,"OPENFX_.CFG");
00162 if((fini=fopen(IniFilename,"r")) != NULL){
00163 fscanf(fini,"%ld",&ix);
00164 strcpy(TempPath,"X");
00165 fscanf(fini," %[^\n]",TempPath);
00166 if(ix > 1){
00167 fscanf(fini," %[^\n]",IniFilename);
00168 }
00169 else *FileInPath(IniFilename) = '\0';
00170 fclose(fini);
00171 }
00172 else {
00173 char *pE;
00174 pE=G_GetEnv("TEMP");
00175 if(pE != NULL){
00176 strcpy(TempPath,pE); strcat(TempPath,"\\");
00177 strcpy(IniFilename,TempPath);
00178 *FileInPath(TempPath) = '\0';
00179 }
00180 *FileInPath(IniFilename) = '\0';
00181 }
00182 strcat(IniFilename,"OPENFX_.INI");
00183 }
00184
00185 hWnd = CreateWindow(szAppName,
00186 "View:OpenGL",
00187 fdwStyle,
00188 pr->left,
00189 pr->top,
00190 pr->right,
00191 pr->bottom,
00192 parent,
00193 NULL,
00194 glInstance,
00195 NULL);
00196 if (!hWnd)return NULL;
00197 SendMessage(hWnd, WM_INIT, 0, 0L);
00198 ShowWindow (hWnd, SW_SHOW);
00199 UpdateWindow(hWnd);
00200 glWnd=hWnd;
00201 InvalidateRect(hWnd, NULL, FALSE);
00202 return hWnd;
00203 }
00204
00205 void _DetachViewOpenGL(void){
00206 if(glWnd != NULL)DestroyWindow(glWnd);
00207 }
00208
00209 static PSTR FileInPath(PSTR pstrPath){
00210 PSTR pstr;
00211 pstr = pstrPath + strlen(pstrPath);
00212 while (pstr > pstrPath) {
00213 pstr = (AnsiPrev(pstrPath, pstr));
00214 if (*pstr == '\\' || *pstr == ':' || *pstr == '/') {
00215 pstr = (AnsiNext(pstr));
00216 break;
00217 }
00218 }
00219 return pstr;
00220 }
00221
00222 static LONG WINAPI OpenGLWndProc(HWND hWnd,UINT uMsg,
00223 WPARAM wParam,LPARAM lParam){
00224 GLfloat old;
00225 int i,iPos,iMax,iMin,dn,zDelta;
00226 LONG lRet = 1;
00227 static BOOL flag=FALSE,mmoved=FALSE,bTrackPan=FALSE,bTrackMove=FALSE;
00228 static long xs,ys;
00229 static long dmx,dmy;
00230 switch (uMsg){
00231 case WM_SETCURSOR:
00232 if(bOrtho){
00233 if(GetKeyState(VK_SPACE)&0x8000)SetCursor(LoadCursor(glInstance,MAKEINTRESOURCE(IDC_HAND)));
00234 else if(LOWORD(lParam) != HTCLIENT)SetCursor(LoadCursor(NULL, IDC_ARROW));
00235 else if(*Tool == SELECTOR)SetCursor(LoadCursor(glInstance,MAKEINTRESOURCE(IDC_SELECT)));
00236 else if(*Tool == DESELECTOR)SetCursor(LoadCursor(glInstance,MAKEINTRESOURCE(IDC_DESELECT)));
00237 else if(*Tool == GRABBER)SetCursor(LoadCursor(glInstance,MAKEINTRESOURCE(IDC_GRAB)));
00238 else if(*Tool == ROTATOR)SetCursor(LoadCursor(glInstance,MAKEINTRESOURCE(IDC_GRAB)));
00239 else if(*Tool == EXPANDER)SetCursor(LoadCursor(glInstance,MAKEINTRESOURCE(IDC_GRAB)));
00240 else if(*Tool == SHAPER)SetCursor(LoadCursor(glInstance,MAKEINTRESOURCE(IDC_GRAB)));
00241 else SetCursor(LoadCursor(glInstance,MAKEINTRESOURCE(IDC_HAND)));
00242 }
00243 else lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
00244 break;
00245 case WM_CREATE:{
00246 INT menu_flags;
00247 HDC hDC;
00248 HMENU hmenu;
00249 char str[128];
00250 hDC = GetDC(hWnd);
00251 LoadPrefs();
00252 bSetupPixelFormat(hDC);
00253 hRC = wglCreateContext( hDC );
00254 wglMakeCurrent( hDC, hRC );
00255 if(CheckGPUhardware(hWnd))bCanUseShaders=TRUE; else bCanUseShaders=FALSE;
00256 gl2Initialize();
00257 glActiveTexture(GL_TEXTURE3);
00258 glEnable(GL_TEXTURE_2D);
00259 glActiveTexture(GL_TEXTURE2);
00260 glEnable(GL_TEXTURE_2D);
00261 glActiveTexture(GL_TEXTURE1);
00262 glEnable(GL_TEXTURE_2D);
00263 glActiveTexture(GL_TEXTURE0);
00264 glEnable(GL_TEXTURE_2D);
00265 glGenTextures( 1, &g_check_texture );
00266 glGenTextures( 1, &g_map_texture );
00267 glGenTextures( 1, &g_bump_texture );
00268 glGenTextures( 1, &g_ref_texture );
00269 glGenTextures( 1, &g_tran_texture );
00270 glGenTextures( 1, &g_movie_texture );
00271 glGenTextures( 1, &g_env_texture );
00272 glGenTextures( 1, &g_envB_texture );
00273 glGenTextures( 1, &g_noise_texture );
00274 up_angle=*PerspTheta;
00275 round_angle=*PerspFi;
00276 if(ScrollBars){
00277 SetScrollRange(hWnd, SB_VERT, -89,89,TRUE);
00278 SetScrollRange(hWnd, SB_HORZ, -179,179,TRUE);
00279 SetScrollPos(hWnd,SB_HORZ,(int)round_angle,TRUE);
00280 SetScrollPos(hWnd,SB_VERT,(int)up_angle,TRUE);
00281 }
00282 else{
00283 SetScrollRange(hWnd, SB_VERT, 0,0,TRUE);
00284 SetScrollRange(hWnd, SB_HORZ, 0,0,TRUE);
00285 SetScrollPos(hWnd,SB_HORZ,0,TRUE);
00286 SetScrollPos(hWnd,SB_VERT,0,TRUE);
00287 }
00288 hmenu=GetMenu(glWndParent);
00289 glMenu=CreatePopupMenu();
00290 LoadString(glInstance,IDS_HINTS,str,127);
00291 AppendMenu(glMenu,MF_ENABLED | MF_STRING,IDM_GLVIEW_MAP,str);
00292 menu_flags=MF_ENABLED | MF_STRING;
00293 if(TwoSided)menu_flags |= MF_CHECKED;
00294 LoadString(glInstance,IDS_SIDES,str,127);
00295 AppendMenu(glMenu,menu_flags,IDM_GLVIEW_TWOSIDE,str);
00296
00297 menu_flags=MF_ENABLED | MF_STRING;
00298 if(bShaders)menu_flags |= MF_CHECKED;
00299 LoadString(glInstance,IDS_SHADERS,str,127);
00300 AppendMenu(glMenu,menu_flags,IDM_GLVIEW_SHADERS,str);
00301
00302 menu_flags=MF_ENABLED | MF_STRING;
00303 if(bOrtho)menu_flags |= MF_CHECKED;
00304 LoadString(glInstance,IDS_ORTHO,str,127);
00305 AppendMenu(glMenu,menu_flags,IDM_GLVIEW_ORTHO,str);
00306
00307 menu_flags=MF_ENABLED | MF_STRING;
00308 if(ScrollBars)menu_flags |= MF_CHECKED;
00309 LoadString(glInstance,IDS_SCROLL,str,127);
00310 AppendMenu(glMenu,menu_flags,IDM_GLVIEW_SCROLLBARS,str);
00311
00312 menu_flags=MF_ENABLED | MF_STRING;
00313 if(bOverlayWire)menu_flags |= MF_CHECKED;
00314 LoadString(glInstance,IDS_OVERLAY,str,127);
00315 AppendMenu(glMenu,menu_flags,IDM_GLVIEW_OVERLAY,str);
00316
00317 menu_flags=MF_ENABLED | MF_STRING;
00318 if(bOverlayWireHidden)menu_flags |= MF_CHECKED;
00319 LoadString(glInstance,IDS_OVERLAY_ALL,str,127);
00320 AppendMenu(glMenu,menu_flags,IDM_GLVIEW_OVERLAY_ALL,str);
00321
00322 menu_flags=MF_ENABLED | MF_STRING;
00323 if(bSelectOnlyInView)menu_flags |= MF_CHECKED;
00324 LoadString(glInstance,IDS_SELECT_ALL,str,127);
00325 AppendMenu(glMenu,menu_flags,IDM_GLVIEW_SELECT_ONLY,str);
00326
00327 menu_flags=MF_ENABLED | MF_STRING;
00328 if(bStereo)menu_flags |= MF_CHECKED;
00329 LoadString(glInstance,IDS_STEREO,str,127);
00330 AppendMenu(glMenu,menu_flags,IDM_GLVIEW_STEREO,str);
00331
00332 LoadString(glInstance,IDS_PREF,str,127);
00333 AppendMenu(glMenu,MF_ENABLED | MF_STRING,IDM_GLVIEW_PREFS,str);
00334 AppendMenu(glMenu,MF_SEPARATOR,0,0);
00335 LoadString(glInstance,IDS_HELP,str,127);
00336 AppendMenu(glMenu,MF_ENABLED | MF_STRING,IDM_GLVIEW_HELP,str);
00337 LoadString(glInstance,IDS_ABOUT,str,127);
00338 AppendMenu(glMenu,MF_ENABLED | MF_STRING,IDM_GLVIEW_ABOUT,str);
00339 LoadString(glInstance,IDS_MENU,str,127);
00340 InsertMenu(hmenu,GLMENU_POSITION,MF_POPUP|MF_BYPOSITION,
00341 (UINT)glMenu,str);
00342 DrawMenuBar(glWndParent);
00343 }
00344 break;
00345 case WM_PAINT:{
00346 HDC hDC;
00347 PAINTSTRUCT ps;
00348 hDC = BeginPaint(hWnd, &ps);
00349 drawScene(hWnd,TRUE);
00350 EndPaint(hWnd, &ps);
00351 }
00352 break;
00353 case WM_LBUTTONDOWN:
00354 if(bOrtho){
00355 if(GetKeyState(VK_SPACE)&0x8000){;}
00356 else if((*Tool == SELECTOR || *Tool == DESELECTOR))bDrawSelection=TRUE;
00357 else if((*Tool == GRABBER))bTrackMove=TRUE;
00358 else if((*Tool == ROTATOR))bTrackMove=TRUE;
00359
00360 }
00361 mmoved=FALSE;
00362 xs=LOWORD(lParam);
00363 ys=HIWORD(lParam);
00364 SelXs=xs; SelYs=ys;
00365 dmx=xs; dmy=ys;
00366 SetCapture(hWnd);
00367 bTrackPan=TRUE;
00368 break;
00369 case WM_MOUSEMOVE:
00370 if(bTrackPan){
00371 long dx,dy;
00372 dx=(short)LOWORD(lParam)-xs; xs=(short)LOWORD(lParam);
00373 dy=(short)HIWORD(lParam)-ys; ys=(short)HIWORD(lParam);
00374 if(bDrawSelection){
00375 mmoved=TRUE;
00376 SelXc=xs; SelYc=ys;
00377 if(mode > 0)InvalidateRect(hWnd, NULL, FALSE);
00378 }
00379 else if(bTrackMove){
00380
00381 }
00382 else {
00383 if(labs(dx) > 0 || labs(dy) > 0){
00384 mmoved=TRUE;
00385 round_angle=round_angle+(double)dx;
00386 while(round_angle < -180.0)round_angle += 360.0;
00387 while(round_angle > 180.0)round_angle -= 360.0;
00388 *PerspFi = (double)round_angle;
00389 SetScrollPos(hWnd,SB_HORZ,(int)round_angle,TRUE);
00390 up_angle=up_angle+(double)dy;
00391 *PerspTheta = (double)up_angle;
00392 if(up_angle > -90 && up_angle < 90)
00393 SetScrollPos(hWnd,SB_VERT,(int)up_angle,TRUE);
00394 if(mode > 0)InvalidateRect(hWnd, NULL, FALSE);
00395 else drawScene(hWnd,FALSE);
00396 }
00397 }
00398 }
00399 break;
00400 case WM_RBUTTONDOWN:{
00401 POINT pt;
00402 HMENU hMenu=LoadMenu(glInstance,"GLViewPopupMenu");
00403 if(hMenu == NULL)break;
00404 pt.x=LOWORD(lParam);
00405 pt.y=HIWORD(lParam);
00406 ClientToScreen(hWnd,&pt);
00407 if(TwoSided)CheckMenuItem(hMenu,IDM_GLVIEW_TWOSIDE,MF_CHECKED);
00408 else CheckMenuItem(hMenu,IDM_GLVIEW_TWOSIDE,MF_UNCHECKED);
00409 if(bOverlayWire)CheckMenuItem(hMenu,IDM_GLVIEW_OVERLAY,MF_CHECKED);
00410 else CheckMenuItem(hMenu,IDM_GLVIEW_OVERLAY,MF_UNCHECKED);
00411 if(bStereo)CheckMenuItem(hMenu,IDM_GLVIEW_STEREO,MF_CHECKED);
00412 else CheckMenuItem(hMenu,IDM_GLVIEW_STEREO,MF_UNCHECKED);
00413 if(Mapped)CheckMenuItem(hMenu,IDM_QUICKMAPCHANGE,MF_CHECKED);
00414 else CheckMenuItem(hMenu,IDM_QUICKMAPCHANGE,MF_UNCHECKED);
00415 if(bShaders)CheckMenuItem(hMenu,IDM_GLVIEW_SHADERS,MF_CHECKED);
00416 else CheckMenuItem(hMenu,IDM_GLVIEW_SHADERS,MF_UNCHECKED);
00417 if(bOrtho)CheckMenuItem(hMenu,IDM_GLVIEW_ORTHO,MF_CHECKED);
00418 else CheckMenuItem(hMenu,IDM_GLVIEW_ORTHO,MF_UNCHECKED);
00419 if(bOverlayWireHidden)CheckMenuItem(hMenu,IDM_GLVIEW_OVERLAY_ALL,MF_CHECKED);
00420 else CheckMenuItem(hMenu,IDM_GLVIEW_OVERLAY_ALL,MF_UNCHECKED);
00421 if(bSelectOnlyInView)CheckMenuItem(hMenu,IDM_GLVIEW_SELECT_ONLY,MF_CHECKED);
00422 else CheckMenuItem(hMenu,IDM_GLVIEW_SELECT_ONLY,MF_UNCHECKED);
00423 TrackPopupMenu(GetSubMenu(hMenu,0),TPM_LEFTALIGN | TPM_LEFTBUTTON,
00424 pt.x,pt.y,0,hWnd,NULL);
00425 DestroyMenu(hMenu);
00426 }
00427 break;
00428 case WM_LOAD_MAPS:
00429 SendMessage(hWnd,WM_COMMAND,IDM_GLVIEW_MAP,0);
00430 break;
00431 case WM_SHOWMAP:
00432 bDrawMapping=(BOOL)wParam;
00433 current_map=(GLint)lParam;
00434 InvalidateRect(hWnd, NULL, FALSE);
00435 break;
00436 case WM_UPDATE_MAP:
00437 if(!Mapped)break;
00438 if(!Update)break;
00439 case WM_UPDATE:
00440 if(!bCanUseShaders)Make3dDisplayList();
00441 else if(!bShaders)Make3dDisplayList();
00442 else Make3dDisplayListProg();
00443 InvalidateRect(hWnd, NULL, FALSE);
00444 break;
00445 case WM_LBUTTONUP:
00446 if(bDrawSelection){
00447 SelectVertexInRectGL();
00448 bDrawSelection=FALSE;
00449 }
00450 if(bTrackMove){
00451 xs=LOWORD(lParam);
00452 ys=HIWORD(lParam);
00453 if(*Tool == GRABBER)MoveInPerspectiveGL((double)(xs-dmx),(double)(ys-dmy));
00454 if(*Tool == ROTATOR)RotateInPerspectiveGL((double)(xs-dmx),(double)(ys-dmy));
00455
00456 PostMessage(hWnd,WM_UPDATE,0,0);
00457 mmoved=FALSE;
00458 bTrackMove=FALSE;
00459 }
00460 if(bTrackPan){
00461 ReleaseCapture();
00462 bTrackPan=FALSE;
00463 }
00464 if(mmoved){
00465 mmoved=FALSE;
00466 InvalidateRect(hWnd, NULL, FALSE);
00467 break;
00468 }
00469 mmoved=FALSE;
00470 break;
00471 case WM_INIT:
00472 initialize(hWnd);
00473 break;
00474 case WM_SIZE:
00475 resize(hWnd);
00476 lRet=0;
00477 break;
00478 case WM_VSCROLL:
00479 GetScrollRange(hWnd, SB_VERT, &iMin, &iMax);
00480 iPos = GetScrollPos(hWnd, SB_VERT);
00481 switch (LOWORD(wParam)) {
00482 case SB_ENDSCROLL:
00483 dn=0;
00484 if(mode == 0 || flag)InvalidateRect(hWnd, NULL, FALSE);
00485 flag=FALSE;
00486 break;
00487 case SB_LINEDOWN: dn = 1; break;
00488 case SB_LINEUP: dn = -1; break;
00489 case SB_PAGEDOWN: dn = 5; break;
00490 case SB_PAGEUP: dn = -5; break;
00491 case SB_THUMBTRACK:
00492 case SB_THUMBPOSITION: dn = (int)(short)HIWORD(wParam)-iPos; break;
00493 default: dn = 0;
00494 }
00495 if ((dn = BOUND (iPos + dn, iMin, iMax) - iPos) != 0) {
00496 SetScrollPos(hWnd, SB_VERT, iPos + dn, TRUE);
00497 old=up_angle;
00498 up_angle=(GLfloat)(iPos+dn);
00499 *PerspTheta = (double)up_angle;
00500 if(old != up_angle){
00501 if(mode > 0){
00502 if(!flag && (GetKeyState(VK_CONTROL) & 0x8000))flag=TRUE;
00503 if(!flag)InvalidateRect(hWnd, NULL, FALSE);
00504 }
00505 else drawScene(hWnd,FALSE);
00506 }
00507 }
00508 break;
00509 case WM_MOUSEWHEEL:
00510 return 0;
00511 case WM_HSCROLL:
00512 GetScrollRange(hWnd, SB_HORZ, &iMin, &iMax);
00513 iPos = GetScrollPos(hWnd, SB_HORZ);
00514 switch (LOWORD(wParam)) {
00515 case SB_ENDSCROLL:
00516 if(mode == 0 || flag)InvalidateRect(hWnd, NULL, FALSE);
00517 flag=FALSE;
00518 dn=0;
00519 break;
00520 case SB_LINEDOWN: dn = 1; break;
00521 case SB_LINEUP: dn = -1; break;
00522 case SB_PAGEDOWN: dn = 5; break;
00523 case SB_PAGEUP: dn = -5; break;
00524 case SB_THUMBTRACK:
00525 case SB_THUMBPOSITION: dn = (int)(short)HIWORD(wParam) - iPos; break;
00526 default: dn = 0;
00527 }
00528 if ((dn = BOUND (iPos + dn, iMin, iMax) - iPos) != 0) {
00529 SetScrollPos(hWnd, SB_HORZ, iPos + dn, TRUE);
00530 old=round_angle;
00531 round_angle=(GLfloat)(iPos+dn);
00532 *PerspFi = (double)round_angle;
00533 if(old != round_angle){
00534 if(mode > 0){
00535 if(!flag && (GetKeyState(VK_CONTROL) & 0x8000))flag=TRUE;
00536 if(!flag)InvalidateRect(hWnd, NULL, FALSE);
00537 }
00538 else drawScene(hWnd,FALSE);
00539 }
00540 }
00541 break;
00542 case WM_COMMAND:
00543 GluCommands(LOWORD(wParam),hWnd);
00544 break;
00545 case WM_CLOSE:
00546 PostMessage(glWndParent,WM_COMMAND,IDM_WINDOW_SHOWOPENGL,0);
00547 break;
00548 case WM_DESTROY:{
00549 RECT rc;
00550 POINT pt1,pt2;
00551 char *w, yesyes[]="YES", nono[]="NO",str[64];
00552 HGLRC hRC;
00553 HDC hDC;
00554 FreeMapList();
00555 glDisable(GL_TEXTURE_2D);
00556 glActiveTexture(GL_TEXTURE1);
00557 glDisable(GL_TEXTURE_2D);
00558 glActiveTexture(GL_TEXTURE2);
00559 glDisable(GL_TEXTURE_2D);
00560 glActiveTexture(GL_TEXTURE3);
00561 glDisable(GL_TEXTURE_2D);
00562 glDeleteTextures( 1, &g_check_texture );
00563 glDeleteTextures( 1, &g_map_texture );
00564 glDeleteTextures( 1, &g_bump_texture );
00565 glDeleteTextures( 1, &g_movie_texture );
00566 glDeleteTextures( 1, &g_env_texture );
00567 glDeleteTextures( 1, &g_envB_texture );
00568 glDeleteTextures( 1, &g_ref_texture );
00569 glDeleteTextures( 1, &g_tran_texture );
00570 glDeleteTextures( 1, &g_noise_texture );
00571 if(bCanUseShaders)UnloadShaders();
00572 hRC = wglGetCurrentContext();
00573 hDC = wglGetCurrentDC();
00574 wglMakeCurrent(NULL, NULL);
00575 if(hRC != NULL)wglDeleteContext(hRC);
00576 if(hDC != NULL)ReleaseDC(hWnd, hDC);
00577 glWnd=NULL;
00578 if(TwoSided)w=yesyes; else w=nono;
00579 WritePrivateProfileString(IniSection,"TWOSIDED",w,IniFilename);
00580 if(ScrollBars)w=yesyes; else w=nono;
00581 WritePrivateProfileString(IniSection,"SCROLLBARS",w,IniFilename);
00582 if(bOverlayWire)w=yesyes; else w=nono;
00583 WritePrivateProfileString(IniSection,"OVERLAY",w,IniFilename);
00584 if(bOverlayWireHidden)w=yesyes; else w=nono;
00585 WritePrivateProfileString(IniSection,"OVERLAYALL",w,IniFilename);
00586 if(bSelectOnlyInView)w=yesyes; else w=nono;
00587 WritePrivateProfileString(IniSection,"SELECTONLYINVIEW",w,IniFilename);
00588 if(bStereo)w=yesyes; else w=nono;
00589 WritePrivateProfileString(IniSection,"STEREO",w,IniFilename);
00590 if(bShaders)w=yesyes; else w=nono;
00591 WritePrivateProfileString(IniSection,"SHADERS",w,IniFilename);
00592 if(bOrtho)w=yesyes; else w=nono;
00593 WritePrivateProfileString(IniSection,"ORTHO",w,IniFilename);
00594 RemoveMenu(GetMenu(glWndParent),GLMENU_POSITION,MF_BYPOSITION);
00595 if(glMenu != NULL)DestroyMenu(glMenu);
00596 DrawMenuBar(glWndParent);
00597 glMenu=NULL;
00598 }
00599 break;
00600 default:
00601 lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
00602 break;
00603 }
00604 return lRet;
00605 }
00606
00607 static void GluCommands(WORD cmd,HWND hWnd){
00608 char HelpText[]="Click in Window to Prepare Updated View\n"
00609 "Drag Scroll Bars to Move Viewpoint\n\n"
00610 "Hold Ctrl while dragging scrollbar\n"
00611 "to prevent intermediate updates";
00612 switch (cmd){
00613 case IDM_GLVIEW_PREFS:
00614 DialogBox(glInstance,MAKEINTRESOURCE(DLG_PREFS),hWnd,
00615 (DLGPROC)PrefsDlgProc);
00616 if(Mapped && glMapList == NULL)BuildMapList();
00617 PostMessage(glWnd,WM_UPDATE,0,0);
00618 break;
00619 case IDM_QUICKMAPCHANGE:
00620 Mapped ^=1;
00621 case IDM_GLVIEW_MAP:
00622 BuildMapList();
00623 PostMessage(glWnd,WM_UPDATE,0,0);
00624 break;
00625 case IDM_GLVIEW_HELP:
00626 MessageBox(hWnd,HelpText,"Help",MB_OK);
00627 break;
00628 case IDM_GLVIEW_ABOUT:
00629 MessageBox(hWnd,ABOUT_VERSION,"About Designer OpenGL Viewer",MB_OK);
00630 break;
00631 case IDM_GLVIEW_SCROLLBARS:
00632 ScrollBars ^= 1;
00633 if(ScrollBars){
00634 SetScrollRange(hWnd, SB_VERT, -89,89,TRUE);
00635 SetScrollRange(hWnd, SB_HORZ, -179,179,TRUE);
00636 SetScrollPos(hWnd,SB_HORZ,(int)round_angle,TRUE);
00637 SetScrollPos(hWnd,SB_VERT,(int)up_angle,TRUE);
00638 }
00639 else{
00640 SetScrollRange(hWnd, SB_VERT, 0,0,TRUE);
00641 SetScrollRange(hWnd, SB_HORZ, 0,0,TRUE);
00642 SetScrollPos(hWnd,SB_HORZ,0,TRUE);
00643 SetScrollPos(hWnd,SB_VERT,0,TRUE);
00644 }
00645 if(ScrollBars)CheckMenuItem(glMenu,IDM_GLVIEW_SCROLLBARS,MF_CHECKED);
00646 else CheckMenuItem(glMenu,IDM_GLVIEW_SCROLLBARS,MF_UNCHECKED);
00647 break;
00648 case IDM_GLVIEW_OVERLAY:
00649 bOverlayWire ^= 1;
00650 if(bOverlayWire)CheckMenuItem(glMenu,IDM_GLVIEW_OVERLAY,MF_CHECKED);
00651 else CheckMenuItem(glMenu,IDM_GLVIEW_OVERLAY,MF_UNCHECKED);
00652 PostMessage(glWnd,WM_UPDATE,0,0);
00653 break;
00654 case IDM_GLVIEW_OVERLAY_ALL:
00655 bOverlayWireHidden ^= 1;
00656 if(bOverlayWireHidden)CheckMenuItem(glMenu,IDM_GLVIEW_OVERLAY_ALL,MF_CHECKED);
00657 else CheckMenuItem(glMenu,IDM_GLVIEW_OVERLAY_ALL,MF_UNCHECKED);
00658 PostMessage(glWnd,WM_UPDATE,0,0);
00659 break;
00660 case IDM_GLVIEW_SELECT_ONLY:
00661 bSelectOnlyInView ^= 1;
00662 if(bSelectOnlyInView)CheckMenuItem(glMenu,IDM_GLVIEW_SELECT_ONLY,MF_CHECKED);
00663 else CheckMenuItem(glMenu,IDM_GLVIEW_SELECT_ONLY,MF_UNCHECKED);
00664 PostMessage(glWnd,WM_UPDATE,0,0);
00665 break;
00666 case IDM_GLVIEW_STEREO:
00667 bStereo ^= 1;
00668 if(bStereo)CheckMenuItem(glMenu,IDM_GLVIEW_STEREO,MF_CHECKED);
00669 else CheckMenuItem(glMenu,IDM_GLVIEW_STEREO,MF_UNCHECKED);
00670 PostMessage(glWndParent,(WM_USER+1),0,0);
00671 break;
00672 case IDM_GLVIEW_SHADERS:
00673 bShaders ^= 1;
00674 if(bShaders)CheckMenuItem(glMenu,IDM_GLVIEW_SHADERS,MF_CHECKED);
00675 else CheckMenuItem(glMenu,IDM_GLVIEW_SHADERS,MF_UNCHECKED);
00676 PostMessage(glWndParent,(WM_USER+1),0,0);
00677 break;
00678 case IDM_GLVIEW_ORTHO:
00679 bOrtho ^= 1;
00680 if(bOrtho)CheckMenuItem(glMenu,IDM_GLVIEW_ORTHO,MF_CHECKED);
00681 else CheckMenuItem(glMenu,IDM_GLVIEW_ORTHO,MF_UNCHECKED);
00682 PostMessage(glWndParent,(WM_USER+1),0,0);
00683 break;
00684 case IDM_GLVIEW_TWOSIDE:
00685 TwoSided ^= 1;
00686 if(TwoSided)glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);
00687 else glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_FALSE);
00688 if(TwoSided)CheckMenuItem(glMenu,IDM_GLVIEW_TWOSIDE,MF_CHECKED);
00689 else CheckMenuItem(glMenu,IDM_GLVIEW_TWOSIDE,MF_UNCHECKED);
00690 PostMessage(glWnd,WM_UPDATE,0,0);
00691 break;
00692 case IDM_GLVIEW_SHOWOPENGL:
00693 PostMessage(hWnd,WM_CLOSE,0,0);
00694 break;
00695 default:
00696 break;
00697 }
00698 }
00699
00701
00702 #define ALIGNULONG(i) ((i+3)/4*4)
00703
00704 static char *short_form(char *filename){
00705 char *sps,*spc;
00706 sps=spc=filename;
00707 while((spc=strchr(spc,'\\')) != NULL){spc++; sps=spc;}
00708 return sps;
00709 }
00710
00711 static void CheckMapPath(char *fn){
00712 long l;
00713 char *fs;
00714 FILE *Bit_File=NULL;
00715 char pref[32],preff[32],temp_name[255];
00716 if((Bit_File=fopen((char *)fn,"rb")) != NULL){
00717 fclose(Bit_File);
00718 return;
00719 }
00720 fs=short_form(fn);
00721 strcpy(preff,"MAP-PATH");
00722 for(l=1;l<=128;l++){
00723 sprintf(pref,"%s%ld",preff,l);
00724 GetPrivateProfileString("RPREFERENCES",pref,"$$$",
00725 temp_name,255,IniFilename);
00726 if(strncmp(temp_name,"$$$",3) == 0)break;
00727 if(temp_name[1] != ':')continue;
00728 if(temp_name[strlen(temp_name)-1] != '\\')strcat(temp_name,"\\");
00729 strcat(temp_name,fs);
00730 if((Bit_File=fopen((char *)temp_name,"rb")) != NULL){
00731 fclose(Bit_File);
00732 strcpy(fn,temp_name);
00733 return;
00734 }
00735 }
00736 }
00737
00738 unsigned char *LoadMAP(char *InFile, long *xx,long *yy){
00739
00740
00741 int ff;
00742 char CurrentFile[255];
00743 strcpy(CurrentFile,InFile);
00744 CheckMapPath(CurrentFile);
00745 if (strstr(CurrentFile,".GIF") || strstr(CurrentFile,".gif"))
00746 return MakeImageFromFile(CurrentFile,xx,yy,3);
00747 else if(strstr(CurrentFile,".TGA") || strstr(CurrentFile,".tga"))
00748 return MakeImageFromFile(CurrentFile,xx,yy,5);
00749 else if(strstr(CurrentFile,".JPG") || strstr(CurrentFile,".jpg"))
00750 return MakeImageFromFile(CurrentFile,xx,yy,0);
00751 else if(strstr(CurrentFile,".TIF") || strstr(CurrentFile,".tif"))
00752 return MakeImageFromFile(CurrentFile,xx,yy,1);
00753 else if(strstr(CurrentFile,".PNG") || strstr(CurrentFile,".png"))
00754 return MakeImageFromFile(CurrentFile,xx,yy,2);
00755 else if(strstr(CurrentFile,".BMP") || strstr(CurrentFile,".bmp"))
00756 return MakeImageFromFile(CurrentFile,xx,yy,4);
00757 return NULL;
00758 }
00759
00760 void BuildMapList(void){
00761 long i,x,y;
00762 unsigned char *p;
00763 FreeMapList();
00764 if(!Mapped || nImaps == 0)return;
00765 if((glMapList=(GLMAP *)X__Malloc(nImaps*sizeof(GLMAP))) == NULL)return;
00766 NglMapList=nImaps;
00767 StartWait();
00768 for(i=0;i<nImaps;i++){
00769 glMapList[i].pixels=NULL;
00770 glMapList[i].bMovie=FALSE;
00771 if(iMap[i].S != NULL){
00772 if(iMap[i].si.in_use && iMap[i].si.thumb != NULL){
00773 x=iMap[i].si.thumbx; y=iMap[i].si.thumby;
00774 if((p=(unsigned char *)X__Malloc(x*y*3)) != NULL){
00775
00776 memcpy(p,iMap[i].si.thumb,x*y*3);
00777 glMapList[i].pixels=p;
00778 glMapList[i].x=x;
00779 glMapList[i].y=y;
00780 }
00781 }
00782 else if(iMap[i].Type == ANIMBRUSH)glMapList[i].bMovie=TRUE;
00783 else if((p=LoadMAP(iMap[i].S,&x,&y)) != NULL){
00784 glMapList[i].pixels=p;
00785 glMapList[i].x=x;
00786 glMapList[i].y=y;
00787 }
00788 }
00789 glMapList[i].pixelsR=NULL;
00790 glMapList[i].bMovieR=FALSE;
00791 if(iMap[i].R != NULL){
00792 if(iMap[i].ri.in_use && iMap[i].ri.thumb != NULL){
00793 x=iMap[i].ri.thumbx; y=iMap[i].ri.thumby;
00794 if((p=(unsigned char *)X__Malloc(x*y*3)) != NULL){
00795
00796 memcpy(p,iMap[i].ri.thumb,x*y*3);
00797 glMapList[i].pixelsR=p;
00798 glMapList[i].xR=x;
00799 glMapList[i].yR=y;
00800 }
00801 }
00802 else if(iMap[i].TypeR == ANIMBRUSH)glMapList[i].bMovieR=TRUE;
00803 else if((p=LoadMAP(iMap[i].R,&x,&y)) != NULL){
00804 glMapList[i].pixelsR=p;
00805 glMapList[i].xR=x;
00806 glMapList[i].yR=y;
00807 }
00808 }
00809
00810 glMapList[i].pixelsB=NULL;
00811 glMapList[i].bMovieB=FALSE;
00812 if(iMap[i].B != NULL){
00813 if(iMap[i].bi.in_use && iMap[i].bi.thumb != NULL){
00814 x=iMap[i].bi.thumbx; y=iMap[i].bi.thumby;
00815 if((p=(unsigned char *)X__Malloc(x*y*3)) != NULL){
00816
00817 memcpy(p,iMap[i].bi.thumb,x*y*3);
00818 glMapList[i].pixelsB=p;
00819 glMapList[i].xB=x;
00820 glMapList[i].yB=y;
00821 }
00822 }
00823 else if(iMap[i].TypeB == ANIMBRUSH)glMapList[i].bMovieB=TRUE;
00824 else if((p=LoadMAP(iMap[i].B,&x,&y)) != NULL){
00825
00826 glMapList[i].pixelsB=p;
00827 glMapList[i].xB=x;
00828 glMapList[i].yB=y;
00829 }
00830 }
00831
00832 glMapList[i].pixelsT=NULL;
00833 glMapList[i].bMovieT=FALSE;
00834 if(iMap[i].T != NULL){
00835 if(iMap[i].ti.in_use && iMap[i].ti.thumb != NULL){
00836 x=iMap[i].ti.thumbx; y=iMap[i].ti.thumby;
00837 if((p=(unsigned char *)X__Malloc(x*y*3)) != NULL){
00838
00839 memcpy(p,iMap[i].ti.thumb,x*y*3);
00840 glMapList[i].pixelsT=p;
00841 glMapList[i].xT=x;
00842 glMapList[i].yT=y;
00843 }
00844 }
00845 else if(iMap[i].TypeT == ANIMBRUSH)glMapList[i].bMovieT=TRUE;
00846 else if((p=LoadMAP(iMap[i].T,&x,&y)) != NULL){
00847
00848 glMapList[i].pixelsT=p;
00849 glMapList[i].xT=x;
00850 glMapList[i].yT=y;
00851 }
00852 }
00853
00854 }
00855 SetMappingQuality();
00856 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
00857 EndWait();
00858 return;
00859 }
00860
00861 void FreeMapList(void){
00862 long i;
00863 if(NglMapList == 0 || glMapList == NULL)return;
00864 for(i=0;i<NglMapList;i++){
00865 if(glMapList[i].pixels != NULL)X__Free(glMapList[i].pixels);
00866 if(glMapList[i].pixelsR != NULL)X__Free(glMapList[i].pixelsR);
00867 if(glMapList[i].pixelsB != NULL)X__Free(glMapList[i].pixelsB);
00868 if(glMapList[i].pixelsT != NULL)X__Free(glMapList[i].pixelsT);
00869 }
00870 X__Free(glMapList);
00871 glMapList=NULL;
00872 NglMapList=0;
00873 return;
00874 }
00875
00876
00877 static unsigned char *MakeImageFromFile(char *JPGfile, long *xx, long *yy, long type){
00878 int x_size,y_size;
00879 unsigned char *p,*px,*R,*G,*B,*r,*g,*b;
00880 long i,j,imagesize,xi,yi;
00881 long x,y;
00882 FILE *t24;
00883 char lname[256];
00884 HMODULE hLib;
00885 FARPROC fpFun;
00886 BOOL (*fpGetMapSize)(char *, long *, long *);
00887 BOOL (*fpGetMap)(char *, long, long,
00888 unsigned char *, unsigned char *, unsigned char *);
00889 GetModuleFileName(glInstance,lname,255);
00890 *FileInPath(lname) = '\0';
00891 if (type == 0)strcat(lname,"jpg_map.dll");
00892 else if(type == 1)strcat(lname,"tif_map.dll");
00893 else if(type == 2)strcat(lname,"png_map.dll");
00894 else if(type == 3)strcat(lname,"gif_map.dll");
00895 else if(type == 4)strcat(lname,"bmp_map.dll");
00896 else if(type == 5)strcat(lname,"tga_map.dll");
00897 else return NULL;
00898 R=G=B=NULL;
00899 hLib=LoadLibrary(lname);
00900 if(hLib != NULL){
00901 if((fpFun=GetProcAddress(hLib,"_GetExternalImageSize")) != NULL){
00902 fpGetMapSize = (void *)fpFun;
00903 if((*fpGetMapSize)(JPGfile,&x,&y)){
00904 if((R = (unsigned char *)X__Malloc(x*y)) == NULL)goto CLOSEOUT;
00905 if((G = (unsigned char *)X__Malloc(x*y)) == NULL)goto CLOSEOUT;
00906 if((B = (unsigned char *)X__Malloc(x*y)) == NULL)goto CLOSEOUT;
00907 if((fpFun=GetProcAddress(hLib,"_GetExternalImage")) != NULL){
00908 fpGetMap = (void *)fpFun;
00909 if(!(*fpGetMap)(JPGfile,x,y,R,G,B))goto CLOSEOUT;
00910 }
00911 else goto CLOSEOUT;
00912 }
00913 else goto CLOSEOUT;
00914 }
00915 else goto CLOSEOUT;
00916 FreeLibrary(hLib);
00917 }
00918 else return NULL;
00919
00920 x_size=(int)ALIGNULONG(x);
00921 y_size = y;
00922 imagesize=x_size*y_size*3;
00923 if((p=(unsigned char *)X__Malloc(imagesize+3)) == NULL){
00924 X__Free(R);
00925 X__Free(G);
00926 X__Free(B);
00927 return NULL;
00928 }
00929 for(j=0;j<y;j++){
00930 px=(p+(y-j-1)*x_size*3);
00931 r=(R+j*x); g=(G+j*x); b=(B+j*x);
00932 for(i=0;i<x;i++){
00933 *px++ = *r++;
00934 *px++ = *g++;
00935 *px++ = *b++;
00936 }
00937 }
00938 X__Free(R);
00939 X__Free(G);
00940 X__Free(B);
00941 if (x_size < 128)xi=32; else xi=64;
00942 if (y_size < 128)yi=32; else yi=64;
00943 if((px=(unsigned char *)X__Malloc(xi*yi*3+3)) == NULL){
00944 X__Free((char *)p);
00945 return NULL;
00946 }
00947 gluScaleImage(GL_RGB,x_size,y_size,GL_UNSIGNED_BYTE,
00948 p,xi,yi,GL_UNSIGNED_BYTE,px);
00949 X__Free((char *)p);
00950 *xx = xi;
00951 *yy = yi;
00952 return px;
00953 CLOSEOUT:
00954 if(R != NULL)X__Free(R);
00955 if(G != NULL)X__Free(G);
00956 if(B != NULL)X__Free(B);
00957 FreeLibrary(hLib);
00958 return NULL;
00959 }
00960
00962
00963 static void LoadPrefs(void){
00964 double R,G,B;
00965 char pref_id[64];
00966 GetPrivateProfileString(IniSection,"WIRE","$$$",
00967 pref_id,sizeof(pref_id),IniFilename);
00968 if(strncmp(pref_id,"YES",3) == 0)mode=0;
00969 if(strncmp(pref_id,"NO",2) == 0)mode=1;
00970 GetPrivateProfileString(IniSection,"WIREB","$$$",
00971 pref_id,sizeof(pref_id),IniFilename);
00972 if(strncmp(pref_id,"YES",3) == 0)bounding_box=1;
00973 if(strncmp(pref_id,"NO",2) == 0)bounding_box=0;
00974 GetPrivateProfileString(IniSection,"COLOUR","$$$",
00975 pref_id,sizeof(pref_id),IniFilename);
00976 if(strncmp(pref_id,"$$$",3) != 0){
00977 sscanf(pref_id,"%lf %lf %lf",&R,&G,&B);
00978 gbRed=(GLfloat)R; gbGreen=(GLfloat)G; gbBlue=(GLfloat)B;
00979 }
00980 GetPrivateProfileString(IniSection,"MAPPED","$$$",
00981 pref_id,sizeof(pref_id),IniFilename);
00982 if(strncmp(pref_id,"YES",3) == 0)Mapped=TRUE;
00983 if(strncmp(pref_id,"NO",2) == 0)Mapped=FALSE;
00984 GetPrivateProfileString(IniSection,"UPDATE","$$$",
00985 pref_id,sizeof(pref_id),IniFilename);
00986 if(strncmp(pref_id,"YES",3) == 0)Update=TRUE;
00987 if(strncmp(pref_id,"NO",2) == 0)Update=FALSE;
00988 GetPrivateProfileString(IniSection,"FASTEST","$$$",
00989 pref_id,sizeof(pref_id),IniFilename);
00990 if(strncmp(pref_id,"YES",3) == 0)Fastest=TRUE;
00991 if(strncmp(pref_id,"NO",2) == 0)Fastest=FALSE;
00992 GetPrivateProfileString(IniSection,"CLAMPED","$$$",
00993 pref_id,sizeof(pref_id),IniFilename);
00994 if(strncmp(pref_id,"YES",3) == 0)Clamped=TRUE;
00995 if(strncmp(pref_id,"NO",2) == 0)Clamped=FALSE;
00996 GetPrivateProfileString(IniSection,"DEPTHCUE","$$$",
00997 pref_id,sizeof(pref_id),IniFilename);
00998 if(strncmp(pref_id,"YES",3) == 0)AttenuateLight=TRUE;
00999 if(strncmp(pref_id,"NO",2) == 0)AttenuateLight=FALSE;
01000 GetPrivateProfileString(IniSection,"TWOSIDED","$$$",
01001 pref_id,sizeof(pref_id),IniFilename);
01002 if(strncmp(pref_id,"YES",3) == 0)TwoSided=TRUE;
01003 if(strncmp(pref_id,"NO",2) == 0)TwoSided=FALSE;
01004 GetPrivateProfileString(IniSection,"SCROLLBARS","$$$",
01005 pref_id,sizeof(pref_id),IniFilename);
01006 if(strncmp(pref_id,"YES",3) == 0)ScrollBars=TRUE;
01007 if(strncmp(pref_id,"NO",2) == 0)ScrollBars=FALSE;
01008 GetPrivateProfileString(IniSection,"OVERLAY","$$$",
01009 pref_id,sizeof(pref_id),IniFilename);
01010 if(strncmp(pref_id,"YES",3) == 0)bOverlayWire=TRUE;
01011 if(strncmp(pref_id,"NO",2) == 0)bOverlayWire=FALSE;
01012 GetPrivateProfileString(IniSection,"STEREO","$$$",
01013 pref_id,sizeof(pref_id),IniFilename);
01014 if(strncmp(pref_id,"YES",3) == 0)bStereo=TRUE;
01015 if(strncmp(pref_id,"NO",2) == 0)bStereo=FALSE;
01016 GetPrivateProfileString(IniSection,"SHADERS","$$$",
01017 pref_id,sizeof(pref_id),IniFilename);
01018 if(strncmp(pref_id,"YES",3) == 0)bShaders=TRUE;
01019 if(strncmp(pref_id,"NO",2) == 0)bShaders=FALSE;
01020 GetPrivateProfileString(IniSection,"ORTHO","$$$",
01021 pref_id,sizeof(pref_id),IniFilename);
01022 if(strncmp(pref_id,"YES",3) == 0)bOrtho=TRUE;
01023 if(strncmp(pref_id,"NO",2) == 0)bOrtho=FALSE;
01024 GetPrivateProfileString(IniSection,"NURBSWIREONLY","$$$",
01025 pref_id,sizeof(pref_id),IniFilename);
01026 if(strncmp(pref_id,"YES",3) == 0)bNurbsWireOnly=TRUE;
01027 if(strncmp(pref_id,"NO",2) == 0)bNurbsWireOnly=FALSE;
01028 GetPrivateProfileString(IniSection,"OVERLAYALL","$$$",
01029 pref_id,sizeof(pref_id),IniFilename);
01030 if(strncmp(pref_id,"YES",3) == 0)bOverlayWireHidden=TRUE;
01031 if(strncmp(pref_id,"NO",2) == 0)bOverlayWireHidden=FALSE;
01032 GetPrivateProfileString(IniSection,"SELECTONLYINVIEW","$$$",
01033 pref_id,sizeof(pref_id),IniFilename);
01034 if(strncmp(pref_id,"YES",3) == 0)bSelectOnlyInView=TRUE;
01035 if(strncmp(pref_id,"NO",2) == 0)bSelectOnlyInView=FALSE;
01036 return;
01037 }
01038
01039 static BOOL CALLBACK PrefsDlgProc(HWND hdlg,UINT msg,
01040 WPARAM wparam,LPARAM lparam){
01041 BOOL state;
01042 static double R,G,B;
01043 char *w, yesyes[]="YES", nono[]="NO",str[64];
01044 unsigned char uColour[3];
01045 switch( msg ) {
01046 case WM_INITDIALOG:
01047 CentreDlgOnC(hdlg);
01048 if(mode == 0)state=TRUE; else state=FALSE;
01049 SendDlgItemMessage(hdlg,DLG_PREFS_WIRE,BM_SETCHECK,state,0);
01050 if(bounding_box == 1)state=TRUE; else state=FALSE;
01051 SendDlgItemMessage(hdlg,DLG_PREFS_WIREB,BM_SETCHECK,state,0);
01052 if(Mapped == TRUE)state=TRUE; else state=FALSE;
01053 SendDlgItemMessage(hdlg,DLG_PREFS_MAPS,BM_SETCHECK,state,0);
01054 if(Update == TRUE)state=TRUE; else state=FALSE;
01055 SendDlgItemMessage(hdlg,DLG_PREFS_UPDATE,BM_SETCHECK,state,0);
01056 if(Fastest == TRUE)state=TRUE; else state=FALSE;
01057 SendDlgItemMessage(hdlg,DLG_PREFS_FASTEST,BM_SETCHECK,state,0);
01058 if(Clamped == TRUE)state=TRUE; else state=FALSE;
01059 SendDlgItemMessage(hdlg,DLG_PREFS_CLAMPED,BM_SETCHECK,state,0);
01060 if(AttenuateLight == TRUE)state=TRUE; else state=FALSE;
01061 SendDlgItemMessage(hdlg,DLG_PREFS_DEPTHC,BM_SETCHECK,state,0);
01062 if(bNurbsWireOnly == TRUE)state=TRUE; else state=FALSE;
01063 SendDlgItemMessage(hdlg,DLG_PREFS_NURBSR,BM_SETCHECK,state,0);
01064 R=(double)gbRed; G=(double)gbGreen; B=(double)gbBlue;
01065 return (TRUE);
01066 case WM_COMMAND:
01067 switch(LOWORD(wparam)){
01068 case DLG_PREFS_COLOUR:
01069 uColour[0]=(unsigned char)(R*255.0);
01070 uColour[1]=(unsigned char)(G*255.0);
01071 uColour[2]=(unsigned char)(B*255.0);
01072 ChooseColour(uColour,"Background Color",hdlg);
01073 R=(double)uColour[0]/255.0;
01074 G=(double)uColour[1]/255.0;
01075 B=(double)uColour[2]/255.0;
01076 break;
01077 case IDOK:
01078 if(SendDlgItemMessage(hdlg,DLG_PREFS_WIRE,BM_GETCHECK,0,0))
01079 mode=0; else mode=1;
01080 if(mode == 0)w=yesyes; else w=nono;
01081 WritePrivateProfileString(IniSection,"WIRE",w,IniFilename);
01082 if(SendDlgItemMessage(hdlg,DLG_PREFS_WIREB,BM_GETCHECK,0,0))
01083 bounding_box=1; else bounding_box=0;
01084 if(bounding_box == 1)w=yesyes; else w=nono;
01085 WritePrivateProfileString(IniSection,"WIREB",w,IniFilename);
01086 if(SendDlgItemMessage(hdlg,DLG_PREFS_MAPS,BM_GETCHECK,0,0))
01087 Mapped=TRUE; else Mapped=FALSE;
01088 if(Mapped == TRUE)w=yesyes; else w=nono;
01089 WritePrivateProfileString(IniSection,"MAPPED",w,IniFilename);
01090 if(SendDlgItemMessage(hdlg,DLG_PREFS_UPDATE,BM_GETCHECK,0,0))
01091 Update=TRUE; else Update=FALSE;
01092 if(Update == TRUE)w=yesyes; else w=nono;
01093 WritePrivateProfileString(IniSection,"UPDATE",w,IniFilename);
01094 if(SendDlgItemMessage(hdlg,DLG_PREFS_FASTEST,BM_GETCHECK,0,0))
01095 Fastest=TRUE; else Fastest=FALSE;
01096 if(Fastest == TRUE)w=yesyes; else w=nono;
01097 WritePrivateProfileString(IniSection,"FASTEST",w,IniFilename);
01098 if(SendDlgItemMessage(hdlg,DLG_PREFS_CLAMPED,BM_GETCHECK,0,0))
01099 Clamped=TRUE; else Clamped=FALSE;
01100 if(Clamped == TRUE)w=yesyes; else w=nono;
01101 WritePrivateProfileString(IniSection,"CLAMPED",w,IniFilename);
01102 if(SendDlgItemMessage(hdlg,DLG_PREFS_DEPTHC,BM_GETCHECK,0,0))
01103 AttenuateLight=TRUE; else AttenuateLight=FALSE;
01104 if(AttenuateLight == TRUE)w=yesyes; else w=nono;
01105 WritePrivateProfileString(IniSection,"DEPTHCUE",w,IniFilename);
01106 if(SendDlgItemMessage(hdlg,DLG_PREFS_NURBSR,BM_GETCHECK,0,0))
01107 bNurbsWireOnly=TRUE; else bNurbsWireOnly=FALSE;
01108 if(bNurbsWireOnly == TRUE)w=yesyes; else w=nono;
01109 WritePrivateProfileString(IniSection,"NURBSWIREONLY",w,IniFilename);
01110
01111 gbRed=(GLfloat)R; gbGreen=(GLfloat)G; gbBlue=(GLfloat)B;
01112 SetMappingQuality();
01113 glClearColor(gbRed,gbGreen,gbBlue,1.0);
01114 InvalidateRect(GetParent(hdlg),NULL,FALSE);
01115 sprintf(str,"%lf %lf %lf",R,G,B);
01116 WritePrivateProfileString(IniSection,"COLOUR",str,IniFilename);
01117 EndDialog(hdlg,TRUE);
01118 return(TRUE);
01119 break;
01120 case IDCANCEL:
01121 EndDialog(hdlg,FALSE);
01122 return(TRUE);
01123 break;
01124 default: break;
01125 }
01126 break;
01127 default: break;
01128 }
01129 return(FALSE);
01130 }