Intro to DirectX Part 4 - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Intro to DirectX Part 4

Description:

d3dLight.Position.x = 0.0f; d3dLight.Position.y = 100.0f; d3dLight. ... and remember kids, don't let directx get into the hands of those crummy bobsledders... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 12
Provided by: tagdC
Category:
Tags: directx | direct | intro | part

less

Transcript and Presenter's Notes

Title: Intro to DirectX Part 4


1
Intro to DirectX Part 4
  • Putting it all together

Danny Dyer
2
Information about these slides
  • Companion to the more detailed slides available
    on the TAGD resources page.
  • http//www.gettagd.com/resources.php
  • You can find the page numbers that reference the
    other slides at the bottom right of these slides.

3
Togetherness
  • We learned about a bunch (or a few) different
    concepts, but how do we put them all together?
  • Wouldnt it be cool if we could have a spinning
    textured cube with lighting ?!
  • Just imagine the possibilities

4
Back to Program Flow
WinMain() // done for you
begin
resources
acquire
OnResetDevice()
setup state
update
OnFrameMove()
render
render
OnFrameRender()
release
resources
OnLostDevice()
4
fin
return 0 // done for you
5
Acquire Get Resources
  • //Declare our global variables at the top
  • ID3DXMesh g_pMesh
  • IDirect3DTexture9 g_pTexture
  • // Called when our device is created or reset
  • HRESULT CALLBACK OnResetDevice( IDirect3DDevice9
    pd3dDevice,
  • const D3DSURFACE_DESC
    pBackBufferSurfaceDesc, void pUserContext )
  • // load a mesh with normals
  • D3DXLoadMeshFromX( boxmesh.x, D3DX_SYSTEMMEM,
    pd3dDevice, NULL,
  • NULL, NULL, NULL, g_pMesh )
  • // load our texture
  • D3DXCreateTextureFromFile( pd3dDevice,
    L"texture.bmp", g_pTexture )

6
Acquire Setup State
  • HRESULT CALLBACK OnResetDevice( IDirect3DDevice9
    pd3dDevice,
  • const D3DSURFACE_DESC
    pBackBufferSurfaceDesc, void pUserContext )
  • // get resources
  • // define our view matrix
  • D3DXMATRIX view
  • D3DXVECTOR3 eye(0,0,-5)
  • D3DXVECTOR3 at(0,0,0)
  • D3DXVECTOR3 up(0,1,0)
  • D3DXMatrixLookAtLH(view, eye, at, up)
  • // define our projection matrix
  • D3DXMATRIX proj
  • D3DXMatrixPerspectiveFovLH(proj, D3DX_PI /
    4.0f, 4.0f/ 3, 1.0f, 100.0f)
  • // set these matrices to the device
  • pd3dDevice-gtSetTransform(D3DTS_VIEW, view)
  • pd3dDevice-gtSetTransform(D3DTS_PROJECTION,
    proj)

7
setup_lighting()
  • void setup_lighting()
  • // Set the RGBA for diffuse reflection.
  • D3DMATERIAL9 mat
  • mat.Diffuse.r 0.0f
  • mat.Diffuse.g 0.5f
  • mat.Diffuse.b 1.0f
  • mat.Diffuse.a 1.0f
  • pd3dDevice-gtSetMaterial(mat)
  • // Initialize the light.
  • D3DLIGHT9 d3dLight
  • ZeroMemory(d3dLight, sizeof(d3dLight))
  • // Set up a white point light.
  • d3dLight.Type D3DLIGHT_POINT
  • d3dLight.Diffuse.r 1.0f
  • d3dLight.Diffuse.g 1.0f
  • d3dLight.Diffuse.b 1.0f

8
Render
  • void CALLBACK OnFrameRender( IDirect3DDevice9
    pd3dDevice, double fTime, float fElapsedTime,
    void pUserContext )
  • HRESULT hr
  • // Clear the render target and the zbuffer
  • pd3dDevice-gtClear(0, NULL, D3DCLEAR_TARGET
    D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 45, 50, 170),
    1.0f, 0)
  • // Render the scene
  • if( SUCCEEDED( pd3dDevice-gtBeginScene() ) )
  • // set our texture
  • pd3dDevice-gtSetTexture(0, g_pTexture)
  • // update angle
  • static float angle 0.0f
  • angle fElapsedTime
  • if(angle gt 2.0f D3DX_PI)
  • angle 0.0f

9
Release
  • // Release all of our resources created in
    OnResetDevice()
  • void CALLBACK OnLostDevice( void pUserContext )
  • if( g_pTexture )
  • g_pTexture-gtRelease()
  • if( g_pMesh )
  • g_pMesh-gtRelease()

10
Thats it!
  • Thats really all there is too it.
  • Making DirectX applications is simple as long as
    you have a framework.

11
What do you want next?
  • Possible Topics
  • Rendering Pipeline
  • Shaders
  • Vertex/Index Buffers
  • Others??
  • bovicide_at_gmail.com
  • and remember kids, dont let directx get into
    the hands of those crummy bobsledders
Write a Comment
User Comments (0)
About PowerShow.com