Пример #1
0
bool TerrainClass::Initialize(ID3D11Device* device, char* heightMapFilename, WCHAR* textureFilename, char* colorMapFilename)
{
	bool result;


	// Load in the height map for the terrain.
	result = LoadHeightMap(heightMapFilename);
	if (!result)
	{
		return false;
	}

	// Normalize the height of the height map.
	NormalizeHeightMap();

	// Calculate the normals for the terrain data.
	result = CalculateNormals();
	if (!result)
	{
		return false;
	}

	// Calculate the texture coordinates.
	CalculateTextureCoordinates();

	// Load the texture.
	result = LoadTexture(device, textureFilename);
	if (!result)
	{
		return false;
	}

	// Load in the color map for the terrain.
	result = LoadColorMap(colorMapFilename);
	if (!result)
	{
		return false;
	}

	// Initialize the vertex and index buffer that hold the geometry for the terrain.
	result = InitializeBuffers(device);
	if (!result)
	{
		return false;
	}

	return true;
}
Пример #2
0
void SetVideoMode(void)
{
   /* set new variable screen info */
   if (ioctl(FrameBufferFD, FBIOPUT_VSCREENINFO, &VarInfo)) {
      sprintf(exiterror, "FBIOPUT_VSCREENINFO failed: %s\n", strerror(errno));
      strcat(exiterror, "Perhaps the device does not support the selected mode\n");
      exit(0);
   }

   /* reload the screen info to update rgb bits */
   if (ioctl(FrameBufferFD, FBIOGET_VSCREENINFO, &VarInfo)) {
      sprintf(exiterror, "error: ioctl(FBIOGET_VSCREENINFO) failed: %s\n",
	      strerror(errno));
      exit(0);
   }

   /* reload the fixed info to update color mode */
   if (ioctl(FrameBufferFD, FBIOGET_FSCREENINFO, &FixedInfo)) {
      sprintf(exiterror, "error: ioctl(FBIOGET_FSCREENINFO) failed: %s\n",
	      strerror(errno));
      exit(0);
   }

   if (DesiredDepth && DesiredDepth !=  VarInfo.bits_per_pixel) {
      sprintf(exiterror, "error: Could not set set %d bpp\n", DesiredDepth);
      exit(0);
   }

   if(DisplayMode & GLUT_INDEX && FixedInfo.visual == FB_VISUAL_DIRECTCOLOR) {
      sprintf(exiterror, "error: Could not set 8 bit color mode\n");
      exit(0);
   }

   /* initialize colormap */
   LoadColorMap();
}
Пример #3
0
MRESULT PMfrCommands (HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
     {
     /*
        These are the routnes that handle the commands issued by
        the FRACTINT for PM menus.

        In most cases, they call another support routine to
        handle or schedule the event requested by the user.
     */

     SHORT sCommand = SHORT1FROMMP(mp1);


     switch (sCommand)
          {
          case IDM_GO:
               /* fire up the subtask */
               cp.fContinueCalc = TRUE ;
               if (npNewParms.fNewParms)
                  {
                  CopyParmsToBase();
                  /* GetMemoryBitmap(); */
                  SetSwitchEntry (hwnd, szTitleBar,
                                  GetFractalName(cp.iFractType) );
                  }

               cp.sSubAction = SUB_ACT_CALC;   /* we want a Calculation */

               DosSemClear (&cp.ulSemTrigger) ;  /* release the subthread */

               sStatus = STATUS_WORKING ;
               /* WinInvalidateRect (hwnd, NULL, FALSE) ; */
               UpdateMenuText (hwnd, IDM_FREEZE_HALT, szHalt);
               EnableMenuItem (hwnd, IDM_GO, FALSE) ;
               EnableMenuItem (hwnd, IDM_FREEZE_HALT, TRUE) ;
               /* WinStartTimer (hab, hwnd, ID_TIMER, 5000); */
               return 0 ;

          case IDM_PAN:
               /* Pan selected.  Pan to where the cross hairs were */
               PanNewCenter(hwnd);
               fGoodPan = FALSE;
               return 0;

          case IDM_ZIN_WIN:
               /* Zoom to the Window selected. */
               EraseZoomBox(hwnd);
               ZoomNewWindow(hwnd, TRUE);   /* zoom in */
               fGoodZoom = FALSE;
               return 0;

          case IDM_ZOUT_WIN:
               /* Zoom to the Window selected. */
               EraseZoomBox(hwnd);
               ZoomNewWindow(hwnd, FALSE);   /* zoom out */
               fGoodZoom = FALSE;
               return 0;

          case IDM_FREEZE_HALT:
               if (sStatus == STATUS_WORKING)
                  {
                  /* schedule the subthread to find a stopping place */
                  cp.fContinueCalc = FALSE ;
                  EnableMenuItem (hwnd, IDM_FREEZE_HALT, FALSE) ;
                  }
               if (sStatus == STATUS_READY)
                  {
                  /* we Freeze to play with parms repeatedly */
                  /* make a copy to play with.  We will keep */
                  /* working with only this copy */
                  InitNewParms(NULL);
                  /* now change state */
                  sStatus = STATUS_FROZEN;
                  EnableMenuItem (hwnd, IDM_FREEZE_HALT, FALSE);
                  }

               return 0 ;

          case IDM_ABOUT:
               /* send up the About box */
               WinDlgBox (HWND_DESKTOP, hwnd, AboutDlgProc,
                    (HMODULE) 0, IDD_ABOUT, NULL) ;

               return 0 ;

          case IDM_NEW_FRACTAL:
               /*
                * send up the Select Fractal Type box.
                * On OK return, schedule the new parameters.
                * Handle the special cases needing files or other data
                * as part of exiting the initial dialog box.
               */
               if (WinDlgBox (HWND_DESKTOP, hwnd, SelFractalDlgProc,
                       (HMODULE) 0, IDD_SET_FRACTTYPE, NULL) )
                  ScheduleNewParms (hwnd);

               return 0 ;

          case IDM_SET_PARAMS:
               /*
                * send up the Set Paramters box.
                * On OK return, schedule the new parameters.
               */
               if (WinDlgBox (HWND_DESKTOP, hwnd, SetParametersDlgProc,
                       (HMODULE) 0, IDD_SET_PARAMS, NULL) )
               ScheduleNewParms (hwnd);

               return 0 ;

          case IDM_SET_OPTIONS:
               /*
                * send up the Set Options box.
                * On OK return, schedule the new parameters.
               */
               if (WinDlgBox (HWND_DESKTOP, hwnd, SetOptionsDlgProc,
                       (HMODULE) 0, IDD_SET_OPTIONS, NULL) )
               ScheduleNewParms (hwnd);

               return 0 ;

          case IDM_SET_IMAGE:
               /*
                * send up the Set Image box.
                * On OK return, schedule the new parameters.
               */
               if (WinDlgBox (HWND_DESKTOP, hwnd, SetImageDlgProc,
                       (HMODULE) 0, IDD_SET_IMAGE, NULL) )
               ScheduleNewParms (hwnd);

               return 0 ;

          case IDM_SET_PALETTE:
               /*
                * send up the Set Palette box.
                * Return is not checked because effects are immediate
               */
               WinDlgBox (HWND_DESKTOP, hwnd, SetPaletteDlgProc,
                       (HMODULE) 0, IDD_SET_PALETTE, NULL) ;

               return 0 ;

          case IDM_ZIN_PICK:
          case IDM_ZOUT_PICK:
               /*
                * Send up the Zoom Value dialog box.
                * On OK return, schedule the new parameters.
               */
               if ( WinDlgBox (HWND_DESKTOP, hwnd, ZoomValueDlgProc,
                        (HMODULE) 0, IDD_NUMBER_PICK,
                        MPFROMP((PVOID) &COMMANDMSG(&msg)->cmd)) )
                  ScheduleNewParms (hwnd);

               return 0 ;

          case IDM_ZIN_2:
          case IDM_ZIN_5:
          case IDM_ZIN_10:
               /*
                * Zoom in by fixed value.
                * Schedule the new parameters.
               */
               InitNewParms(NULL);
               CalcZoomValues(&npNewParms,
                      (double) (sCommand), TRUE );
               npNewParms.fNewParms = TRUE;
               ScheduleNewParms(hwnd);

               return 0;

          case IDM_ZOUT_2:
          case IDM_ZOUT_5:
          case IDM_ZOUT_10:
               /*
                * Zoom out by fixed value.
                * Schedule the new parameters.
               */
               InitNewParms(NULL);
               CalcZoomValues(&npNewParms,
                      (double) (sCommand - 10), FALSE );
               npNewParms.fNewParms = TRUE;
               ScheduleNewParms(hwnd);

               return 0;

          case IDM_SET_EXTENTS:
               /*
                * Send up the Set Extents dialog box.
                * On OK return, schedule the new parameters.
               */
               if ( WinDlgBox (HWND_DESKTOP, hwnd, SetExtentsDlgProc,
                      (HMODULE) 0, IDD_SET_EXTENTS, NULL) )
                   ScheduleNewParms (hwnd);

               return 0;

          case IDM_SET_SWAP:
               /* swap Mandel for Julia or vice versa.
                  Handle it as a parm change */
               InitNewParms(NULL);
               if (fractalspecific[npNewParms.iFractType].tojulia != NOFRACTAL
                      && npNewParms.param[0] == 0.0
                      && npNewParms.param[1] == 0.0)
                  {
                  /* switch to corresponding Julia set */
                  npNewParms.iFractType =
                         fractalspecific[npNewParms.iFractType].tojulia;
                  npNewParms.param[0] = npNewParms.XCenter;
                  npNewParms.param[1] = npNewParms.YCenter;

                  npNewParms.mxXL = fractalspecific[npNewParms.iFractType].xmin;
                  npNewParms.mxXR = fractalspecific[npNewParms.iFractType].xmax;
                  npNewParms.mxYB = fractalspecific[npNewParms.iFractType].ymin;
                  npNewParms.mxYT = fractalspecific[npNewParms.iFractType].ymax;

                  }

               else if (fractalspecific[npNewParms.iFractType].tomandel != NOFRACTAL)
                  {
                  /* switch to corresponding Mandel set */
                  npNewParms.iFractType =
                         fractalspecific[npNewParms.iFractType].tomandel;
                  npNewParms.param[0] = 0.0;
                  npNewParms.param[1] = 0.0;
                  npNewParms.mxXL = fractalspecific[npNewParms.iFractType].xmin;
                  npNewParms.mxXR = fractalspecific[npNewParms.iFractType].xmax;
                  npNewParms.mxYB = fractalspecific[npNewParms.iFractType].ymin;
                  npNewParms.mxYT = fractalspecific[npNewParms.iFractType].ymax;
                  }

               npNewParms.fNewParms = TRUE;
               ScheduleNewParms (hwnd);
               return 0;

          case IDM_SET_RESET:
               /* copy the work copy of the parms back from the
                  set used by the calculation engine.
                  This resets any dicking around done with the
                  dialogs.
                  Note: this is only active during FREEZE mode.
               */

               CopyParmsToNew();

               return 0;

          case IDM_HELP_INTRO:
               /* basic Introductory Help */
               SimpleHelp(hab, hwnd, szTitleBar,
                         (HMODULE) 0, IDT_TEXT, IDT_HELP_INTRO);
               return 0;

          case IDM_HELP_FRACTTYPE:
               /* Fractal list Help */
               SimpleHelp(hab, hwnd, szTitleBar,
                         (HMODULE) 0, IDT_TEXT, IDT_HELP_TYPES);
               return 0;

          case IDM_HELP_OPERATE:
               /* Menu Help */
               SimpleHelp(hab, hwnd, szTitleBar,
                       (HMODULE) 0, IDT_TEXT, IDT_HELP_OPERATE);
               return 0;

          case IDM_PRINT_FILE:
               /* Send up the Print Where Dialog.
                  On OK return, fire up the subtask */
               if ( WinDlgBox(HWND_DESKTOP, hwnd, PrintOptionsDlgProc,
                    (HMODULE) 0, IDD_PRINT, NULL) )
                  {
                  /* fire up the subtask */
                  cp.sSubAction = SUB_ACT_PRINT;   /* we want a Print */

                  cp.fContinueCalc = TRUE;
                  DosSemClear (&cp.ulSemTrigger) ;  /* release the subthread */

                  sStatus = STATUS_WORKING ;
                  UpdateMenuText (hwnd, IDM_FREEZE_HALT, szHalt);
                  EnableMenuItem (hwnd, IDM_GO, FALSE) ;
                  EnableMenuItem (hwnd, IDM_FREEZE_HALT, TRUE) ;
                  cp.fSuppressPaint = TRUE;
                  WinInvalidateRect(hwnd, NULL, FALSE);
                  }

               return 0 ;

          case IDM_READ_FILE:
               /* Send up the Load/Save Format Dialog to find
                  out the format we will read.
                  Then send up the generic Open File dialog.
                  On OK return, fire up the subtask */
               {
               DLF dlf;
               HFILE hfDummy;
               PSZ pszExt;

               if ( WinDlgBox(HWND_DESKTOP, hwnd, LoadSaveFmtDlgProc,
                    (HMODULE) 0, IDD_LOADSAVE_TYPE, szLoadWhatFmt) )
                  {

                  FileFmtExt (&pszExt);

                  SetupDLF (&dlf, DLG_OPENDLG, &hfDummy,
                            pszExt, szTitleBar,
                            szOpenTitle, szOpenHelp);

                  if (TDF_OLDOPEN == DlgFile(hwnd, &dlf) )
                     {
                     /* close the dummy file handle */
                     DosClose(hfDummy);
                     /* fire up the subtask */
                     cp.sSubAction = SUB_ACT_LOAD;   /* we want a Load */
                     cp.sSubFunction = cp.sLastLoadSaveType;
                     _fstrcpy(cp.szFileName, dlf.szOpenFile);

                     cp.fContinueCalc = TRUE;
                     DosSemClear (&cp.ulSemTrigger) ;  /* release the subthread */

                     sStatus = STATUS_WORKING ;
                     UpdateMenuText (hwnd, IDM_FREEZE_HALT, szHalt);
                     EnableMenuItem (hwnd, IDM_GO, FALSE) ;
                     EnableMenuItem (hwnd, IDM_FREEZE_HALT, TRUE) ;
                     cp.fSuppressPaint = TRUE;
                     WinInvalidateRect(hwnd, NULL, FALSE);
                     }
                  }

               return 0 ;
               }

          case IDM_SAVE_FILE:
               /* Send up the Load/Save Format Dialog to find
                  out the format we will be writing.
                  Then send up the generic Save File dialog.
                  On OK return, fire up the subtask */
               {
               DLF dlf;
               HFILE hfDummy;
               PSZ pszExt;

               if ( WinDlgBox(HWND_DESKTOP, hwnd, LoadSaveFmtDlgProc,
                    (HMODULE) 0, IDD_LOADSAVE_TYPE, szSaveWhatFmt) )
                  {

                  FileFmtExt (&pszExt);

                  SetupDLF (&dlf, DLG_SAVEDLG, &hfDummy,
                            pszExt, szTitleBar,
                            szOpenTitle, szOpenHelp);
                  _fstrcpy(dlf.szOpenFile, cp.szFileName);

                  if (TDF_NOSAVE != DlgFile(hwnd, &dlf) )
                     {
                     /* close the dummy file handle */
                     DosClose(hfDummy);
                     /* and delete the dummy file */
                     DosDelete(dlf.szOpenFile, 0);
                     /* fire up the subtask */
                     cp.sSubAction = SUB_ACT_SAVE;   /* we want a Save */
                     cp.sSubFunction = cp.sLastLoadSaveType;
                     _fstrcpy(cp.szFileName, dlf.szOpenFile);

                     cp.fContinueCalc = TRUE;
                     DosSemClear (&cp.ulSemTrigger) ;  /* release the subthread */

                     sStatus = STATUS_WORKING ;
                     UpdateMenuText (hwnd, IDM_FREEZE_HALT, szHalt);
                     EnableMenuItem (hwnd, IDM_GO, FALSE) ;
                     EnableMenuItem (hwnd, IDM_FREEZE_HALT, TRUE) ;
                     cp.fSuppressPaint = TRUE;
                     WinInvalidateRect(hwnd, NULL, FALSE);
                     }
                 }

               return 0 ;
               }

          case IDM_READ_COLORMAP:
               /* Send up the generic Open File dialog.
                  On OK return, read in the file via subroutine. */
               {
               DLF dlf;
               HFILE hfDummy;

               SetupDLF (&dlf, DLG_OPENDLG, &hfDummy,
                         "\\*.map", szTitleBar,
                         szColorMapTitle, szColorMapHelp);

               if (TDF_OLDOPEN == DlgFile(hwnd, &dlf) )
                  {
                  /* close the dummy file handle */
                  DosClose(hfDummy);
                  /* throw up the hour-glass */
                  WinSetCapture(HWND_DESKTOP, hwnd);
                  WinSetPointer(HWND_DESKTOP, hptrWait);
                  /* read it in */
                  LoadColorMap(dlf.szOpenFile);
                  /* now clean up */
                  WinSetPointer(HWND_DESKTOP, hptrArrow);
                  WinSetCapture(HWND_DESKTOP, (HWND) NULL);
                  }
               }

               return 0;

          case IDM_WRITE_COLORMAP:
               /* Send up the generic Save File dialog.
                  On OK return, write the file via subroutine */
               {
               DLF dlf;
               HFILE hfDummy;

               SetupDLF (&dlf, DLG_SAVEDLG, &hfDummy,
                         "\\*.map", szTitleBar,
                         szColorMapTitle, szColorMapHelp);

               if (TDF_NOSAVE != DlgFile(hwnd, &dlf) )
                  {
                  /* close the dummy file handle */
                  DosClose(hfDummy);
                  /* throw up the hour-glass */
                  WinSetCapture(HWND_DESKTOP, hwnd);
                  WinSetPointer(HWND_DESKTOP, hptrWait);
                  /* write it out */
                  SaveColorMap(dlf.szOpenFile);
                  /* now clean up */
                  WinSetPointer(HWND_DESKTOP, hptrArrow);
                  WinSetCapture(HWND_DESKTOP, (HWND) NULL);
                  }
               }

               return 0;

          case IDM_CLEAR_CLPB:
               /* clear the current contents of the clipboard */
               WinOpenClipbrd (hab);
               WinEmptyClipbrd (hab);
               WinCloseClipbrd (hab);

               return 0;

          case IDM_PASTE:
               {  /* paste from the clipboard into us */
               USHORT usClipBrdInfo;

               if ( WinQueryClipbrdFmtInfo(hab, CF_BITMAP, &usClipBrdInfo) )
                  {  /* we have a bitmap to fetch */
                  /* draw the curtain over the display */
                  cp.fSuppressPaint = TRUE;
                  WinInvalidateRect(hwnd, NULL, FALSE);
                  WinUpdateWindow(hwnd);
                  /* throw up the hour-glass */
                  WinSetCapture(HWND_DESKTOP, hwnd);
                  WinSetPointer(HWND_DESKTOP, hptrWait);
                  /* fetch the bitmap */
                  PMfrFetchClipbrdBmp(hab);
                  /* now clean up */
                  WinSetPointer(HWND_DESKTOP, hptrArrow);
                  WinSetCapture(HWND_DESKTOP, (HWND) NULL);
                  /* and schedule redrawing the window */
                  SetSwitchEntry (hwnd, szTitleBar,
                                  GetFractalName(cp.iFractType) );
                  cp.fSuppressPaint = FALSE;
                  WinInvalidateRect(hwnd, NULL, FALSE);
                  }
               }

               return 0;

          case IDM_COPY_BMP:
               {  /* copy to the clipboard from us */

               /* throw up the hour-glass */
               WinSetCapture(HWND_DESKTOP, hwnd);
               WinSetPointer(HWND_DESKTOP, hptrWait);
               /* write the bitmap */
               PMfrWriteClipbrdBmp(hab);
               /* now clean up */
               WinSetPointer(HWND_DESKTOP, hptrArrow);
               WinSetCapture(HWND_DESKTOP, (HWND) NULL);

               }

               return 0;

          }

     return 0;

     }