主题:问一下该题的渲染位置
VOID RenderSene()
{
HRESULT hr;
D3DXMATRIX matWorld;
//检查Direct3D设备是否已经创建,如果没有创建就直接返回
if( NULL == g_pMyd3dDevice )
return;
// 测试设备的协作能力,是否可以正常渲染
if(FAILED( hr = g_pMyd3dDevice->TestCooperativeLevel() ) )
{
// 假如设备丢失,不能进行渲染
if( D3DERR_DEVICELOST == hr )
return;
// 检查设备是否需要重新设置
if( D3DERR_DEVICENOTRESET == hr )
{
if( FAILED(hr = g_pMyd3dDevice->Reset(&g_d3dpp) ) )
return;
g_pMyd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
g_pMyd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
}
}
// 清除Direct3D设备的后台表面,背景颜色为蓝色RGB(0,0,255)
g_pMyd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255,255,255), 1.0f, 0 );
// 打开3D渲染开关
g_pMyd3dDevice->BeginScene();
// 设置待渲染顶点的来源
g_pMyd3dDevice->SetStreamSource( 0, g_pMyVxBufferRec, sizeof(CUSTOMVERTEX) );
// 进行3D渲染,在这里设置渲染的顶点格式,并调用DrawPrimitive完成顶点渲染处理
g_pMyd3dDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX );
float i, j;
for (i = -GRID_WIDTH/2 + 1; i < GRID_WIDTH/2; i+=4)
{
for(j = -GRID_WIDTH/2 + 1; j < GRID_WIDTH/2; j+=4)
{
if((j > -2) && (j < 2))
continue;
D3DXMatrixTranslation( &matWorld, j, 0, i );
g_pMyd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
g_pMyd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
}
}
D3DXMatrixRotationY( &matWorld, timeGetTime()/100.0f );
g_pMyd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
g_pMyd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
// 设置待渲染顶点的来源
g_pMyd3dDevice->SetStreamSource( 0, g_pMyVxBufferLine, sizeof(CUSTOMVERTEX) );
// 进行3D渲染,在这里设置渲染的顶点格式,并调用DrawPrimitive完成顶点渲染处理
g_pMyd3dDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX );
D3DXMatrixIdentity(&matWorld);
g_pMyd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
g_pMyd3dDevice->DrawPrimitive( D3DPT_LINELIST, 0, NUM_GRID*NUM_GRID );
// 关闭3D渲染开关
g_pMyd3dDevice->EndScene();
// 展现后台表面到窗口的客户区域中,即把渲染后的图像显示到窗口中
g_pMyd3dDevice->Present( NULL, NULL, NULL, NULL );
return;
}
其中
D3DXMatrixRotationY( &matWorld, timeGetTime()/100.0f );
g_pMyd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
g_pMyd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
是不是在正中渲染?我怎么觉得不像(世界矩阵不是变了吗?)
(D3DXMatrixRotationY( &matWorld, timeGetTime()/100.0f );
一开始能看到在正中有一矩形在旋转,在vc6.0重新运行几遍之后却看不到旋转,能否解释一下?)
详细代码见附件
{
HRESULT hr;
D3DXMATRIX matWorld;
//检查Direct3D设备是否已经创建,如果没有创建就直接返回
if( NULL == g_pMyd3dDevice )
return;
// 测试设备的协作能力,是否可以正常渲染
if(FAILED( hr = g_pMyd3dDevice->TestCooperativeLevel() ) )
{
// 假如设备丢失,不能进行渲染
if( D3DERR_DEVICELOST == hr )
return;
// 检查设备是否需要重新设置
if( D3DERR_DEVICENOTRESET == hr )
{
if( FAILED(hr = g_pMyd3dDevice->Reset(&g_d3dpp) ) )
return;
g_pMyd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
g_pMyd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );
}
}
// 清除Direct3D设备的后台表面,背景颜色为蓝色RGB(0,0,255)
g_pMyd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255,255,255), 1.0f, 0 );
// 打开3D渲染开关
g_pMyd3dDevice->BeginScene();
// 设置待渲染顶点的来源
g_pMyd3dDevice->SetStreamSource( 0, g_pMyVxBufferRec, sizeof(CUSTOMVERTEX) );
// 进行3D渲染,在这里设置渲染的顶点格式,并调用DrawPrimitive完成顶点渲染处理
g_pMyd3dDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX );
float i, j;
for (i = -GRID_WIDTH/2 + 1; i < GRID_WIDTH/2; i+=4)
{
for(j = -GRID_WIDTH/2 + 1; j < GRID_WIDTH/2; j+=4)
{
if((j > -2) && (j < 2))
continue;
D3DXMatrixTranslation( &matWorld, j, 0, i );
g_pMyd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
g_pMyd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
}
}
D3DXMatrixRotationY( &matWorld, timeGetTime()/100.0f );
g_pMyd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
g_pMyd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
// 设置待渲染顶点的来源
g_pMyd3dDevice->SetStreamSource( 0, g_pMyVxBufferLine, sizeof(CUSTOMVERTEX) );
// 进行3D渲染,在这里设置渲染的顶点格式,并调用DrawPrimitive完成顶点渲染处理
g_pMyd3dDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX );
D3DXMatrixIdentity(&matWorld);
g_pMyd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
g_pMyd3dDevice->DrawPrimitive( D3DPT_LINELIST, 0, NUM_GRID*NUM_GRID );
// 关闭3D渲染开关
g_pMyd3dDevice->EndScene();
// 展现后台表面到窗口的客户区域中,即把渲染后的图像显示到窗口中
g_pMyd3dDevice->Present( NULL, NULL, NULL, NULL );
return;
}
其中
D3DXMatrixRotationY( &matWorld, timeGetTime()/100.0f );
g_pMyd3dDevice->SetTransform( D3DTS_WORLD, &matWorld );
g_pMyd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
是不是在正中渲染?我怎么觉得不像(世界矩阵不是变了吗?)
(D3DXMatrixRotationY( &matWorld, timeGetTime()/100.0f );
一开始能看到在正中有一矩形在旋转,在vc6.0重新运行几遍之后却看不到旋转,能否解释一下?)
详细代码见附件