Original Post
Hi everyone ! I have tried a DirectX tutorial on NeXe. I'm on the Texturing tutorial. The code compiles fine, but the image isn't shown. I get a red rectangle instead of my image. I've tried multiple different images but it didn't work neither. Anyone have an idea ? Here's the code:
IDirect3D8* Direct3D ;
IDirect3DDevice8* Device ;
IDirect3DTexture8* Texture ;
HRESULT Error ;
// Vertex FVF
const DWORD D3DFVF_VERTEX = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 ;
Vertex QuadFace[4] ;
LRESULT CALLBACK WndProc( HWND, UINT, WPARAM, LPARAM ) ;
BOOL Direct3DInit( )
{
// Create D3D
Direct3D = Direct3DCreate8( D3D_SDK_VERSION ) ;
if( Direct3D == NULL )
return FALSE ;
// structure to hold infos on the display mode
D3DDISPLAYMODE displayMode ;
Error = Direct3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &displayMode ) ;
if( FAILED( Error ) )
return FALSE ;
// Used to explain to Direct3D how it will present things on the screen
D3DPRESENT_PARAMETERS presentParameters ;
ZeroMemory( &presentParameters, sizeof( D3DPRESENT_PARAMETERS ) ) ;
presentParameters.Windowed = TRUE ; // Not fullscreen
presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD ;
presentParameters.BackBufferFormat = displayMode.Format ;
presentParameters.BackBufferHeight = displayMode.Height ;
presentParameters.BackBufferWidth = displayMode.Width ;
// Create the device
Error = Direct3D->CreateDevice( D3DADAPTER_DEFAULT, // Default display adapter
D3DDEVTYPE_HAL, // Hardware acceleration
WindowInfos::Window,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&presentParameters,
&Device ) ;
if( FAILED( Error ) )
return FALSE ;
D3DXMATRIX Matrix ;
D3DXMatrixPerspectiveFovLH( &Matrix,
D3DX_PI/6, // 60°
WindowInfos::Width / WindowInfos::Height,
1.0,
100.0 ) ;
Device->SetTransform( D3DTS_PROJECTION, &( D3DMATRIX )Matrix ) ;
D3DXMatrixIdentity( &Matrix ) ;
Device->SetTransform( D3DTS_WORLD, &( D3DMATRIX )Matrix ) ;
D3DXMatrixTranslation( &Matrix, 0.0, 0.0, 20.0 ) ;
Device->SetTransform( D3DTS_VIEW, &( D3DMATRIX )Matrix ) ;
QuadFace[0].Create( 0, 0, 0, 1, 0, 0, 0, 1 ) ;
QuadFace[1].Create( 0, 1, 0, 0, 1, 0, 1, 1 ) ;
QuadFace[3].Create( 2, 1, 0, 0, 0, 1, 1, 0 ) ;
QuadFace[2].Create( 2, 0, 0, 1, 1, 0, 0, 0 ) ;
// Blender between the vertex color and the texture color
Device->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ) ;
Device->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ) ;
Device->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ) ;
// Turn off the alpha channel
Device->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE ) ;
// We don't need lighting
Device->SetRenderState( D3DRS_LIGHTING, FALSE ) ;
D3DXCreateTextureFromFile( Device, "C:\\Documents and Settings\\Alex\\Mes documents\\signature.bmp", &Texture ) ;
return TRUE ;
}
void DrawScene( )
{
// Clear the screen
Device->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0, 0 ), 1.0f, 0 ) ;
// Make it possible to draw stuff
Device->BeginScene( ) ;
Device->SetVertexShader( D3DFVF_VERTEX ) ;
Device->SetTexture( 0, Texture ) ; // 0th texture
Device->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, QuadFace, sizeof( Vertex ) ) ;
// Clean the stuff needed by BeginScene( )
Device->EndScene( ) ;
// Put the back buffer onto the screen
Device->Present( NULL, NULL, NULL, NULL ) ;
}