home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / VBasic / VLIB20.ZIP / VLIBDEMO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-14  |  59.6 KB  |  1,935 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM:    Vlibdemo.exe
  4.  
  5.     PURPOSE:    To demonstrate the usage of Visualib(TM) functions.
  6.     
  7.     PROVIDER:   Visual Technology, Co.
  8.                 P.O.Box 901-413
  9.                 Kansas City, MO 64190
  10.                 Tel. (219) 289-0235
  11.                 Fax. (816) 746-6618
  12.     
  13.     DATE:        May, 1993
  14.  
  15. ****************************************************************************/
  16.  
  17. #include <windows.h>
  18. #include "visualib.h"
  19. #include "menu.h"
  20. #include "vlibdemo.h"
  21. #include "demoproc.h"
  22. #include "dialogs.h"
  23.  
  24. HINSTANCE    hInst;
  25. HPALETTE    hpal;
  26. short   viewer20, viewer21, viewer22;
  27. short   viewer30, viewer31, viewer32, viewer33, viewer34, viewer35;
  28. short   demo_function, animate_length;
  29. short   light0, light1, light2, light3, light4, light5, light6, light7, light8;
  30. short   mater0, mater1, mater2, mater3, mater4, mater5, mater6, mater7;
  31. HGLOBAL hdib1, hdib2, hdib3;
  32. COLORREF    backcolor;
  33. BOOL    withframe = FALSE;
  34.  
  35. void    FunctionDemos (HDC hdc); 
  36.  
  37. int PASCAL WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR CmdLine, int nCmdShow)
  38. {
  39.     MSG msg;
  40.  
  41.     if (hPrev)
  42.         return (FALSE);
  43.  
  44.     if (!InitApplication (hInst))
  45.         return (FALSE);
  46.     
  47.     if (!InitInstance (hInst, nCmdShow))
  48.         return (FALSE);
  49.     
  50.     while (GetMessage (&msg, NULL, NULL, NULL)) {
  51.         TranslateMessage (&msg);
  52.         DispatchMessage (&msg);
  53.     }
  54.     return (msg.wParam);
  55. }
  56.  
  57. void    ViewerReset ()
  58. {
  59.     RECT    port;
  60.  
  61.     SetViewerName (viewer21, "2D Objects");
  62.     SetRect (&port, 10, 10, 110, 110);
  63.     SetViewport (viewer21, port);
  64.     SetWindow2D (viewer21, -10, -10, 10, 10);
  65.  
  66.     SetViewerName (viewer22, "U.S. Flag");
  67.     SetRect (&port, 10, 10, 410, 227);
  68.     SetViewport (viewer22, port);
  69.     SetWindow2D (viewer22, 0, 0, 1, (real) (13.0 / 24.0));
  70.  
  71.     SetViewerName (viewer31, "View Motion");
  72.     SetRect (&port, 120, 10, 220, 110);
  73.     SetViewport (viewer31, port);
  74.     SetView3D (viewer31, 100, 100, 100, 0, 0, 0, 0);
  75.     SetPerspective (viewer31, 45, 1, 1, 1000);
  76.  
  77.     SetViewerName (viewer32, "Object Rotation");
  78.     SetRect (&port, 230, 10, 330, 110);
  79.     SetViewport (viewer32, port);
  80.     SetView3D (viewer32, 100, 100, 100, 0, 0, 0, 0);
  81.     SetPerspective (viewer32, 45, 1, 1, 1000);
  82.  
  83.     SetViewerName (viewer33, "View Zoom");
  84.     SetRect (&port, 230, 130, 330, 230);
  85.     SetViewport (viewer33, port);
  86.     SetPolarView (viewer33, 1, 1, 0, 20, 75, 45, 0);
  87.     SetPerspective (viewer33, 90, 1, 1, 1000);
  88.  
  89.     SetViewerName (viewer34, "Ortho Project");
  90.     SetRect (&port, 120, 130, 220, 230);
  91.     SetViewport (viewer34, port);
  92.     SetPolarView (viewer34, 0, 0, 0, 10, 45, 45, 0);
  93.     SetProjection3D (viewer34, -10, -10, 10, 10, 1, 100, VL_ORTHOGONAL);
  94.  
  95.     SetViewerName (viewer35, "Depth Clipping");
  96.     SetRect (&port, 10, 130, 110, 230);
  97.     SetViewport (viewer35, port);
  98.     SetPolarView (viewer35, 0, 0, 0, 20, 75, 45, 0);
  99.     SetPerspective (viewer35, 90, 1, 1, 80);
  100. }
  101.  
  102. /****************************************************************************
  103.  
  104.     FUNCTION: InitApplication (HANDLE)
  105.  
  106.     PURPOSE: Initializes window data and registers window class
  107.  
  108.     COMMENTS:
  109.  
  110.         This function is called at initialization time only if no other 
  111.         instances of the application are running.  This function performs 
  112.         initialization tasks that can be done once for any number of running 
  113.         instances.  
  114.  
  115.         In this case, we initialize a window class by filling out a data 
  116.         structure of type WNDCLASS and calling the Windows RegisterClass () 
  117.         function.  Since all instances of this application use the same window
  118.         class, we only need to do this when the first instance is initialized.
  119.  
  120. ****************************************************************************/
  121.  
  122. BOOL InitApplication (HINSTANCE hInstance)
  123. {
  124.     WNDCLASS  wc;
  125.     RECT    port;
  126.     VECTOR3    parameter;
  127.  
  128.     if (!InitializeVisualib ())
  129.         return (FALSE);
  130.     SelectLight (light0 = CreateLight (NULL, VL_POINTLIGHT));
  131.     SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  132.     VSET3 (parameter, 50, 250, 0);
  133.     ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  134.     ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (255, 255, 255));
  135.     SwitchLight (VL_CURRENT, TRUE);
  136.  
  137.     SelectLight (light1 = CreateLight (NULL, VL_POINTLIGHT));
  138.     SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  139.     VSET3 (parameter, 350, -100, 200);
  140.     ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  141.     ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (255, 255, 255));
  142.     SwitchLight (VL_CURRENT, TRUE);
  143.  
  144.     SelectLight (light2 = CreateLight (NULL, VL_POINTLIGHT));
  145.     VSET3 (parameter, -50, 0, 0);
  146.     ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  147.     ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (51, 255, 51));
  148.  
  149.     SelectLight (light3 = CreateLight (NULL, VL_POINTLIGHT));
  150.     VSET3 (parameter, 250, -20, 0);
  151.     ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  152.     ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (51, 51, 255));
  153.  
  154.     SelectLight (light4 = CreateLight (NULL, VL_SPOTLIGHT));
  155.     SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  156.     VSET3 (parameter, 0, 100, 100);
  157.     ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  158.     VSET3 (parameter, 0, -0.707, -0.707);
  159.     ShadingParameter (VL_CURRENT, VL_LIGHTDIRECTION, FALSE, parameter);
  160.     ShadingFactor (VL_CURRENT, VL_SPOTLIGHTANGLE, 20);
  161.     ShadingFactor (VL_CURRENT, VL_SPOTLIGHTSPREAD, 50);
  162.     ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (255, 0, 0));
  163.  
  164.     SelectLight (light5 = CreateLight (NULL, VL_SPOTLIGHT));
  165.     SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  166.     VSET3 (parameter, 100, 0, 100);
  167.     ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  168.     VSET3 (parameter, -0.707, 0, -0.707);
  169.     ShadingParameter (VL_CURRENT, VL_LIGHTDIRECTION, FALSE, parameter);
  170.     ShadingFactor (VL_CURRENT, VL_SPOTLIGHTANGLE, 20);
  171.     ShadingFactor (VL_CURRENT, VL_SPOTLIGHTSPREAD, 50);
  172.     ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (0, 255, 0));
  173.  
  174.     SelectLight (light6 = CreateLight (NULL, VL_SPOTLIGHT));
  175.     SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  176.     VSET3 (parameter, 100, 100, 100);
  177.     ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  178.     VSET3 (parameter, -0.577, -0.577, -0.577);
  179.     ShadingParameter (VL_CURRENT, VL_LIGHTDIRECTION, FALSE, parameter);
  180.     ShadingFactor (VL_CURRENT, VL_SPOTLIGHTANGLE, 20);
  181.     ShadingFactor (VL_CURRENT, VL_SPOTLIGHTSPREAD, 50);
  182.     ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (0, 0, 255));
  183.  
  184.     SelectLight (light7 = CreateLight (NULL, VL_POINTLIGHT));
  185.     SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  186.     VSET3 (parameter, 50, 250, 0);
  187.     ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  188.     ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (255, 255, 255));
  189.  
  190.     SelectLight (light8 = CreateLight (NULL, VL_POINTLIGHT));
  191.     SetLightCoordinateType (VL_CURRENT, VL_WORLDLIGHT);
  192.     VSET3 (parameter, 350, -100, 200);
  193.     ShadingParameter (VL_CURRENT, VL_LIGHTLOCATION, FALSE, parameter);
  194.     ShadingColor (VL_CURRENT, VL_LIGHTCOLOR, RGB (255, 255, 255));
  195.  
  196.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_PHONGSHADE);
  197.     ShadingOption (VL_CURRENT, VL_BACKFACEREMOVAL, TRUE);
  198.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, TRUE);
  199.     ShadingOption (VL_CURRENT, VL_LOCALVIEWER, TRUE);
  200.  
  201.     SelectMaterial (mater0 = CreateMaterial (NULL));
  202.     ShadingColor (VL_CURRENT, VL_MATERIALSPECULAR, RGB (255, 255, 255));
  203.     ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, 1);
  204.     ShadingColor (VL_CURRENT, VL_MATERIALAMBIENT, RGB (255, 255, 255));
  205.     ShadingFactor (VL_CURRENT, VL_AMBIENTREFLECT, 0.2f);
  206.     ShadingColor (VL_CURRENT, VL_MATERIALDIFFUSE, RGB (255, 255, 255));
  207.     ShadingFactor (VL_CURRENT, VL_SHININESS, 30);
  208.  
  209.     SelectMaterial (mater1 = CreateMaterial (NULL));
  210.     ShadingColor (VL_CURRENT, VL_MATERIALSPECULAR, RGB (255, 255, 255));
  211.     ShadingColor (VL_CURRENT, VL_MATERIALAMBIENT, RGB (255, 0, 0));
  212.     ShadingFactor (VL_CURRENT, VL_AMBIENTREFLECT, 0.3f);
  213.     ShadingColor (VL_CURRENT, VL_MATERIALDIFFUSE, RGB (255, 0, 0));
  214.     ShadingFactor (VL_CURRENT, VL_SHININESS, 40);
  215.  
  216.     SelectMaterial (mater2 = CreateMaterial (NULL));
  217.     ShadingColor (VL_CURRENT, VL_MATERIALSPECULAR, RGB (255, 255, 255));
  218.     ShadingColor (VL_CURRENT, VL_MATERIALAMBIENT, RGB (255, 255, 255));
  219.     ShadingFactor (VL_CURRENT, VL_AMBIENTREFLECT, 0.4f);
  220.     ShadingColor (VL_CURRENT, VL_MATERIALDIFFUSE, RGB (0, 255, 0));
  221.     ShadingFactor (VL_CURRENT, VL_SHININESS, 20);
  222.  
  223.     SelectMaterial (mater3 = CreateMaterial (NULL));
  224.     ShadingColor (VL_CURRENT, VL_MATERIALSPECULAR, RGB (255, 255, 255));
  225.     ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, 0.5f);
  226.     ShadingColor (VL_CURRENT, VL_MATERIALAMBIENT, RGB (255, 255, 255));
  227.     ShadingFactor (VL_CURRENT, VL_AMBIENTREFLECT, 0.1f);
  228.     ShadingColor (VL_CURRENT, VL_MATERIALDIFFUSE, RGB (0, 0, 255));
  229.     ShadingFactor (VL_CURRENT, VL_SHININESS, 10);
  230.     mater4 = CreateMaterial (NULL);
  231.     mater5 = CreateMaterial (NULL);
  232.     mater6 = CreateMaterial (NULL);
  233.     mater7 = CreateMaterial (NULL);
  234.     SelectMaterial (mater0);
  235.  
  236.     hpal = SetRGBPalette ();
  237.     SetRect (&port, 0, 0, 400, 300);
  238.     viewer20 = CreateViewer ("2D Primitive Test", port, VL_TWOD, VL_HORZFIT);
  239.     SetWindow2D (viewer20, -10, -10, 10, 10); 
  240.     viewer30 = CreateViewer ("3D Primitive Test", port, VL_THREED, VL_HORZFIT);
  241.     SetView3D (viewer30, 100, 100, 100, 0, 0, 0, 0);
  242.     SetPerspective (viewer30, 45, 1, 30, 1000);
  243.     SetDepthBuffer (viewer30);
  244.  
  245.     viewer21 = CreateViewer ("2D Objects", port, VL_TWOD, VL_HORZFIT);
  246.     viewer22 = CreateViewer ("U.S. Flag", port, VL_TWOD, VL_ALLFIT);
  247.     viewer31 = CreateViewer ("View Motion", port, VL_THREED, VL_ALLFIT);
  248.     viewer32 = CreateViewer ("Object Rotation", port, VL_THREED, VL_ALLFIT);
  249.     viewer33 = CreateViewer ("View Zoom", port, VL_THREED, VL_ALLFIT);
  250.     viewer34 = CreateViewer ("Ortho Project", port, VL_THREED, VL_HORZFIT);
  251.     viewer35 = CreateViewer ("Depth Clipping", port, VL_THREED, VL_ALLFIT);
  252.     ViewerReset ();
  253.     demo_function = IDM_DEMO_START;
  254. //    demo_function = 0;
  255.     wc.style = NULL;
  256.     wc.lpfnWndProc = MainWndProc;
  257.     wc.cbClsExtra = 0;
  258.     wc.cbWndExtra = 0;
  259.     wc.hInstance = hInstance;
  260.     wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE (VL_LOGO));
  261.     wc.hCursor = LoadCursor (NULL, IDC_ARROW);
  262.     backcolor = RGB (0, 64, 64);
  263.     wc.hbrBackground = CreateSolidBrush (backcolor);
  264.     wc.lpszMenuName =  "VlibDemo";
  265.     wc.lpszClassName = "VlibDemoClass";
  266.  
  267.     return (RegisterClass (&wc));
  268.  
  269. }
  270.  
  271. /****************************************************************************
  272.  
  273.     FUNCTION:  InitInstance (HANDLE, int)
  274.  
  275.     PURPOSE:  Saves instance handle and creates main window
  276.  
  277.     COMMENTS:
  278.  
  279.         This function is called at initialization time for every instance of 
  280.         this application.  This function performs initialization tasks that 
  281.         cannot be shared by multiple instances.  
  282.  
  283.         In this case, we save the instance handle in a static variable and 
  284.         create and display the main program window.  
  285.     
  286. ****************************************************************************/
  287.  
  288. BOOL InitInstance (HINSTANCE hInstance, int nCmdShow)
  289. {
  290.     HWND    hWnd;
  291.     int     sw, sh, ww, wh;
  292.  
  293.     sw = GetSystemMetrics (0);
  294.     sh = GetSystemMetrics (1);
  295.     hInst = hInstance;
  296.  
  297.     ww = (int) (sw * 0.8);
  298.     wh = (int) (sh * 0.8);
  299.     sw = (int) (sw * 0.1);
  300.     sh = (int) (sh * 0.1);
  301.     hWnd = CreateWindow ("VlibDemoClass",
  302.         "Visualib 2.0 Demonstration",
  303.         WS_OVERLAPPEDWINDOW, sw, sh, ww, wh,
  304.         NULL, NULL, hInstance, NULL);
  305.  
  306.     if (!hWnd)
  307.         return (FALSE);
  308.  
  309.     ShowWindow (hWnd, nCmdShow);
  310.     UpdateWindow (hWnd);
  311.     PostMessage (hWnd, WM_COMMAND, IDM_DEMO_WITHFRAME, 0L);
  312.     return (TRUE);
  313. }
  314.  
  315. POINT3D surf[16] = {
  316.     {-3, 0, 1}, {2, 1, 0}, {5, 0, 0}, {8, 0, 2},
  317.     {-2, 2, 3}, {1, 4, 3}, {6, 4, 1}, {7, 2, 1},
  318.     {-2, 5, 5}, {1, 7, 3}, {5, 5, 2}, {7, 6, 3},
  319.     {-2, 8, 8}, {2, 9, 0}, {4, 7, 4}, {8, 9, 9}
  320. };
  321.  
  322. real    sknot[20] = {0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 4, 4};
  323. real    tknot[20] = {0, 0, 0, 1, 1, 1, 2, 2, 3, 4, 4, 4};
  324.  
  325. void    ObjectMotion2D (HDC hdc)
  326. {
  327.     short   i;
  328.  
  329.     SelectViewer (viewer21);
  330.     PenColor (hdc, VL_BLUE);
  331.     DisplayViewerFrame (hdc, VL_CURRENT);
  332.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  333.     DisplayViewerName (hdc, VL_CURRENT, 0);
  334.  
  335.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  336.  
  337.     PenColor (hdc, VL_RED);
  338.     for (i = 0; i < 5 * animate_length; i ++) {
  339.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  340.         BrushColor (hdc, VL_GREEN);
  341.         Flower2D (hdc, 0, 0, 0, 6, 6, 10, 4.5f / 6);
  342.         BrushColor (hdc, VL_RED);
  343.         Star2D (hdc, 0, 0, 0, 4, 4, 5);
  344.         Rotate2D (6);
  345.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  346.     }
  347.     for (i = 0; i < 5 * animate_length; i ++) {
  348.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  349.         BrushColor (hdc, VL_GREEN);
  350.         Flower2D (hdc, 0, 0, 0, 6, 6, 10, 4.5f / 6);
  351.         BrushColor (hdc, VL_RED);
  352.         Star2D (hdc, 0, 0, 0, 4, 4, 5);
  353.         MoveViewer2D (VL_CURRENT, (real)0.25, 0, TRUE);
  354.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  355.     }
  356.  
  357.     for (i = 0; i < 5 * animate_length; i ++) {
  358.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  359.         BrushColor (hdc, VL_GREEN);
  360.         Flower2D (hdc, 0, 0, 0, 6, 6, 10, 4.5f / 6);
  361.         BrushColor (hdc, VL_RED);
  362.         Star2D (hdc, 0, 0, 0, 4, 4, 5);
  363.         Scale2D ((real)1.06, (real)1.06);
  364.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  365.     }
  366.     EndDoubleBuffer (&hdc, VL_CURRENT);
  367. }
  368.  
  369. void    ViewerMotion3D (HDC hdc)
  370. {
  371.     short   i, depthbuffer, shadingmethod;
  372.  
  373.     shadingmethod = ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_FLATSHADE);
  374.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, FALSE);
  375.     ShadingOption (VL_CURRENT, VL_BACKFACEREMOVAL, TRUE);
  376.     ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, FALSE);
  377.     SelectViewer (viewer31);
  378.     PenColor (hdc, VL_BLUE);
  379.     DisplayViewerFrame (hdc, VL_CURRENT);
  380.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  381.     DisplayViewerName (hdc, VL_CURRENT, 0);
  382.  
  383.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  384.     SelectMaterial (mater1);
  385.     PenColor (hdc, VL_NONE);
  386.     for (i = 0; i < 3 * animate_length; i ++) {
  387.         MoveViewer3D (VL_CURRENT, 0, 0, -10, TRUE);
  388.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  389.         if (Cube (hdc, 50, 50, 25))
  390.             UpdateDoubleBuffer (hdc, VL_CURRENT);
  391.         else
  392.             goto exit;
  393.     }
  394.     SelectMaterial (mater2);
  395.     for (i = 0; i < 3 * animate_length; i ++) {
  396.         MoveViewer3D (VL_CURRENT, 0, 5, 0, TRUE);
  397.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  398.         if (Cube (hdc, 50, 50, 25))
  399.             UpdateDoubleBuffer (hdc, VL_CURRENT);
  400.         else
  401.             goto exit;
  402.     }
  403.     SelectMaterial (mater3);
  404.     for (i = 0; i < 3 * animate_length; i ++) {
  405.         MoveViewer3D (VL_CURRENT, 5, 0, 0, TRUE);
  406.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  407.         if (Cube (hdc, 50, 50, 25))
  408.             UpdateDoubleBuffer (hdc, VL_CURRENT);
  409.         else
  410.             goto exit;
  411.     }
  412.     SelectMaterial (mater0);
  413.     for (i = 0; i < 5 * animate_length; i ++) {
  414.         RotateViewer3D (VL_CURRENT, 6, 'z', FALSE);
  415.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  416.         if (!Cube (hdc, 50, 50, 25))
  417.             goto exit;
  418.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  419.     }
  420.     SelectMaterial (mater1);
  421.     for (i = 0; i < 5 * animate_length; i ++) {
  422.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  423.         RotateViewer3D (VL_CURRENT, 6, 'y', FALSE);
  424.         if (Cube (hdc, 50, 50, 25))
  425.             UpdateDoubleBuffer (hdc, VL_CURRENT);
  426.         else
  427.             goto exit;
  428.     }
  429.     SelectMaterial (mater2);
  430.     for (i = 0; i < 5 * animate_length; i ++) {
  431.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  432.         RotateViewer3D (VL_CURRENT, 6, 'x', FALSE);
  433.         if (Cube (hdc, 50, 50, 25))
  434.             UpdateDoubleBuffer (hdc, VL_CURRENT);
  435.         else
  436.             goto exit;
  437.     }
  438. exit:
  439.     EndDoubleBuffer (&hdc, VL_CURRENT);
  440.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  441.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, shadingmethod);
  442. }
  443.  
  444. void    ObjectMotion3D (HDC hdc)
  445. {
  446.     short   i, depthbuffer, shadingmethod;
  447.  
  448.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, FALSE);
  449.     shadingmethod = ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_FLATSHADE);
  450.     SelectViewer (viewer32);
  451.     PenColor (hdc, VL_BLUE);
  452.     DisplayViewerFrame (hdc, VL_CURRENT);
  453.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  454.     DisplayViewerName (hdc, VL_CURRENT, 0);
  455.  
  456.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  457.  
  458.     SelectMaterial (mater1);
  459.     PenColor (hdc, VL_NONE);
  460.     for (i = 0; i <= 5 * animate_length; i ++) {
  461.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  462.         if (Cylinder (hdc, 30, 40, 50)) {
  463.             Rotate3D (3, 'z');
  464.             Rotate3D (6, 'x');
  465.             Rotate3D (3, 'y');
  466.             UpdateDoubleBuffer (hdc, VL_CURRENT);
  467.         }
  468.         else
  469.             break;
  470.     }
  471.     EndDoubleBuffer (&hdc, VL_CURRENT);
  472.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  473.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, shadingmethod);
  474. }
  475.  
  476. void    ViewerZoom3D (HDC hdc)
  477. {
  478.     short   i, depthbuffer, shadingmethod;
  479.     POINT3D p = {0, 0, 0};
  480.  
  481.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, FALSE);
  482.     shadingmethod = ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_FLATSHADE);    ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, FALSE);
  483.     SelectViewer (viewer33);
  484.     PenColor (hdc, VL_RED);
  485.     DisplayViewerFrame (hdc, VL_CURRENT);
  486.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  487.     DisplayViewerName (hdc, VL_CURRENT, 0);
  488.  
  489.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  490.  
  491.     SelectMaterial (mater2);
  492.     PenColor (hdc, VL_NONE);
  493.     for (i = 0; i < 5 * animate_length; i ++) {
  494.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  495.         if (Cone (hdc, 3, 5, 10)) {
  496.             ZoomViewer3D (VL_CURRENT, 1.05f);
  497.             UpdateDoubleBuffer (hdc, VL_CURRENT);
  498.         }
  499.         else
  500.             break;
  501.     }
  502.     EndDoubleBuffer (&hdc, VL_CURRENT);
  503.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  504.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, shadingmethod);
  505. }
  506.  
  507. void    OrthoProject3D (HDC hdc)
  508. {
  509.     POINT3D p = {3, -1, -4};
  510.  
  511.     PenColor (hdc, VL_RED);
  512.     DisplayViewerFrame (hdc, viewer34);
  513.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  514.     DisplayViewerName (hdc, viewer34, 0);
  515.     SelectViewer (viewer34);
  516.     SelectMaterial (mater3);
  517.     PenColor (hdc, VL_NONE);
  518.     Ellipsoid (hdc, 3, 4, 5);
  519. }
  520.  
  521. void    RotateStar (HDC hdc)
  522. {
  523.     short   i;
  524.     BOOL    depthbuffer, shadingmethod;
  525.  
  526.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, FALSE);
  527.     shadingmethod = ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_FLATSHADE);
  528.     PenColor (hdc, VL_RED);
  529.     DisplayViewerFrame (hdc, viewer35);
  530.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  531.     DisplayViewerName (hdc, viewer35, 0);
  532.  
  533.     SelectViewer (viewer35);
  534.     BeginDoubleBuffer (&hdc, viewer35);
  535.     PenColor (hdc, VL_NONE);
  536.     for (i = 0; i < 5 * animate_length; i ++) {
  537.         ClearViewer (hdc, viewer35, VL_GRAY);
  538.         if (SolidStar (hdc, 5, 20, 20, 5)) {
  539.             MoveViewer3D (viewer35, 0, 0, (real)-0.5, TRUE);
  540.             Rotate3D (6 * i, 'z');
  541.             UpdateDoubleBuffer (hdc, viewer35);
  542.         }
  543.         else
  544.             break;
  545.     }
  546.     EndDoubleBuffer (&hdc, viewer35);
  547.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  548.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, shadingmethod);
  549. }
  550.  
  551. void CompositeDemo2D (HDC hdc)
  552. {
  553.     RECT    orgport, newport;
  554.  
  555.     SelectViewer (viewer22);
  556.     PenColor (hdc, VL_BLACK);
  557.     DisplayViewerFrame (hdc, VL_CURRENT);
  558.     USFlag (hdc);
  559.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  560.     DisplayViewerName (hdc, VL_CURRENT, 0);
  561.  
  562.     GetViewport (VL_CURRENT, &orgport);
  563.     SetRect (&newport, 350, 230, 410, 260);
  564.     SetViewport (VL_CURRENT, newport);
  565.     USFlag (hdc);
  566.     PenColor (hdc, VL_BLACK);
  567.     DisplayViewerFrame (hdc, VL_CURRENT);
  568.     SetViewport (VL_CURRENT, orgport);
  569. }
  570.  
  571. void    RotateSpring (HDC hdc)
  572. {
  573.     short   i, depthbuffer, shadingmethod;
  574.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, FALSE);
  575.     shadingmethod = ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_FLATSHADE);
  576.     SelectViewer (viewer31);
  577.     PenColor (hdc, VL_BLUE);
  578.     DisplayViewerFrame (hdc, VL_CURRENT);
  579.     SetViewerName (VL_CURRENT, "3D Curve");
  580.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  581.     DisplayViewerName (hdc, VL_CURRENT, 0);
  582.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  583.     Scale3D (20, 20, 20);
  584.     for (i = 0; i < 5 * animate_length; i ++) {
  585.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  586.         PenColor (hdc, VL_BLUE);
  587.         Spring (hdc, 3, 2, 0.5f);
  588.         Translate3D (0.05f, 0, 0);
  589.         Rotate3D (-6, 'y');
  590.         PushTransformation3D (NULL);
  591.         SelectMaterial (mater0);
  592.         PenColor (hdc, VL_NONE);
  593.         Rotate3D (6 * i, 'z');
  594.         Translate3D (0, 2, 0);
  595.         Rotate3D (3, 'y');
  596.         if (!Tetrahedron (hdc, 1))
  597.             break;
  598.         PushTransformation3D (NULL);
  599.         SelectMaterial (mater1);
  600.         Rotate3D (6, 'x');
  601.         Translate3D (0, 0, 2);
  602.         Rotate3D (3 * i, 'z');
  603.         if (!Octahedron (hdc, 1))
  604.             break;
  605.         PopTransformation3D (NULL);
  606.         PopTransformation3D (NULL);
  607.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  608.     }
  609.     EndDoubleBuffer (&hdc, VL_CURRENT);
  610.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  611.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, shadingmethod);
  612. }
  613.  
  614. void    RotateFrame (HDC hdc)
  615. {
  616.     short   i;
  617.     COORD    point[] = {0, 0, 0, 1, 1, -1, 1, 1, 1, -1, -1, 1, -1, 1, -1,
  618.         1, -1, -1, 1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1,
  619.         -1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, 1,
  620.         0, 0, 0, 1, -1, 1, -1, -1, -1, 0, 0, 0};
  621.     
  622.     PenColor (hdc, VL_BLUE);
  623.     SelectViewer (viewer32);
  624.     DisplayViewerFrame (hdc, VL_CURRENT);
  625.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  626.     Scale3D (30, 30, 30);
  627.     PenColor (hdc, VL_BLUE);
  628.     for ( i = 0; i < 5 * animate_length; i++) {
  629.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  630.         Polyline3D (hdc, VL_3D, point, 19);
  631.         Rotate3D (6, 'z');
  632.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  633.     }
  634.     EndDoubleBuffer (&hdc, VL_CURRENT);
  635. }
  636.  
  637. void    RotateSurface (HDC hdc)
  638. {
  639.     short   i, depthbuffer, shadingmethod;
  640.  
  641.     shadingmethod = ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_FLATSHADE);
  642.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, FALSE);
  643.     ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, TRUE);
  644.     SelectViewer (viewer35);
  645.     PenColor (hdc, VL_BLUE);
  646.     DisplayViewerFrame (hdc, VL_CURRENT);
  647.     SetViewerName (VL_CURRENT, "NURBS Surface");
  648.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  649.     DisplayViewerName (hdc, VL_CURRENT, 0);
  650.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  651.     PenColor (hdc, VL_MAGENTA);
  652.     ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, TRUE);
  653.     for (i = 0; i < 5 * animate_length; i++) {
  654.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  655.         if (!NURBSSurface (hdc, VL_3D, (LPCOORD) surf, 4, 4, sknot, tknot, 8, 8))
  656.             break;
  657.         Rotate3D (6, 'z');
  658.         Rotate3D (12, 'x');
  659.         Rotate3D (3, 'y');
  660.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  661.     }
  662.     EndDoubleBuffer (&hdc, VL_CURRENT);
  663.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  664.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, shadingmethod);
  665.     ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, FALSE);
  666. }
  667.  
  668. void    RotateDodecahedron (HDC hdc)
  669. {
  670.     short   i, depthbuffer, shadingmethod;
  671.  
  672.     shadingmethod = ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_FLATSHADE);
  673.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, FALSE);
  674.     ShadingOption (VL_CURRENT, VL_BACKFACEREMOVAL, TRUE);
  675.     ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, FALSE);
  676.     SelectViewer (viewer33);
  677.     PenColor (hdc, VL_RED);
  678.     DisplayViewerFrame (hdc, VL_CURRENT);
  679.     SetViewerName (VL_CURRENT, "Dodecahedron");
  680.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  681.     DisplayViewerName (hdc, VL_CURRENT, 0);
  682.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  683.     Scale3D (6, 6, 6);
  684.     BrushColor (hdc, VL_BROWN);
  685.     PenColor (hdc, VL_NONE);
  686.     for (i = 0; i < 5 * animate_length; i ++) {
  687.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  688.         if (!Dodecahedron (hdc, 0.5f))
  689.             break;
  690.         Translate3D (0, (real)0.1, 0);
  691.         Rotate3D (6, 'z');
  692.         UpdateDoubleBuffer (hdc, VL_CURRENT);
  693.     }
  694.     EndDoubleBuffer (&hdc, VL_CURRENT);
  695.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  696.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, shadingmethod);
  697. }
  698.  
  699. void    RotateIcosahedron (HDC hdc)
  700. {
  701.     short   i, depthbuffer, shadingmethod;
  702.  
  703.     shadingmethod = ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_FLATSHADE);
  704.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, FALSE);
  705.     ShadingOption (VL_CURRENT, VL_BACKFACEREMOVAL, TRUE);
  706.     ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, FALSE);
  707.     SelectViewer (viewer34);
  708.     PenColor (hdc, VL_RED);
  709.     DisplayViewerFrame (hdc, VL_CURRENT);
  710.     SetViewerName (VL_CURRENT, "Icosahedron");
  711.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  712.     DisplayViewerName (hdc, VL_CURRENT, 0);
  713.     BeginDoubleBuffer (&hdc, VL_CURRENT);
  714.     Scale3D (3, 3, 3);
  715.     BrushColor (hdc, VL_YELLOW);
  716.     PenColor (hdc, VL_NONE);
  717.     for (i = 0; i < 5 * animate_length; i ++) {
  718.         ClearViewer (hdc, VL_CURRENT, VL_GRAY);
  719.         if (Icosahedron (hdc, 1)) {
  720.             Rotate3D (3, 'y');
  721.             Translate3D ((real)0.1, 0, 0);
  722.             Rotate3D (6, 'z');
  723.             UpdateDoubleBuffer (hdc, VL_CURRENT);
  724.         }
  725.         else
  726.             break;
  727.     }
  728.     EndDoubleBuffer (&hdc, VL_CURRENT);
  729.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  730.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, shadingmethod);
  731. }
  732.  
  733. void    Surfaces (HDC hdc, WORD cmd)
  734. {
  735.     SelectViewer (viewer30);
  736.     ClearDepthBuffer (0xffff);
  737.     if (ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_INQUIRE) == VL_WIREFRAME) {
  738.         PenColor (hdc, VL_RED);
  739.     }
  740.     else {
  741.         ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, TRUE);
  742.         PenColor (hdc, VL_NONE);
  743.     }
  744.  
  745.     PushTransformation3D (NULL);
  746.     switch (cmd) {
  747.         case IDM_SURFACE_BEZIER:
  748.         {
  749.             POINT3D surf[16] = {
  750.                 {0, 6, 3}, {2, 6, 0}, {4, 6, 2}, {6, 6, 0},
  751.                 {0, 4, 0}, {2, 4, 5}, {4, 4, 0}, {6, 4, 6},
  752.                 {0, 2, 5}, {2, 2, 0}, {4, 2, 6}, {6, 2, 0},
  753.                 {0, 0, 0}, {2, 0, 3}, {4, 0, 0}, {6, 0, 3}};
  754.  
  755.             Scale3D (5, 5, 5);
  756.             BezierSurface (hdc, VL_3D, (LPCOORD) surf, 16, 16);
  757.             PenColor (hdc, VL_GREEN);
  758.             Net3D (hdc, VL_3D, (LPCOORD) surf, 4, 4);
  759.             PolyMark3D (hdc, VL_3D, (LPCOORD) surf, 16, 2, 2, VL_CIRCLEMARK);
  760.             break;
  761.         }
  762.         case IDM_SURFACE_HERMIT:
  763.         {
  764.             POINT3D surf[16] = {
  765.                 {0, 0, 0}, {0, 6, 0}, {0, 6, 6}, {0, 6, -2},
  766.                 {6, 0, 0}, {6, 6, 0}, {0, 2, 2}, {0, 6, -2},
  767.                 {2, 0, 2}, {2, 0, 2}, {0, 0, 0}, {0, 0, 0},
  768.                 {2, 0, 2}, {2, 0, 2}, {0, 0, 0}, {0, 0, 0}};
  769.  
  770.             Scale3D (5, 5, 5);
  771.             HermitSurface (hdc, VL_3D, (LPCOORD) surf, 16, 16);
  772.             PenColor (hdc, VL_GREEN);
  773. //            Net3D (hdc, VL_3D, (LPCOORD) surf, 4, 4);
  774. //            PolyMark3D (hdc, VL_3D, (LPCOORD) surf, 16, 2, 2, VL_DIAMONDMARK);
  775.             break;
  776.         }
  777.         case IDM_SURFACE_BSPLINE:
  778.         {
  779.             break;
  780.         }
  781.         case IDM_SURFACE_NURBS:
  782.         {
  783.             POINT3D surf[36] = {
  784.                 {0,0,0},{1,0,0},{2,0,0},{3,0,0},{4,0,0},{5,0,0},
  785.                 {0,1,0},{1,1,0},{2,1,0},{3,1,0},{4,1,0},{5,1,0},
  786.                 {0,2,0},{1,2,0},{2,2,9},{3,2,9},{4,2,0},{5,2,0},
  787.                 {0,3,0},{1,3,0},{2,3,9},{3,3,9},{4,3,0},{5,3,0},
  788.                 {0,4,0},{1,4,0},{2,4,0},{3,4,0},{4,4,0},{5,4,0},
  789.                 {0,5,0},{1,5,0},{2,5,0},{3,5,0},{4,5,0},{5,5,0}};
  790.             real    sknot[20] = {0,0,0,1,2,3,3,3};
  791.             real    tknot[20] = {0,0,0,1,2,3,3,3};
  792.  
  793.             SwitchLight (light0, FALSE);
  794.             SwitchLight (light1, FALSE);
  795.             SwitchLight (light4, TRUE);
  796.             Scale3D (10, 10, 5);
  797.             Translate3D (-3, -2, 0);
  798.             NURBSSurface (hdc, VL_3D, (LPCOORD) surf, 6, 6, sknot, tknot, 4, 4);
  799.             PenColor (hdc, VL_GREEN);
  800.             Net3D (hdc, VL_3D, (LPCOORD) surf, 6, 6);
  801.             PolyMark3D (hdc, VL_3D, (LPCOORD) surf, 36, 2, 2, VL_BOXMARK);
  802.             break;
  803.         }
  804.         case IDM_SURFACE_COONSPATCH:
  805.         {
  806.             POINT3D    point[] = {{0,0,4},{1,-2,3},{2,-2,2},{3,0,1},
  807.                                {4,0,0},{4,1,0},{4,2,0},{4,3,0},
  808.                                {4,4,0},{3,4,0},{2,4,0},{1,4,0},
  809.                                {0,4,0},{0,3,1},{-2,2,2},{-2,1,3}};
  810.             Scale3D (5, 5, 5);
  811.             CoonsPatch (hdc, VL_3D, (LPCOORD) point, 5, 5);
  812. /*
  813.             POINT3D    cpu0[]={{0,0,4},{1,0,3},{2,0,2},{3,0,1},{4,0,0}};
  814.             POINT3D    cpu1[]={{0,4,0},{1,4,0},{2,4,0},{3,4,0},{4,4,0}};
  815.             POINT3D    cpv0[]={{0,0,4},{0,1,3},{0,2,2},{0,3,1},{0,4,0}};
  816.             POINT3D    cpv1[]={{4,0,0},{4,1,0},{4,2,0},{4,3,0},{4,4,0}};
  817.             Scale3D (5, 5, 2);
  818.             CoonsPatch (hdc, cpu0, cpu1, 5, cpv0, cpv1, 5);
  819. */
  820.             break;
  821.         }
  822.     }
  823.     PopTransformation3D (NULL);
  824. }
  825.  
  826. void    Curves3D (HDC hdc, WORD cmd)
  827. {
  828.     POINT3D curve[16] = {
  829.         {0, 0, 0}, {20, -30, 30}, {40, 30, -30}, {60, 0, 0},
  830.         {0, 4, 0}, {2, 4, 5}, {4, 4, 0}, {6, 4, 6},
  831.         {0, 2, 5}, {2, 2, 0}, {4, 2, 6}, {6, 2, 0},
  832.         {0, 0, 0}, {2, 0, 3}, {4, 0, 0}, {6, 0, 3}};
  833.     COORD    point[] = {0, 0, 0, 1, 1, 1, 1, 0, 2, 0, 3, 1, 4, 1, 4, 0};
  834.     real Knot1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  835.     real Knot2[] = {0, 0, 0, 1, 1, 1, 4, 5, 5, 5};
  836.     real Knot3[] = {0, 0, 0, 1, 1, 1, 1, 2, 3, 4, 5, 6};
  837.     real Knot4[] = {0, 0, 0, 1, 3, 5, 7, 9, 10, 15};
  838.  
  839.     SelectViewer (viewer30);
  840.     ClearDepthBuffer (0xffff);
  841.     PushTransformation3D (NULL);
  842.     switch (cmd) {
  843.         case IDM_3DCURVE_SPRING:
  844.             MarkPosition3D (hdc, 0, 0, 0, 20, VL_ORIGIN);
  845.             PenColor (hdc, VL_BLUE);
  846.             Spring3D (hdc, 30, 10, 10, 40);
  847.             PenColor (hdc, VL_YELLOW);
  848.             Rotate3D (90, 'y');
  849.             Spring3D (hdc, 30, 10, 10, 40);
  850.             PenColor (hdc, VL_GREEN);
  851.             Rotate3D (-90, 'x');
  852.             Spring3D (hdc, 30, 10, 10, 40);
  853.             SetViewerName (VL_CURRENT, "3D Springs");
  854.             break;
  855.         case IDM_3DCURVE_SPIRAL:
  856.             MarkPosition3D (hdc, 0, 0, 0, 20, VL_ORIGIN);
  857.             PenColor (hdc, VL_GREEN);
  858.             Spiral3D (hdc, 0, 10, 0, 0.5f, 40);
  859.             PenColor (hdc, VL_YELLOW);
  860.             Rotate3D (90, 'y');
  861.             Spiral3D (hdc, 0, 10, 0, 0.5f, 40);
  862.             PenColor (hdc, VL_RED);
  863.             Rotate3D (-90, 'x');
  864.             Spiral3D (hdc, 0, 10, 0, 0.5f, 40);
  865.             SetViewerName (VL_CURRENT, "3D Spiral");
  866.             break;
  867.         case IDM_3DCURVE_BEZIER:
  868.             PenColor (hdc, VL_GREEN);
  869.             BezierCurve3D (hdc, VL_3D, (LPCOORD) curve);
  870.             SetViewerName (VL_CURRENT, "3D Bezier Curve");
  871.             break;
  872.         case IDM_3DCURVE_HERMIT:
  873.             PenColor (hdc, VL_GREEN);
  874.             HermitCurve3D (hdc, VL_3D, (LPCOORD) curve);
  875.             SetViewerName (VL_CURRENT, "3D Hermit Curve");
  876.             break;
  877.         case IDM_3DCURVE_BSPLINE:
  878.             PenColor (hdc, VL_GREEN);
  879.             BSplineCurve3D (hdc, VL_3D, (LPCOORD) curve, 16);
  880.             SetViewerName (VL_CURRENT, "3D B-Spline Curve");
  881.             break;
  882.         case IDM_3DCURVE_NURBS:
  883.             PenColor (hdc, VL_GREEN);
  884.             Scale3D (5, 5, 5);
  885.             NURBSCurve3D (hdc, VL_2D, point, 8, Knot3);
  886.             SetViewerName (VL_CURRENT, "3D NURBS Curve");
  887.             break;
  888.         case IDM_3DCURVE_QBEZIER:
  889.         {
  890.             COORD    point[] = {0, 0, 0, 1, 1, 1, 1, 0, 2, 0, 3, 1, 4, 1, 4, 0};
  891.             SetViewerName (VL_CURRENT, "3D Quadratic Bezier Curve");
  892.             Scale3D (12, 12, 12);
  893.             PenColor (hdc, VL_RED);
  894.             Polyline3D (hdc, VL_2D, point, 3);
  895.             PenColor (hdc, VL_BLUE);
  896.             PolyMark3D (hdc, VL_2D, point, 3, 3, 3, VL_DIAMONDMARK);
  897.             PenColor (hdc, VL_GREEN);
  898.             QBezierCurve3D (hdc, VL_2D, point);
  899.             SetViewerName (VL_CURRENT, "3D Quadratic Bezier Curve");
  900.             break;
  901.         }
  902.         case IDM_3DCURVE_QBSPLINE:
  903.         {
  904.             COORD    point[] = {0, 0, 0, 1, 1, 1, 1, 0, 2, 0, 3, 1, 4, 1, 4, 0};
  905.             SetViewerName (VL_CURRENT, "3D Quadratic B-Spline Curve");
  906.             Scale3D (12, 12, 12);
  907.             PenColor (hdc, VL_RED);
  908.             Polyline3D (hdc, VL_2D, point, 8);
  909.             PenColor (hdc, VL_BLUE);
  910.             PolyMark3D (hdc, VL_2D, point, 8, 3, 3, VL_DIAMONDMARK);
  911.             PenColor (hdc, VL_GREEN);
  912.             QBSplineCurve3D (hdc, VL_2D, point, 8);
  913.             break;
  914.         }
  915.         case IDM_3DCURVE_QNURBS:
  916.         {
  917.             COORD    point[] = {0, 0, 0, 1, 1, 1, 1, 0, 2, 0, 3, 1, 4, 1, 4, 0};
  918.             real knot[] = {0, 0, 0, 1, 1, 1, 1, 2, 3, 4, 5, 6};
  919.             
  920.             SetViewerName (VL_CURRENT, "3D Quadratic NURBS Curve");
  921.             Scale3D (12, 12, 12);
  922.             PenColor (hdc, VL_RED);
  923.             Polyline3D (hdc, VL_2D, point, 8);
  924.             PenColor (hdc, VL_BLUE);
  925.             PolyMark3D (hdc, VL_2D, point, 8, 3, 3, VL_DIAMONDMARK);
  926.             PenColor (hdc, VL_GREEN);
  927.             QNURBSCurve3D (hdc, VL_2D, point, 8, knot);
  928.             break;
  929.         }
  930.         case IDM_3DCURVE_CATMULLROM:
  931. //          CatmullRomSpline3D (hdc, cp3, n);
  932.             break;
  933.         case IDM_3DSHAPE_ELLIPSOID:
  934.             Ellipsoid (hdc, 20, 30, 40);
  935.             break;
  936.         case IDM_3DSHAPE_ELLIPTICPARAB:
  937. //          EllipticParaboloid (hdc, height, count1, count2);
  938.             break;
  939.         case IDM_3DSHAPE_HYPERBOLOID1:
  940. //          Hyperboloid1 (hdc, z1, z2, count1, count2);
  941.             break;
  942.         case IDM_3DSHAPE_HYPERBOLOID2:
  943. //          Hyperboloid2 (hdc, height, count1, count2);
  944.             break;
  945.         case IDM_3DSHAPE_HYPERBOLICPARAB:
  946. //          HyperbolicParaboloid (hdc, x1, x2, y1, y2, count1, count2);
  947.             break;
  948.     }
  949.     PopTransformation3D (NULL);
  950. }
  951.  
  952. VOIDED    ShowSolidPrimitives (HDC hdc, WORD cmd)
  953. {
  954.     ClearDepthBuffer (0xffff);
  955.     switch (cmd) {
  956.         case IDM_SOLID_TUBE:
  957.             SetViewerName (VL_CURRENT, "Tube and Ring");
  958.             Tube (hdc, 15, 20, 2, 30);
  959.             break;
  960.         case IDM_SOLID_TORUS:
  961.             SetViewerName (VL_CURRENT, "Torus and Wedged Torus");
  962.             TranslateTo3D (-20, 20, 0);
  963.             if (!Torus (hdc, 15, 5))
  964.                 break;
  965.             TranslateTo3D (20, -20, 0);
  966.             WedgedTorus (hdc, 15, 5, 90, 360, 180, 90);
  967.             break;
  968.         case IDM_SOLID_SPHERE:
  969.             SetViewerName (VL_CURRENT, "Sphere and Wedged Sphere");
  970.             WedgedSphere (hdc, 20, 20, 30, 90, 0, 45, 135);
  971.             break;
  972.         case IDM_SOLID_ELLIPSOID:
  973.             SetViewerName (VL_CURRENT, "Ellipsoid");
  974.             PenColor (hdc, VL_NONE);
  975.             Ellipsoid (hdc, 20, 40, 30);
  976.             break;
  977.         case IDM_SOLID_CYLINDER:
  978.             SetViewerName (VL_CURRENT, "Cylinder and Wedge");
  979.             if (!WedgedCylinder (hdc, 10, 20, 30, 0.7f, 90, 0))
  980.                 break;
  981.             TranslateTo3D (30, -30, 0);
  982.             if (!Wedge (hdc, 20, 10, 5, 45, 180))
  983.                 break;
  984.             TranslateTo3D (-30, 30, 0);
  985.             Wedge (hdc, 20, 10, 5, 180, 45);
  986.             break;
  987.         case IDM_SOLID_CONE:
  988.             SetViewerName (VL_CURRENT, "Cone and Wedged Cone");
  989.             if (!WedgedCone (hdc, 10, 20, 30, 90, 0))
  990.                 break;
  991.             TranslateTo3D (30, -30, 0);
  992.             if (!WedgedCone (hdc, 20, 10, 30, 110, 0))
  993.                 break;
  994.             TranslateTo3D (-30, 30, 0);
  995.             WedgedCone (hdc, 20, 10, 30, 180, 45);
  996.             break;
  997.         case IDM_SOLID_TETRAHEDRON:
  998.             SetViewerName (VL_CURRENT, "Tetrahedron (4 facets)");
  999.             Tetrahedron (hdc, 20);
  1000.             MarkPosition3D (hdc, 0, 0, 0, 10, VL_CROSSHAIR);
  1001.             break;
  1002.         case IDM_SOLID_OCTAHEDRON:
  1003.             SetViewerName (VL_CURRENT, "Octahedron (8 facets)");
  1004.             Octahedron (hdc, 20);
  1005.             MarkPosition3D (hdc, 0, 0, 0, 20, VL_ORIGIN);
  1006.             break;
  1007.         case IDM_SOLID_DODECAHEDRON:
  1008.             SetViewerName (VL_CURRENT, "Dodecahedron (12 facets)");
  1009.             Dodecahedron (hdc, 20);
  1010.             MarkPosition3D (hdc, 0, 0, 0, 10, VL_ORIGIN);
  1011.             break;
  1012.         case IDM_SOLID_ICOSAHEDRON:
  1013.             SetViewerName (VL_CURRENT, "Icosahedron (20 facets)");
  1014.             Icosahedron (hdc, 20);
  1015.             MarkPosition3D (hdc, 0, 0, 0, 10, VL_ORIGIN);
  1016.             break;
  1017.         case IDM_SOLID_FRUSTUM:
  1018.             SetViewerName (VL_CURRENT, "Frustum");
  1019.             Frustum (hdc, 20, 30, 10, 20, 20);
  1020.             break;
  1021.         case IDM_SOLID_RIDGE:
  1022.             SetViewerName (VL_CURRENT, "Ridge");
  1023.             Ridge (hdc, 20, 30, 10, 20);
  1024.             break;
  1025.         case IDM_SOLID_BOX:
  1026.             SetViewerName (VL_CURRENT, "Box");
  1027.             Cube (hdc, 40, 40, 20);
  1028.             break;
  1029.         case IDM_SOLID_STAR:
  1030.             SetViewerName (VL_CURRENT, "Solid Star");
  1031.             SolidStar (hdc, 5, 20, 20, 10);
  1032.             break;
  1033.         case IDM_SOLID_FLOWER:
  1034.             SetViewerName (VL_CURRENT, "Solid Flower");
  1035.             SolidFlower (hdc, 8, 0.666f, 30, 30, 10);
  1036.             break;
  1037.     }
  1038.     PenColor (hdc, VL_BLUE);
  1039.     DisplayViewerFrame (hdc, VL_CURRENT);
  1040.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  1041.     DisplayViewerName (hdc, VL_CURRENT, FALSE);
  1042. }
  1043.  
  1044. void    ShadingSettings (HWND hwnd, WORD cmd)
  1045. {
  1046.     COLORREF    color;
  1047.     FARPROC        lpProc;
  1048.  
  1049.     switch (cmd) {
  1050.         case IDM_OPTION_PREVIEW:
  1051.         {
  1052.             RECT rect = {50, 50, 100, 100};
  1053.             HDC    hdc;
  1054.  
  1055.             SelectViewer (viewer30);
  1056.             hdc = GetDC (hwnd);
  1057.             ShadingPreview (hdc, &rect, 40, 173);
  1058.             ReleaseDC (hwnd, hdc);
  1059.             break;
  1060.         }
  1061.         case IDM_GLOBAL_AMBIENT:
  1062.             color = ShadingColor (VL_CURRENT, VL_GLOBALAMBIENT, VL_INQUIRE);
  1063.             color = SelectColor (color);
  1064.             ShadingColor (VL_CURRENT, VL_GLOBALAMBIENT, color);
  1065.             break;
  1066.         case IDM_OPTION_BACKCOLOR:
  1067.         {
  1068.             HBRUSH    hbrush;
  1069.  
  1070.             backcolor = SelectColor (backcolor);
  1071.             hbrush = GetClassWord (hwnd, GCW_HBRBACKGROUND);
  1072.             DeleteObject (hbrush);
  1073.             hbrush = CreateSolidBrush (backcolor);
  1074.             SetClassWord (hwnd, GCW_HBRBACKGROUND, hbrush);
  1075.             InvalidateRect (hwnd, NULL, TRUE);
  1076.             UpdateWindow (hwnd);
  1077.             break;
  1078.         }
  1079.         case IDM_OPTION_REDRAW:
  1080.             InvalidateRect (hwnd, NULL, TRUE);
  1081.             UpdateWindow (hwnd);
  1082.             break;
  1083.         case IDM_OPTION_SHADEMODE:
  1084.              lpProc = MakeProcInstance (DlgShading, hInst);
  1085.             DialogBox (hInst, "DLGSHADING", hwnd, lpProc);
  1086.             FreeProcInstance (lpProc);
  1087.             break;
  1088.         case IDM_SELECT_M1:
  1089.             SelectMaterial (mater0);
  1090.             lpProc = MakeProcInstance (DlgMaterial, hInst);
  1091.             DialogBox (hInst, "DLGMATERIAL", hwnd, lpProc);
  1092.             FreeProcInstance (lpProc);
  1093.             break;
  1094.         case IDM_SELECT_M2:
  1095.             SelectMaterial (mater1);
  1096.             lpProc = MakeProcInstance (DlgMaterial, hInst);
  1097.             DialogBox (hInst, "DLGMATERIAL", hwnd, lpProc);
  1098.             FreeProcInstance (lpProc);
  1099.             break;
  1100.         case IDM_SELECT_M3:
  1101.             SelectMaterial (mater2);
  1102.             lpProc = MakeProcInstance (DlgMaterial, hInst);
  1103.             DialogBox (hInst, "DLGMATERIAL", hwnd, lpProc);
  1104.             FreeProcInstance (lpProc);
  1105.             break;
  1106.         case IDM_SELECT_M4:
  1107.             SelectMaterial (mater3);
  1108.             lpProc = MakeProcInstance (DlgMaterial, hInst);
  1109.             DialogBox (hInst, "DLGMATERIAL", hwnd, lpProc);
  1110.             FreeProcInstance (lpProc);
  1111.             break;
  1112.         case IDM_SELECT_L1:
  1113.             SelectLight (light0);
  1114.             lpProc = MakeProcInstance (DlgLightSetup, hInst);
  1115.             DialogBox (hInst, "DLGLIGHTSETUP", hwnd, lpProc);
  1116.             FreeProcInstance (lpProc);
  1117.             break;
  1118.         case IDM_SELECT_L2:
  1119.             SelectLight (light1);
  1120.             lpProc = MakeProcInstance (DlgLightSetup, hInst);
  1121.             DialogBox (hInst, "DLGLIGHTSETUP", hwnd, lpProc);
  1122.             FreeProcInstance (lpProc);
  1123.             break;
  1124.         case IDM_SELECT_L3:
  1125.             SelectLight (light2);
  1126.             lpProc = MakeProcInstance (DlgLightSetup, hInst);
  1127.             DialogBox (hInst, "DLGLIGHTSETUP", hwnd, lpProc);
  1128.             FreeProcInstance (lpProc);
  1129.             break;
  1130.         case IDM_SELECT_L4:
  1131.             SelectLight (light3);
  1132.             lpProc = MakeProcInstance (DlgLightSetup, hInst);
  1133.             DialogBox (hInst, "DLGLIGHTSETUP", hwnd, lpProc);
  1134.             FreeProcInstance (lpProc);
  1135.             break;
  1136.         case IDM_OPTION_TEXTURE:
  1137.             lpProc = MakeProcInstance (DlgTexture, hInst);
  1138.             DialogBox (hInst, "DLGTEXTURE", hwnd, lpProc);
  1139.             FreeProcInstance (lpProc);
  1140.             break;
  1141.     }
  1142. }
  1143.  
  1144. WORD    halign = TA_CENTER;
  1145. WORD    valign = TA_BASELINE;
  1146.  
  1147. VOIDED    ShowTextPrimitives (HDC hdc, int func)
  1148. {
  1149.     char    str[40];
  1150.  
  1151.     wsprintf (str, "Visualib\nAdvanced\nTechnology");
  1152.     switch (func) {
  1153.         case IDM_TEXT_2D:
  1154.             SelectViewer (viewer20);
  1155.             TextParameter (VL_TEXT_HEIGHT, 4);
  1156.             BrushColor (hdc, VL_RED);
  1157.             PenColor (hdc, VL_GREEN);
  1158.             SetTextAlign (hdc, halign | valign);
  1159.             Text2D (hdc, 0, 0, 0, str);
  1160.             SetViewerName (VL_CURRENT, "2D Horizontal Text");
  1161.             break;
  1162.         case IDM_TEXT_3D:
  1163.             SelectViewer (viewer30);
  1164.             MarkPosition3D (hdc, 0, 0, 0, 40, VL_ORIGIN);
  1165.             PushTransformation3D (NULL);
  1166.             TextParameter (VL_TEXT_HEIGHT, 15);
  1167.             BrushColor (hdc, VL_YELLOW);
  1168.             PenColor (hdc, VL_BLUE);
  1169.             SetTextAlign (hdc, TA_LEFT | TA_BOTTOM);
  1170.             Text3D (hdc, 3, 1, 0, str);
  1171.             PushTransformation3D (NULL);
  1172.             Rotate3D (90, 'y');
  1173.             SetTextAlign (hdc, TA_RIGHT | TA_BOTTOM);
  1174.             Text3D (hdc, -3, 1, 0, str);
  1175.             PopTransformation3D (NULL);
  1176.             Rotate3D (-90, 'x');
  1177.             SetTextAlign (hdc, TA_TOP | TA_LEFT);
  1178.             Text3D (hdc, 3, -1, 0, str);
  1179.             PopTransformation3D (NULL);
  1180.             SetViewerName (VL_CURRENT, "3D Horizontal Text");
  1181.             break;
  1182.         case IDM_TEXT_SOLID:
  1183.             SelectViewer (viewer30);
  1184.             TextParameter (VL_TEXT_HEIGHT, 30);
  1185.             ClearDepthBuffer (0xffff);
  1186.             TextParameter (VL_TEXT_THICKNESS, 8);
  1187.             SelectMaterial (mater0);
  1188.             PushTransformation3D (NULL);
  1189.             Rotate3D (135, 'z');
  1190.             Rotate3D (30, 'x');
  1191.             SetTextAlign (hdc, TA_BASELINE | TA_CENTER);
  1192.             SolidText (hdc, str);
  1193.             PopTransformation3D (NULL);
  1194.             SetViewerName (VL_CURRENT, "Solid Text");
  1195.             break;
  1196.     }
  1197.     PenColor (hdc, VL_BLUE);
  1198.     DisplayViewerFrame (hdc, VL_CURRENT);
  1199.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  1200.     DisplayViewerName (hdc, VL_CURRENT, FALSE);
  1201. }
  1202.  
  1203. void    ProcessWindowPaint (HWND hwnd)
  1204. {
  1205.     PAINTSTRUCT ps;
  1206.     HDC         hdc;
  1207.  
  1208.     hdc = BeginPaint (hwnd, &ps);
  1209.     SelectPalette (hdc, hpal, 0);
  1210.     RealizePalette (hdc);
  1211.     FunctionDemos (hdc);
  1212.     EndPaint (hwnd, &ps);
  1213. }
  1214.  
  1215. void    SpotlightDemo (HDC hdc)
  1216. {
  1217.     SelectViewer (viewer30);
  1218.     PenColor (hdc, VL_BLUE);
  1219.     DisplayViewerFrame (hdc, VL_CURRENT);
  1220.     SetViewerName (VL_CURRENT, "Spot Lights Demo");
  1221.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  1222.     DisplayViewerName (hdc, VL_CURRENT, FALSE);
  1223.     ShadingOption (VL_CURRENT, VL_TWOSIDESHADE, FALSE);
  1224.     ShadingOption (VL_CURRENT, VL_BACKFACEREMOVAL, TRUE);
  1225.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, TRUE);
  1226.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_PHONGSHADE);
  1227.     ClearDepthBuffer (0xffff);
  1228.     SelectMaterial (mater0);
  1229.     SwitchLight (light4, TRUE);
  1230.     SwitchLight (light5, TRUE);
  1231.     SwitchLight (light6, TRUE);
  1232.     SolidFlower (hdc, 8, 0.666f, 30, 30, 10);
  1233. }
  1234.  
  1235. void    ImageMappingDemo (HDC hdc)
  1236. {
  1237.     COORD    point[12];
  1238.     static BOOL    LoadImage = TRUE;
  1239.  
  1240.     if (LoadImage) {
  1241. //        ReadDIBFile ("material.bmp", &hdib1);
  1242.         ReadDIBFile (NULL, &hdib1);
  1243.         ReadDIBFile ("redmarbl.bmp", &hdib2);
  1244.         ReadDIBFile ("c:\\windows\\system\\vgalogo.rle", &hdib3);
  1245.         LoadImage = FALSE;
  1246.     }
  1247.  
  1248.     SelectViewer (viewer30);
  1249.     SetViewerName (VL_CURRENT, "Image Mapping");
  1250.     PenColor (hdc, VL_BLUE);
  1251.     DisplayViewerFrame (hdc, VL_CURRENT);
  1252.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  1253.     DisplayViewerName (hdc, VL_CURRENT, 0);
  1254.     Scale3D (20, 20, 30);
  1255.  
  1256.     point[0] = -1; point[1] = -1; point[2] = 1;
  1257.     point[3] = 1; point[4] = -1; point[5] = 1;
  1258.     point[6] = 1; point[7] = 1; point[8] = 1;
  1259.     point[9] = -1; point[10] = 1; point[11] = 1;
  1260.     if (hdib1) {
  1261.         if (!ImageMap3D (hdc, hdib1, VL_3D, point))
  1262.             return;
  1263.     }
  1264.  
  1265.     point[0] = 1; point[1] = 1; point[2] = 1;
  1266.     point[3] = 1; point[4] = 1; point[5] = -1;
  1267.     point[6] = -1; point[7] = 1; point[8] = -1;
  1268.     point[9] = -1; point[10] = 1; point[11] = 1;
  1269.     if (hdib2) {
  1270.         if (!ImageMap3D (hdc, hdib2, VL_3D, point))
  1271.             return;
  1272.     }
  1273.  
  1274.     point[0] = 1; point[1] = -1; point[2] = -1;
  1275.     point[3] = 1; point[4] = 1; point[5] = -1;
  1276.     point[6] = 1; point[7] = 1; point[8] = 1;
  1277.     point[9] = 1; point[10] = -1; point[11] = 1;
  1278.     if (hdib3) {
  1279.         ImageMap3D (hdc, hdib3, VL_3D, point);
  1280.     }
  1281. }
  1282.  
  1283. void    Transformation2D (HDC hdc, int func)
  1284. {
  1285.     BrushColor (hdc, VL_NONE);
  1286.     switch (func) {
  1287.         case IDM_2DTRANSF_TRANSLATE:
  1288.             PenColor (hdc, VL_RED);
  1289.             Rectangle2D (hdc, 2, 2, 8, 4);
  1290.             Translate2D (0, -6);
  1291.             PenColor (hdc, VL_GREEN);
  1292.             Rectangle2D (hdc, 2, 2, 8, 4);
  1293.             TranslateTo2D (-8, -6);
  1294.             PenColor (hdc, VL_BLUE);
  1295.             Rectangle2D (hdc, 2, 2, 8, 4);
  1296.             Translate2D (0, 6);
  1297.             PenColor (hdc, VL_YELLOW);
  1298.             Rectangle2D (hdc, 2, 2, 8, 4);
  1299.             break;
  1300.         case IDM_2DTRANSF_SCALE:
  1301.             break;
  1302.         case IDM_2DTRANSF_POINTSCALE:
  1303.             break;
  1304.         case IDM_2DTRANSF_ROTATE:
  1305.             break;
  1306.         case IDM_2DTRANSF_POINTROTATE:
  1307.             break;
  1308.         case IDM_2DTRANSF_STRETCH:
  1309.             break;
  1310.         case IDM_2DTRANSF_SHEAR:
  1311.             break;
  1312.         case IDM_2DTRANSF_MIRROR:
  1313.             break;
  1314.     }
  1315. }
  1316.  
  1317. void    Transformation3D (HDC hdc, int func)
  1318. {
  1319.     switch (func) {
  1320.         case IDM_3DTRANSF_TRANSLATE:
  1321.             break;
  1322.         case IDM_3DTRANSF_SCALE:
  1323.             break;
  1324.         case IDM_3DTRANSF_POINTSCALE:
  1325.             break;
  1326.         case IDM_3DTRANSF_ROTATE:
  1327.             break;
  1328.         case IDM_3DTRANSF_AXLEROTATE:
  1329.             break;
  1330.         case IDM_3DTRANSF_STRETCH:
  1331.             break;
  1332.         case IDM_3DTRANSF_SHEAR:
  1333.             break;
  1334.         case IDM_3DTRANSF_MIRROR:
  1335.             break;
  1336.     }
  1337. }
  1338.  
  1339. VOIDED    MaterialPropertyDemo (HDC hdc)
  1340. {
  1341.     short    i, j, n = 1;
  1342.     real    ks, kd, orgks, orgkd, orgn;
  1343.     RECT    rect;
  1344.  
  1345.     SwitchLight (light7, TRUE);
  1346.     SwitchLight (light8, TRUE);
  1347.     SelectViewer (viewer30);
  1348.     SetViewerName (VL_CURRENT, "Material Reflection Property");
  1349.     PenColor (hdc, VL_BLUE);
  1350.     DisplayViewerFrame (hdc, VL_CURRENT);
  1351.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  1352.     DisplayViewerName (hdc, VL_CURRENT, 0);
  1353.     orgks = ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, VL_INQUIRE);
  1354.     orgkd = ShadingFactor (VL_CURRENT, VL_DIFFUSEREFLECT, VL_INQUIRE);
  1355.     orgn = ShadingFactor (VL_CURRENT, VL_SHININESS, VL_INQUIRE);
  1356.     rect.top = 10;
  1357.     ks = 0;
  1358.     for (i = 0; i < 6; i++) {
  1359.         kd = 0;
  1360.         rect.left = 10;
  1361.         rect.bottom = rect.top + 40;
  1362.         for (j = 0; j < 10; j++) {
  1363.             rect.right = rect.left + 40;
  1364.             ShadingFactor (VL_CURRENT, VL_SHININESS, n);
  1365.             ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, ks);
  1366.             ShadingFactor (VL_CURRENT, VL_DIFFUSEREFLECT, kd);
  1367.             if (!ShadingPreview (hdc, &rect, 5, 173))
  1368.                 goto exit;
  1369.             rect.left += 49;
  1370.             kd += 0.1f;
  1371.         }
  1372.         ks += 0.2f;
  1373.         rect.top += 53;
  1374.         n *= 2;
  1375.     }
  1376. exit:
  1377.     ShadingFactor (VL_CURRENT, VL_DIFFUSEREFLECT, orgkd);
  1378.     ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, orgks);
  1379.     ShadingFactor (VL_CURRENT, VL_SHININESS, orgn);
  1380. }
  1381.  
  1382. void    CompositeDemo3D (HDC hdc)
  1383. {
  1384.     real    r0, r1, r2, t1, t2, h;
  1385.     short    i;
  1386.     BOOL    zbuf, flag;
  1387.  
  1388.     SelectViewer (viewer30);
  1389.     SetViewerName (VL_CURRENT, "Object Composition");
  1390.     PenColor (hdc, VL_WHITE);
  1391.     DisplayViewerFrame (hdc, VL_CURRENT);
  1392.     TextColor (hdc, VL_WHITE, VL_BLACK, TRANSPARENT);
  1393.     DisplayViewerName (hdc, VL_CURRENT, 0);
  1394.     zbuf = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, TRUE);
  1395.     ClearDepthBuffer (0xffff);
  1396.     SwitchLight (light7, TRUE);
  1397. //    SwitchLight (light8, TRUE);
  1398.     SelectMaterial (mater0);
  1399.     PushTransformation3D (NULL);
  1400.     r0 = 4.5f; r1 = 30; r2 = 40;
  1401.     h = 10;
  1402.     t1 = 3, t2 = 2;
  1403.     if (!Tube (hdc, r1, r1, t1, h))
  1404.         goto exit;
  1405.  
  1406.     if (!Ring (hdc, r2, r2, t2, h, 90, 360, 1))
  1407.         goto exit;
  1408.     h *= 0.5f;
  1409.     Translate3D (0, 0, h);
  1410.     SelectMaterial (mater1);
  1411.     for (i = 0; i < 18; i++) {
  1412.         Rotate3D (20, 'z');
  1413.         PushTransformation3D (NULL);
  1414.         Translate3D (35, 0, 0);
  1415.         flag = Sphere (hdc, r0);
  1416.         PopTransformation3D (NULL);
  1417.         if (!flag)
  1418.             break;
  1419.     }
  1420. exit:
  1421.     PopTransformation3D (NULL);
  1422.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, zbuf);
  1423. }
  1424.  
  1425. void    DepthClippingDemo (HDC hdc)
  1426. {
  1427.     SelectViewer (viewer30);
  1428.     SetViewerName (VL_CURRENT, "Depth Buffer and Clipping");
  1429.     TextColor (hdc, VL_YELLOW, VL_BLACK, TRANSPARENT);
  1430.     DisplayViewerName (hdc, VL_CURRENT, 0);
  1431.     PenColor (hdc, VL_YELLOW);
  1432.     DisplayViewerFrame (hdc, VL_CURRENT);
  1433.     SetPerspective (VL_CURRENT, 45, 1, 141, 200);
  1434.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, TRUE);
  1435.     ShadingOption (VL_CURRENT, VL_SHADINGMETHOD, VL_PHONGSHADE);
  1436.     ClearDepthBuffer (0xffff);
  1437. //    SwitchLight (light7, TRUE);
  1438.     SwitchLight (light8, TRUE);
  1439.     SelectMaterial (mater1);
  1440.     TranslateTo3D (20, 0, 0);
  1441.     if (!Sphere (hdc, 20))
  1442.         goto exit;
  1443.     SelectMaterial (mater2);
  1444.     TranslateTo3D (0, 20, 0);
  1445.     if (!Sphere (hdc, 20))
  1446.         goto exit;
  1447.     SelectMaterial (mater3);
  1448.     TranslateTo3D (0, 0, 20);
  1449.     if (!Sphere (hdc, 20))
  1450.         return;
  1451.     TranslateTo3D (0, 0, 0);
  1452.     SelectMaterial (mater0);
  1453.     if (!Cube (hdc, 40, 40, 40))
  1454.         goto exit;
  1455.  exit:
  1456.     SetPerspective (VL_CURRENT, 45, 1, 30, 1000);
  1457. }
  1458.  
  1459. void    MarbleRingDemo (hdc)
  1460. {
  1461.     BOOL    depthbuffer;
  1462.     short    texture;
  1463.  
  1464.     SelectViewer (viewer30);
  1465.     SetViewerName (VL_CURRENT, "Marble Ring");
  1466.     TextColor (hdc, VL_BROWN, VL_BLACK, TRANSPARENT);
  1467.     DisplayViewerName (hdc, VL_CURRENT, 0);
  1468.     PenColor (hdc, VL_BROWN);
  1469.     DisplayViewerFrame (hdc, VL_CURRENT);
  1470.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, TRUE);
  1471.     ClearDepthBuffer (0xffff);
  1472.     texture = SolidTexture (VL_MARBLE);
  1473.     ShadingColor (VL_CURRENT, VL_MATERIALSPECULAR, RGB (255, 255, 255));
  1474.     ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, 1);
  1475.     SwitchLight (light7, TRUE);
  1476.     SwitchLight (light8, TRUE);
  1477.     Torus (hdc, 35, 10);
  1478.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  1479.     SolidTexture (texture);
  1480. }
  1481.  
  1482. void    WoodSurfaceDemo (HDC hdc)
  1483. {
  1484.     BOOL    depthbuffer;
  1485.     short    texture;
  1486.     
  1487.     POINT3D surf[36] = {
  1488.         {0,0,0},{1,0,0},{2,0,0},{3,0,0},{4,0,0},{5,0,0},
  1489.         {0,1,0},{1,1,0},{2,1,0},{3,1,0},{4,1,0},{5,1,0},
  1490.         {0,2,0},{1,2,0},{2,2,9},{3,2,9},{4,2,0},{5,2,0},
  1491.         {0,3,0},{1,3,0},{2,3,9},{3,3,9},{4,3,0},{5,3,0},
  1492.         {0,4,0},{1,4,0},{2,4,0},{3,4,0},{4,4,0},{5,4,0},
  1493.         {0,5,0},{1,5,0},{2,5,0},{3,5,0},{4,5,0},{5,5,0}};
  1494.     real    sknot[20] = {0,0,0,1,2,3,3,3};
  1495.     real    tknot[20] = {0,0,0,1,2,3,3,3};
  1496.  
  1497.     SelectViewer (viewer30);
  1498.     SetViewerName (VL_CURRENT, "Wood Surface");
  1499.     TextColor (hdc, VL_GREEN, VL_BLACK, TRANSPARENT);
  1500.     DisplayViewerName (hdc, VL_CURRENT, 0);
  1501.     PenColor (hdc, VL_GREEN);
  1502.     DisplayViewerFrame (hdc, VL_CURRENT);
  1503.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, TRUE);
  1504.     ClearDepthBuffer (0xffff);
  1505.     texture = SolidTexture (VL_WOODGRAIN);
  1506.     ShadingColor (VL_CURRENT, VL_MATERIALSPECULAR, RGB (255, 255, 255));
  1507.     ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, 1);
  1508.     SwitchLight (light7, TRUE);
  1509.     SwitchLight (light8, TRUE);
  1510.     Translate3D (-15, -15, 5);
  1511.     Scale3D (10, 10, 5);
  1512.     NURBSSurface (hdc, VL_3D, (LPCOORD) surf, 6, 6, sknot, tknot, 4, 4);
  1513.     SolidTexture (texture);
  1514.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  1515. }
  1516.  
  1517. void    GraniteCubeDemo (HDC hdc)
  1518. {
  1519.     BOOL    depthbuffer;
  1520.     real    l7, l8;
  1521.     short    texture;
  1522.  
  1523.     SelectViewer (viewer30);
  1524.     SetViewerName (VL_CURRENT, "Granite Cube");
  1525.     TextColor (hdc, VL_WHITE, VL_BLACK, TRANSPARENT);
  1526.     DisplayViewerName (hdc, VL_CURRENT, 0);
  1527.     PenColor (hdc, VL_WHITE);
  1528.     DisplayViewerFrame (hdc, VL_CURRENT);
  1529.     ClearDepthBuffer (0xffff);
  1530.     texture = SolidTexture (VL_GRANITE);
  1531.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, TRUE);
  1532.     ShadingColor (VL_CURRENT, VL_MATERIALSPECULAR, RGB (255, 255, 255));
  1533.     ShadingFactor (VL_CURRENT, VL_SPECULARREFLECT, 1);
  1534.     l7 = ShadingFactor (light7, VL_LIGHTINTENSITY, 2);
  1535.     l8 = ShadingFactor (light8, VL_LIGHTINTENSITY, 2);
  1536.     SwitchLight (light7, TRUE);
  1537.     SwitchLight (light8, TRUE);
  1538.     Cube (hdc, 30, 30, 30);
  1539.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  1540.     SolidTexture (texture);
  1541.     ShadingFactor (light7, VL_LIGHTINTENSITY, l7);
  1542.     ShadingFactor (light8, VL_LIGHTINTENSITY, l8);
  1543. }
  1544.  
  1545. void    StereoTextDemo (HDC hdc)
  1546. {
  1547.     BOOL    depthbuffer;
  1548.  
  1549.     if (!SelectFont ())
  1550.         return;
  1551.     SelectViewer (viewer30);
  1552.     SetViewerName (VL_CURRENT, "Stereo Text");
  1553.     PenColor (hdc, VL_BLUE);
  1554.     DisplayViewerFrame (hdc, VL_CURRENT);
  1555.     TextColor (hdc, VL_BLUE, VL_BLACK, TRANSPARENT);
  1556.     DisplayViewerName (hdc, VL_CURRENT, 0);
  1557.     depthbuffer = ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, TRUE);
  1558.     ClearDepthBuffer (0xffff);
  1559.     TextParameter (VL_TEXT_HEIGHT, 40);
  1560.     TextParameter (VL_TEXT_THICKNESS, 8);
  1561.     SwitchLight (light4, TRUE);
  1562.     SwitchLight (light7, TRUE);
  1563.     SelectMaterial (mater0);
  1564.     PushTransformation3D (NULL);
  1565.     Rotate3D (135, 'z');
  1566.     Rotate3D (90, 'x');
  1567.     SetTextAlign (hdc, TA_CENTER | TA_BASELINE);
  1568.     SolidText (hdc, "Visualib");
  1569.     PopTransformation3D (NULL);
  1570.     ShadingOption (VL_CURRENT, VL_DEPTHBUFFER, depthbuffer);
  1571. }
  1572.  
  1573. void    AnimationDemo (HDC hdc, WORD cmd)
  1574. {
  1575.     switch (cmd) {
  1576.         case IDM_ANIMATE_FRAME:
  1577.             animate_length = 10;
  1578.             RotateFrame (hdc);
  1579.             break;
  1580.         case IDM_ANIMATE_OBJECT2D:
  1581.             animate_length = 10;
  1582.             ObjectMotion2D (hdc);
  1583.             break;
  1584.         case IDM_ANIMATE_SURFACE:
  1585.             animate_length = 10;
  1586.             RotateSurface (hdc);
  1587.             break;
  1588.         case IDM_ANIMATE_ICOSAHEDRON:
  1589.             animate_length = 10;
  1590.             RotateIcosahedron (hdc);
  1591.             break;
  1592.         case IDM_ANIMATE_SPRING:
  1593.             animate_length = 15;
  1594.             RotateSpring (hdc);
  1595.             break;
  1596.         case IDM_ANIMATE_STAR3D:
  1597.             animate_length = 15;
  1598.             RotateStar (hdc);
  1599.             break;
  1600.         case IDM_ANIMATE_DODECAHEDRON:
  1601.             animate_length = 15;
  1602.             RotateDodecahedron (hdc);
  1603.             break;
  1604.         case IDM_ANIMATE_VIEWER3D:
  1605.             animate_length = 7;
  1606.             ViewerMotion3D (hdc);
  1607.             break;
  1608.         case IDM_ANIMATE_ZOOM3D:
  1609.             animate_length = 15;
  1610.             ViewerZoom3D (hdc);
  1611.             break;
  1612.     }
  1613.     ViewerReset ();
  1614. }
  1615.  
  1616. void    Welcome (HDC hdc)
  1617. {
  1618.     char    str[80];
  1619.  
  1620.     SelectViewer (viewer20);
  1621.     PushTransformation2D (NULL);
  1622.     Scale2D (0.1f, 0.1f);
  1623.     SetTextAlign (hdc, TA_BASELINE | TA_CENTER);
  1624.     TextParameter (VL_TEXT_HEIGHT, 40);
  1625.     PenColor (hdc, VL_RED);
  1626.     BrushColor (hdc, VL_YELLOW);
  1627.     wsprintf (str, "Welcome\nto\nVisuaLib");
  1628.     Text2D (hdc, 0, 0, 0, str);
  1629.     DisplayViewerFrame (hdc, VL_CURRENT);
  1630.     PopTransformation2D (NULL);
  1631. }
  1632.  
  1633. void    VlibDemo (HDC hdc, int func)
  1634. {
  1635.     BOOL    l0, l1, l2, l3;
  1636.  
  1637.     l0 = SwitchLight (light0, FALSE);
  1638.     l1 = SwitchLight (light1, FALSE);
  1639.     l2 = SwitchLight (light2, FALSE);
  1640.     l3 = SwitchLight (light3, FALSE);
  1641.     switch (func) {
  1642.         case IDM_DEMO_START:
  1643.             Welcome (hdc);
  1644.             break;
  1645.         case IDM_DEMO_SPOTLIGHT:
  1646.             SpotlightDemo (hdc);
  1647.             break;
  1648.         case IDM_DEMO_MATERIALPROPERTY:
  1649.             MaterialPropertyDemo (hdc);
  1650.             break;
  1651.         case IDM_DEMO_IMAGEMAPPING:
  1652.             ImageMappingDemo (hdc);
  1653.             break;
  1654.         case IDM_DEMO_DEPTHCLIPPING:
  1655.             DepthClippingDemo (hdc);
  1656.             break;
  1657.         case IDM_DEMO_MARBLERING:
  1658.             MarbleRingDemo (hdc);
  1659.             break;
  1660.         case IDM_DEMO_GRANITECUBE:
  1661.             GraniteCubeDemo (hdc);
  1662.             break;
  1663.         case IDM_DEMO_WOODSURFACE:
  1664.             WoodSurfaceDemo (hdc);
  1665.             break;
  1666.         case IDM_DEMO_3DCOMPOSITE:
  1667.             CompositeDemo3D (hdc);
  1668.             break;
  1669.         case IDM_DEMO_STEREOTEXT:
  1670.             StereoTextDemo (hdc);
  1671.             break;
  1672.         case IDM_DEMO_2DCOMPOSITE:
  1673.             CompositeDemo2D (hdc);
  1674.             break;
  1675.         case IDM_DEMO_NURBSCURVE:
  1676.             SelectViewer (viewer20);
  1677.             Primitives2D (hdc, IDM_2DCURVE_NURBS);
  1678.             SelectViewer (viewer30);
  1679.             Primitives3D (hdc, IDM_3DCURVE_NURBS);
  1680.             break;
  1681.     }
  1682.     SwitchLight (light0, l0);
  1683.     SwitchLight (light1, l1);
  1684.     SwitchLight (light2, l2);
  1685.     SwitchLight (light3, l3);
  1686.     SwitchLight (light4, FALSE);
  1687.     SwitchLight (light5, FALSE);
  1688.     SwitchLight (light6, FALSE);
  1689.     SwitchLight (light7, FALSE);
  1690.     SwitchLight (light8, FALSE);
  1691. }
  1692.  
  1693. void    FunctionDemos (HDC hdc)
  1694. {
  1695.     int        func = demo_function;
  1696.  
  1697.     SetROP2 (hdc, R2_COPYPEN);
  1698.     if (func > IDM_2DPRIME_START && func < IDM_2DPRIME_END) {
  1699.         SelectViewer (viewer20);
  1700.         Prime2D (hdc, func);
  1701.     }
  1702.     else if (func > IDM_3DPRIME_START && func < IDM_3DPRIME_END) {
  1703.         SelectViewer (viewer30);
  1704.         Prime3D (hdc, func);
  1705.     }
  1706.     else if (func > IDM_2DCURVE_START && func < IDM_2DCURVE_END) {
  1707.         SelectViewer (viewer20);
  1708.         Curves2D (hdc, func);
  1709.     }
  1710.     else if (func > IDM_3DCURVE_START && func < IDM_3DCURVE_END) {
  1711.         SelectViewer (viewer30);
  1712.         Curves3D (hdc, func);
  1713.     }
  1714.     else if (func >= IDM_SURFACE_START && func < IDM_SURFACE_END) {
  1715.         SelectViewer (viewer30);
  1716.         Surfaces (hdc, func);
  1717.     }
  1718.     else if (func >= IDM_SOLID_START && func < IDM_SOLID_END) {
  1719.         SelectViewer (viewer30);
  1720.         ShowSolidPrimitives (hdc, func);
  1721.     }
  1722.     else if (func > IDM_ANIMATE_START && func < IDM_ANIMATE_END) {
  1723.         AnimationDemo (hdc, func);
  1724.     }
  1725.     else if (func > IDM_TEXT_START && func < IDM_TEXT_END) {
  1726.         ShowTextPrimitives (hdc, func);
  1727.     }
  1728.     else if (func > 910 && func < 920) {
  1729.         SelectViewer (viewer20);
  1730.         Transformation2D (hdc, func);
  1731.     }
  1732.     else if (func > 920 && func < 930) {
  1733.         SelectViewer (viewer30);
  1734.         Transformation3D (hdc, func);
  1735.     }
  1736.     else if (func > 1100 && func < 1200) {
  1737.         SelectViewer (viewer20);
  1738.         Primitives2D (hdc, func);
  1739.     }
  1740.     else if (func > IDM_3DSHAPE_START && func < IDM_3DSHAPE_END) {
  1741.         SelectViewer (viewer30);
  1742.         Primitives3D (hdc, func);
  1743.     }
  1744.     else if (func > 1300 && func < 1400) {
  1745.         SelectViewer (viewer30);
  1746.         ObjectArray (hdc, func);
  1747.     }
  1748.     else {
  1749.         VlibDemo (hdc, func);
  1750.     }
  1751. }
  1752.  
  1753. void    AdjustViewer (HWND hwnd, int viewid)
  1754. {
  1755.     RECT    rect;
  1756.  
  1757.     GetClientRect (hwnd, &rect);
  1758.     rect.left += 10;
  1759.     rect.right -= 10;
  1760.     rect.top += 10;
  1761.     rect.bottom -= 20;
  1762.     SetViewport (viewid, rect);
  1763. }
  1764.  
  1765. BINARY    SavePicture (HWND hwnd, BOOL withframe)
  1766. {
  1767.     RECT    rect;
  1768.     HANDLE    hdib;
  1769.     BOOL    flag;
  1770.  
  1771.     GetScreenRect (hwnd, withframe, &rect);
  1772.     hdib = ScreenToDIB (&rect);
  1773.     if (!hdib)
  1774.         return (FALSE);
  1775.     flag = WriteDIBFile (NULL, hdib);
  1776.     GlobalUnlock (hdib);
  1777.     GlobalFree (hdib);
  1778.     return (flag);
  1779. }
  1780.  
  1781. BINARY    PrintPicture (HWND hwnd, BOOL withframe)
  1782. {
  1783.     RECT    rect;
  1784.     HANDLE    hdib;
  1785.     BOOL    flag;
  1786.  
  1787.     GetScreenRect (hwnd, withframe, &rect);
  1788.     hdib = ScreenToDIB (&rect);
  1789.     if (!hdib)
  1790.         return (FALSE);
  1791.     flag = PrintImage (hdib,
  1792.         VL_BESTFIT | VL_VERTCENTER | VL_HORZCENTER | VL_MARKCORNER,
  1793.         0, 0, 0, 0);
  1794.     GlobalUnlock (hdib);
  1795.     GlobalFree (hdib);
  1796.     return (flag);
  1797. }
  1798.  
  1799. void    PrintFlag (void)
  1800. {
  1801.     SelectViewer (viewer22);
  1802.     PrintDrawing (USFlag,
  1803.         VL_BESTFIT | VL_HORZCENTER | VL_VERTCENTER | VL_MARKCORNER,
  1804.         0, 0, 0, 0);
  1805. }
  1806.  
  1807. void    ExitDemo (void)
  1808. {
  1809.     ExitVisualib ();
  1810.     GlobalUnlock (hdib1);
  1811.     GlobalFree (hdib1);
  1812.     GlobalUnlock (hdib2);
  1813.     GlobalFree (hdib2);
  1814.     GlobalUnlock (hdib3);
  1815.     GlobalFree (hdib3);
  1816.     PostQuitMessage (0);
  1817. }
  1818.  
  1819. void    AlterMenuItem (HWND hwnd, WORD entry)
  1820. {
  1821.     short    flag = MF_BYCOMMAND;
  1822.  
  1823.     switch (entry) {
  1824.         case IDM_DEMO_WITHFRAME:
  1825.             withframe = !withframe;
  1826.             flag |= (withframe) ? MF_CHECKED : MF_UNCHECKED;
  1827.             break;
  1828.     }
  1829.     CheckMenuItem (GetMenu (hwnd), entry, flag);
  1830. }
  1831.                         
  1832. /****************************************************************************
  1833.  
  1834.     FUNCTION: MainWndProc (HWND, WORD, WORD, LONG)
  1835.  
  1836.     PURPOSE:  Processes messages
  1837.  
  1838.     MESSAGES:
  1839.  
  1840.     WM_COMMAND  - application menu (About dialog box)
  1841.     WM_DESTROY  - destroy window
  1842.  
  1843.     COMMENTS:
  1844.  
  1845.     To process the IDM_ABOUT message, call MakeProcInstance () to get the
  1846.     current instance address of the About () function.  Then call Dialog
  1847.     box which will create the box according to the information in your
  1848.     vlibdemo.rc file and turn control over to the About () function.    When
  1849.     it returns, free the intance address.
  1850.  
  1851. ****************************************************************************/
  1852.  
  1853. long WINAPI MainWndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  1854. {
  1855.     switch (msg) {
  1856.         case WM_COMMAND:
  1857.             switch (wParam) {
  1858.                 case IDM_DEMO_EXIT:
  1859.                     ExitDemo ();
  1860.                     break;
  1861.                 case IDM_HELP_ABOUT:
  1862.                     AboutVisualib ();
  1863.                     SendMessage (hWnd, WM_COMMAND, IDM_DEMO_START, 0L);
  1864.                     break;
  1865.                 case IDM_HELP_LICENSE:
  1866.                     LicenseInfo ();
  1867.                     break;
  1868.                 case IDM_HELP_DEMOPROG:
  1869.                     WinHelp (hWnd, "vlibdemo.hlp", HELP_INDEX, 0);
  1870.                     break;
  1871.                 case IDM_HELP_VISUALIB:
  1872.                     WinHelp (hWnd, "visualib.hlp", HELP_INDEX, 0);
  1873.                     break;
  1874.                 case IDM_DEMO_SAVEPICTURE:
  1875.                     SavePicture (hWnd, withframe);
  1876.                     break;
  1877.                 case IDM_DEMO_PRINTPICTURE:
  1878.                     PrintPicture (hWnd, withframe);
  1879.                     break;
  1880.                 case IDM_DEMO_WITHFRAME:
  1881.                     AlterMenuItem (hWnd, wParam);
  1882.                     break;
  1883.                 case IDM_DEMO_PRINTFLAG:
  1884.                     PrintFlag ();
  1885.                     break;
  1886.                 case IDM_TEXT_SELECTFONT:
  1887.                     SelectFont ();
  1888.                     return (NULL);
  1889.                 default:
  1890.                     if (wParam > 200 && wParam < 300) {
  1891.                         ShadingSettings (hWnd, wParam);
  1892.                         break;
  1893.                     }
  1894.                     if (wParam > IDM_ANIMATE_START &&
  1895.                         wParam < IDM_ANIMATE_END) {
  1896.                         HDC    hdc;
  1897.  
  1898.                         hdc = GetDC (hWnd);
  1899.                         AnimationDemo (hdc, wParam);
  1900.                         ReleaseDC (hWnd, hdc);
  1901.                         break;
  1902.                     }
  1903.                     demo_function = wParam;
  1904.                     InvalidateRect (hWnd, NULL, TRUE);
  1905.                     return (DefWindowProc (hWnd, msg, wParam, lParam));
  1906.             }
  1907.             break;
  1908.         case WM_DESTROY:
  1909.             ExitVisualib ();
  1910.             GlobalUnlock (hdib1);
  1911.             GlobalFree (hdib1);
  1912.             GlobalUnlock (hdib2);
  1913.             GlobalFree (hdib2);
  1914.             GlobalUnlock (hdib3);
  1915.             GlobalFree (hdib3);
  1916.             PostQuitMessage (0);
  1917.             break;
  1918.  
  1919.         case WM_PAINT:
  1920.             ProcessWindowPaint (hWnd);
  1921.             break;
  1922.         
  1923.         case WM_SIZE:
  1924.             AdjustViewer (hWnd, viewer20);
  1925.             AdjustViewer (hWnd, viewer30);
  1926.             InvalidateRect (hWnd, NULL, TRUE);
  1927.             break;
  1928.  
  1929.         default:
  1930.             return (DefWindowProc (hWnd, msg, wParam, lParam));
  1931.     }
  1932.     return (NULL);
  1933. }
  1934.  
  1935.