Game Development Reference
In-Depth Information
std::string name = m_textureBaseName;
name += suffix[side];
m_PixelShader.SetTexture(name);
DXUTGetD3D11DeviceContext()->DrawIndexed( 6, side * 6, 0 );
}
return S_OK;
}
First, the vertex and pixel shaders have their SetupRender() methods called. This
is what sets up the transformation matrices in the vertex shader and the lighting and
material constant buffers in the pixel shader. Then the vertex and index buffers are
sent into the ID3D11DeviceContext , and the primitive topology is set to a triangle
list, which is how we
ve set up the indices into the vertex buffer. Then a loop begins
that sets the pixel shader
'
'
s texture, and a call to DrawIndexed() is made to draw
one side of the skybox.
If you read this and said to yourself,
What a fool
McShaffry is setting a different
texture for each face of the sky and that
d be absolutely right.
There is a better way to do this, although it does require some advanced shader code
and a different kind of texture, called a cube map. A cube map is basically a large
texture with all faces present, so there ' s only one texture to manage. As an exercise,
try writing the shaders to use a cube map, create the C++ helper classes to interface
with the shaders, and convert this sky node class to use it. That will utilize almost
every 3D graphics topic you
'
s too expensive!
you
'
'
ve learned so far.
Using Meshes in Your Scene
A 3D game would be pretty boring with nothing but grids and sky. If you want inter-
esting shapes, you
ll need to create them in a modeling tool like 3ds Max, Maya, or
ZBrush. Modeling tools are precise tools for creating shapes for your game levels or
dynamic objects. Direct3D can ' t read files from these modeling tools directly, but it
can read SDKMESH files, which are used in the Direct3D samples and tutorials.
This file format isn
'
t meant for commercial games, but it can be used to get used to
the idea of how to read them, create a SceneNode around them, and put them into a
3D world. The first task is to load the mesh, and like many other things you
'
ve seen,
it is convenient to be able to load meshes from the resource cache. The raw bits of
the SDKMESH file can
'
t be used directly by Direct3D 11. It is loaded into a Direct3D
utility class, CDXUTSDKMesh . That means we have to define a resource loader class
that will help the resource cache load the raw bits into an object directly usable by
Direct3D 11.
'
 
 
Search WWH ::




Custom Search