home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Graphics / sKulpt / skulpt-src / Render.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-28  |  3.7 KB  |  138 lines

  1. #define STRICT
  2.  
  3. // Includes standard Windows
  4. #include <windows.h>
  5. #include <windowsx.h>
  6. #include <time.h>
  7. #include <stdlib.h>
  8. #include <malloc.h>
  9. #include <memory.h>
  10. #include <stdio.h>
  11.  
  12. // Includes D3D
  13. #define  D3D_OVERLOADS
  14. #include <ddraw.h>
  15. #include <d3d.h>
  16. #include <d3dx.h>
  17.  
  18. // Includes utilitaires D3D
  19. #include "d3dmath.h"
  20. #include "d3dutil.h"
  21. #include "D3DEnum.h"
  22.  
  23. // Ids Resources
  24. #include "resource.h"
  25.  
  26. // Constantes
  27. #include "const.h"
  28.  
  29. // Types
  30. #include "types.h"
  31.  
  32. // Variables globales projet
  33. #include "vars.h"
  34.  
  35. // Prototypes fonctions autres modules
  36. #include "proto.h"
  37.  
  38. // Macros
  39. #include "macros.h"
  40.  
  41. // Variables locales au module
  42.  
  43. //***************************** R E G L A G E S  P A R A M E T R E S  D 3 D ****
  44. void vSetD3DState(void)
  45. {
  46. #ifndef NO3D
  47.     // Régler le z-buffering.
  48.     lpd3dDevice->SetRenderState(D3DRENDERSTATE_ZENABLE, dZBuf);
  49.  
  50.     lpd3dDevice->SetRenderState(D3DRENDERSTATE_FILLMODE, dFillMode);
  51.  
  52.     lpd3dDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, bAlpha);
  53.     lpd3dDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCCOLOR); 
  54.     lpd3dDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_SRCCOLOR);
  55.  
  56.     // Définir les 3 matrices du pipeline D3D
  57.     lpd3dDevice->SetTransform( D3DTRANSFORMSTATE_WORLD, &matWorld );
  58.     lpd3dDevice->SetTransform( D3DTRANSFORMSTATE_PROJECTION, &matProj );
  59.     lpd3dDevice->SetTransform( D3DTRANSFORMSTATE_VIEW, &matView );
  60.  
  61.     lpd3dDevice->SetRenderState(D3DRENDERSTATE_CULLMODE , dCull);
  62.  
  63.     lpd3dDevice->SetRenderState( D3DRENDERSTATE_AMBIENT, cAmbient );
  64.     lpd3dDevice->SetRenderState( D3DRENDERSTATE_LIGHTING, TRUE );
  65.     lpd3dDevice->SetRenderState( D3DRENDERSTATE_SPECULARENABLE, bSpecular);
  66.     lpd3dDevice->SetRenderState( D3DRENDERSTATE_ANTIALIAS, bAntialias ? D3DANTIALIAS_SORTINDEPENDENT : D3DANTIALIAS_NONE);
  67. #endif
  68. }
  69.  
  70. HRESULT hrInitWorld( LPDIRECT3DDEVICE7 pd3dDevice )
  71. {
  72.     D3DMATRIX mIdentity;
  73.  
  74.     D3DUtil_SetIdentityMatrix(mIdentity); ;
  75.     
  76.     // World matrix
  77.     matWorld = mIdentity;
  78.  
  79.     // View matrix (position et orientation de la caméra)
  80.     D3DUtil_SetViewMatrix(matView,
  81.                           Observer,    // From
  82.                           Target,    // To
  83.                           D3DVECTOR(0.f, 0.f, 0.f));
  84.  
  85.     // Projection matrix
  86.     matProj = mIdentity;
  87.     matProj._m._11 =  2.0f;
  88.     matProj._m._22 =  2.0f;
  89.     matProj._m._34 =  1.0f;
  90.     matProj._m._43 = -1.0f;
  91.     matProj._m._44 =  0.0f;
  92.  
  93.     // Mettre à jour les variables d'état du pipe D3D
  94.     vSetD3DState();
  95.     return S_OK;
  96. }
  97.  
  98. HRESULT hrRender( LPDIRECT3DDEVICE7 pd3dDevice )
  99. {
  100. #ifndef NO3D
  101.     // Clear the viewport to back color
  102.     // Clear the z-buffer (if present) as well with far clipping plane : z > 10
  103.     pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|(dZBuf == D3DZB_TRUE ? D3DCLEAR_ZBUFFER : 0),
  104.                        cBack, 10.0f, 0L );
  105.  
  106.     // Begin scene
  107.     if( FAILED( pd3dDevice->BeginScene() ) )
  108.         return E_FAIL;
  109.     
  110.     for (register int iTriangle = 0 ; iTriangle <= iTriaLastUsed ; iTriangle++)
  111.     {
  112.         if (Triangles[iTriangle].bEnabled == FALSE) continue;
  113.         if (Triangles[iTriangle].bHidden == TRUE) continue;
  114.  
  115.         pd3dDevice->SetMaterial(&(Materials[Triangles[iTriangle].iMtrl].mtrl));
  116.  
  117.         // Draw base objects triangles
  118.         pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, D3DFVF_VERTEX,
  119.             Triangles[iTriangle].pSommets, dCull == D3DCULL_NONE ? 3 : 6, NULL );
  120.     }
  121.  
  122.     for (register int iObject = 0 ; iObject <= iObjtLastUsed ; iObject++)
  123.     {
  124.         if (Objects[iObject].bEnabled == FALSE) continue;
  125.         if (Objects[iObject].bHidden == TRUE) continue;
  126.  
  127.         pd3dDevice->SetMaterial( &Objects[iObject].mtrl );
  128.  
  129.         // Draw d3d simpleshape objects
  130.         Objects[iObject].pShape -> Draw();
  131.     }
  132.  
  133.     // End scene.
  134.     pd3dDevice->EndScene();
  135. #endif
  136.     return S_OK;
  137. }
  138.