home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 Secrets (4th Edition) / Windows95Secrets4thEdition.iso / tools / graphics / render / showquad.c_ / showquad
Encoding:
Text File  |  1996-05-12  |  3.7 KB  |  158 lines

  1. /*
  2.  * File: showquad.c
  3.  *
  4.  * Author: Taken from RenderMan Companion by Steve Upstill
  5.  *
  6.  * Purpose: Demonstrate Windows app which converts RenderMan to RDC bytestream.
  7.  *
  8.  */
  9.  
  10. #include <windows.h>
  11. #include "rdc.h"            /* RenderDotC interface definition */
  12. #include "ri.h"                /* RenderMan interface definition */
  13.  
  14. /*
  15.  * function: showquads
  16.  *
  17.  * input: none
  18.  *
  19.  * returns: void
  20.  *
  21.  * purpose: Example RenderMan program.
  22.  *
  23.  */
  24. static void showquads(void)
  25. {
  26.     RtFloat fov = 11;
  27.     RtColor white = {1.0, 1.0, 1.0};
  28.     RtPoint hypert1, hypert2;
  29.  
  30.     RiBegin(RI_NULL);
  31.         RiFormat(200, 150, -1);
  32.     RiDisplay("showquad.tif", RI_FILE, RI_RGB, RI_NULL);
  33.     RiProjection(RI_PERSPECTIVE, RI_FOV, (RtPointer)&fov, RI_NULL);
  34.     RiShadingInterpolation("smooth");
  35.  
  36.     RiWorldBegin();
  37.         RiColor(white);
  38.         RiLightSource(RI_DISTANTLIGHT, RI_NULL);
  39.         RiSurface("matte", RI_NULL);
  40.         RiSides(1);
  41.  
  42.         RiTranslate(0, 0, 14.0);
  43.         RiRotate(-90, 1, 0, 0);
  44.  
  45.         RiTranslate(-1.2, 0, 1.2 / 2);
  46.         RiSphere(0.5, -0.5, 0.5, 360, RI_NULL);
  47.  
  48.         RiTranslate(1.2, 0, 0);
  49.         RiTranslate(0, 0, -0.5);
  50.         RiCone(1, 0.5, 360, RI_NULL);
  51.  
  52.         RiTranslate(0.0, 0, 0.5);
  53.         RiTranslate(1.2, 0, 0);
  54.         RiCylinder(0.5, -0.5, 0.5, 360, RI_NULL);
  55.  
  56.         RiTranslate(-2.4, 0, -1.2);
  57.         hypert1[0] = 0.4;
  58.         hypert1[1] = -0.4;
  59.         hypert1[2] = -0.4;
  60.         hypert2[0] = 0.4;
  61.         hypert2[1] = 0.4;
  62.         hypert2[2] = 0.4;
  63.  
  64.         RiHyperboloid(hypert1, hypert2, 360, RI_NULL);
  65.  
  66.         RiTranslate(1.2, 0, -0.5);
  67.         RiParaboloid(0.5, 0, 0.9, 360, RI_NULL);
  68.  
  69.         RiTranslate(1.2, 0, 0.5);
  70.         RiTorus(0.4, 0.15, 0, 360, 360, RI_NULL);
  71.     RiWorldEnd();
  72.     RiEnd();
  73. }
  74.  
  75. /*
  76.  * function: MainWndProc
  77.  *
  78.  * input: Window handle, message id, first and second message parameters.
  79.  *
  80.  * returns: LRESULT - Result of message processing.
  81.  *
  82.  * purpose: Destroys app when main window closes.  Calls default for rest.
  83.  *
  84.  */
  85. static LRESULT WINAPI MainWndProc(HWND hWnd, UINT msg,
  86.     WPARAM wParam, LPARAM lParam)
  87. {
  88.     switch(msg) {
  89.     case WM_DESTROY:
  90.     PostQuitMessage(0);        /* Kill the app when the window goes */
  91.     break;
  92.  
  93.     default:                /* Do the default thing */
  94.     return DefWindowProc(hWnd, msg, wParam, lParam);
  95.     }
  96.  
  97.     return FALSE;
  98. }
  99.  
  100. /*
  101.  * function: WinMain
  102.  *
  103.  * input: Handles to current and previous instances, command line, show state.
  104.  *
  105.  * returns: int APIENTRY - 0 on success
  106.  *
  107.  * purpose: Main entry point for 32 bit windows program.
  108.  *
  109.  */
  110. int APIENTRY WinMain(HANDLE hInstance, HANDLE hPrevInstance,
  111.     LPSTR lpCmdLine, int nCmdShow)
  112. {
  113.     HWND hMainWnd;
  114.     WNDCLASS wc;
  115.     MSG msg;
  116.  
  117.     /*
  118.      * Create a main window
  119.      */
  120.     wc.style = 0;
  121.     wc.hInstance = hInstance;
  122.     wc.lpfnWndProc = MainWndProc;
  123.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  124.     wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
  125.     wc.lpszClassName = "QUAD:MAIN";
  126.     wc.lpszMenuName = NULL;
  127.     wc.cbClsExtra = wc.cbWndExtra = 0;
  128.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
  129.     if (!RegisterClass(&wc))
  130.     return 1;
  131.     hMainWnd = CreateWindow("QUAD:MAIN", "Quads App", WS_OVERLAPPEDWINDOW,
  132.     CW_USEDEFAULT, 0, 100, 100, NULL, NULL, hInstance, NULL);
  133.     if (!hMainWnd)
  134.     return 1;
  135.     ShowWindow(hMainWnd, nCmdShow);
  136.     UpdateWindow(hMainWnd);
  137.  
  138.     /*
  139.      * The following line sets the name of the output rdc file.
  140.      */
  141.     rdcOutputFile(RDC_BYTESTREAM, "showquad.rdc");
  142.  
  143.     /*
  144.      * Draw the quadrics
  145.      */
  146.     showquads();
  147.  
  148.     /*
  149.      * Run message loop until user closes main window.
  150.      */
  151.     while (GetMessage(&msg, NULL, 0, 0)) {
  152.     TranslateMessage(&msg);
  153.     DispatchMessage(&msg);
  154.     }
  155.  
  156.     return 0;
  157. }
  158.