TEX1.C
上传用户:bangxh
上传日期:2007-01-31
资源大小:42235k
文件大小:4k
源码类别:

Windows编程

开发平台:

Visual C++

  1. /*==========================================================================
  2.  *
  3.  *  Copyright (C) 1995, 1996 Microsoft Corporation. All Rights Reserved.
  4.  *
  5.  *  File: tex1.c
  6.  *
  7.  ***************************************************************************/
  8. /*
  9.  * A texture mapping example using a cylindrical mapping.
  10.  */
  11. #include "rmdemo.h"
  12. BOOL
  13. BuildScene(LPDIRECT3DRMDEVICE dev, LPDIRECT3DRMVIEWPORT view,
  14.    LPDIRECT3DRMFRAME scene, LPDIRECT3DRMFRAME camera)
  15. {
  16.     LPDIRECT3DRMMESH mesh = NULL;
  17.     LPDIRECT3DRMMESHBUILDER builder = NULL;
  18.     LPDIRECT3DRMFRAME frame = NULL;
  19.     LPDIRECT3DRMTEXTURE tex = NULL;
  20.     LPDIRECT3DRMMATERIAL mat = NULL;
  21.     LPDIRECT3DRMWRAP wrap = NULL;
  22.     LPDIRECT3DRMLIGHT l1 = NULL;
  23.     LPDIRECT3DRMLIGHT l2 = NULL;
  24.     D3DRMBOX box;
  25.     D3DVALUE miny, maxy;
  26.     D3DVALUE height;
  27.     HRESULT rval;
  28.     dev;
  29.     view;
  30.     camera;
  31.     if (FAILED(lpD3DRM->lpVtbl->CreateLightRGB(lpD3DRM, D3DRMLIGHT_AMBIENT, D3DVAL(0.2),
  32.                                   D3DVAL(0.2), D3DVAL(0.2), &l1)))
  33.   goto generic_error;
  34.     if (FAILED(scene->lpVtbl->AddLight(scene, l1)))
  35. goto generic_error;
  36.     if (FAILED(lpD3DRM->lpVtbl->CreateFrame(lpD3DRM, scene, &frame)))
  37. goto generic_error;
  38.     if (FAILED(frame->lpVtbl->SetOrientation(frame, scene, -D3DVAL(1), -D3DVAL(1),
  39.                                   D3DVAL(1), D3DVAL(0), D3DVAL(1), D3DVAL(0))))
  40.   goto generic_error;
  41.     if (FAILED(lpD3DRM->lpVtbl->CreateLightRGB(lpD3DRM, D3DRMLIGHT_DIRECTIONAL, D3DVAL(1),
  42.                                   D3DVAL(1), D3DVAL(1), &l2)))
  43.   goto generic_error;
  44.     if (FAILED(frame->lpVtbl->AddLight(frame, l2)))
  45. goto generic_error;
  46.     RELEASE(frame);
  47.     if (FAILED(lpD3DRM->lpVtbl->CreateFrame(lpD3DRM, scene, &frame)))
  48. goto generic_error;
  49.     if (FAILED(frame->lpVtbl->SetPosition(frame, scene, D3DVAL(0), D3DVAL(0), D3DVAL(15))))
  50. goto generic_error;
  51.     if (FAILED(frame->lpVtbl->SetRotation(frame, scene, D3DVAL(1.1), D3DVAL(0.3), 
  52.                                D3DVAL(0.0), D3DVAL(0.04))))
  53.        goto generic_error;
  54.     if (FAILED(lpD3DRM->lpVtbl->CreateMeshBuilder(lpD3DRM, &builder)))
  55. goto generic_error;
  56.     rval = builder->lpVtbl->Load(builder, "sphere4.x", NULL,
  57.      D3DRMLOAD_FROMFILE, NULL, NULL);
  58.     if (rval != D3DRM_OK) {
  59.         Msg("Failed to load sphere4.x.n%s", D3DRMErrorToString(rval));
  60. goto ret_with_error;
  61.     }
  62.     rval = lpD3DRM->lpVtbl->LoadTexture(lpD3DRM, "tex7.ppm", &tex);
  63.     if (rval != D3DRM_OK) {
  64.         Msg("Failed to load tex7.ppm.n%s", D3DRMErrorToString(rval));
  65. goto ret_with_error;
  66.     }
  67.     if (FAILED(lpD3DRM->lpVtbl->CreateMaterial(lpD3DRM, D3DVAL(10.0), &mat)))
  68. goto generic_error;
  69.     if (FAILED(builder->lpVtbl->SetTexture(builder, tex)))
  70. goto generic_error;
  71.     if (FAILED(builder->lpVtbl->SetMaterial(builder, mat)))
  72. goto generic_error;
  73.     if (FAILED(builder->lpVtbl->SetColorRGB(builder, D3DVAL(1.0), D3DVAL(1.0), D3DVAL(1.0))))
  74. goto generic_error;
  75.     if (FAILED(builder->lpVtbl->CreateMesh(builder, &mesh)))
  76. goto generic_error;
  77.     RELEASE(builder);
  78.     if (FAILED(mesh->lpVtbl->GetBox(mesh, &box)))
  79. goto generic_error;
  80.     maxy = box.max.y;
  81.     miny = box.min.y;
  82.     height = maxy - miny;
  83.     if (FAILED(lpD3DRM->lpVtbl->CreateWrap(lpD3DRM, D3DRMWRAP_CYLINDER, NULL, D3DVAL(0.0),
  84.                               D3DVAL(0.0), D3DVAL(0.0), D3DVAL(0.0),
  85.                               D3DVAL(1.0), D3DVAL(0.0), D3DVAL(0.0),
  86.                               D3DVAL(0.0), D3DVAL(1.0), D3DVAL(0.0),
  87.                               D3DDivide(miny, height), D3DVAL(1.0),
  88.                               D3DDivide(-D3DVAL(1.0), height), &wrap)))
  89.       goto generic_error;
  90.     if (FAILED(wrap->lpVtbl->Apply(wrap, (LPDIRECT3DRMOBJECT)mesh)))
  91. goto generic_error;
  92.     if (FAILED(frame->lpVtbl->AddVisual(frame, (LPDIRECT3DRMVISUAL) mesh)))
  93. goto generic_error;
  94.     RELEASE(frame);
  95.     RELEASE(wrap);
  96.     RELEASE(mesh);
  97.     RELEASE(tex);
  98.     RELEASE(mat);
  99.     RELEASE(l1);
  100.     RELEASE(l2);
  101.     return TRUE;
  102. generic_error:
  103.     Msg("A failure occurred while building the scene.n");
  104. ret_with_error:
  105.     RELEASE(mesh);
  106.     RELEASE(builder);
  107.     RELEASE(frame);
  108.     RELEASE(tex);
  109.     RELEASE(mat);
  110.     RELEASE(wrap);
  111.     RELEASE(l1);
  112.     RELEASE(l2);
  113.     return FALSE;
  114. }
  115. void
  116. OverrideDefaults(Defaults* defaults)
  117. {
  118.     defaults->bConstRenderQuality = TRUE;
  119.     lstrcpy(defaults->Name, "Texture Mapping Direct3DRM Example");
  120. }