将一个图片以0xff808080的颜色值渲染出来,然后把这个渲染结果保存到一张纹理.
比如,给一个按钮图片,要求加深颜色值,模拟按钮被按下的状态,即可以用这个颜色值渲染,然后保存到一张纹理.
我写的代码有两个问题,一个是保存的纹理有点花,另外就是图片的明暗度未改变,仍然是原来的颜色:
PS:实际的渲染结果那张图,运行的时候其实是不会显示的,这里只是用于说明
代码:
void CRender::InitData()
{
HRESULT hr = E_FAIL;
D3DXIMAGE_INFO info;
char FileName[64] = "src.png";
D3DXGetImageInfoFromFile(FileName, &info);
hr = D3DXCreateTextureFromFileEx(m_pD3DDevice, FileName, info.Width, info.Height,
D3DFMT_FROM_FILE, 0, info.Format, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_DEFAULT, 0, NULL, NULL, &m_pTexture);
D3DXCreateTexture(m_pD3DDevice, 88, 31, 0, D3DUSAGE_RENDERTARGET, info.Format, D3DPOOL_DEFAULT, &m_pDstTexture);
m_pDstTexture->GetSurfaceLevel(0, &m_pSurface);
}
void CRender::RenderExample()
{
m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, m_BackGroundColor, 1.0f, 0);
}
m_pD3DDevice->BeginScene();
m_pD3DDevice->GetRenderTarget(0, &m_pOldSurface);
m_pD3DDevice->SetRenderTarget(0, m_pSurface);
RECT rcPos = { 0, 0, 176, 124 };
RenderObj(m_pTexture, 300, 100, &rcPos, 0xff808080); // 渲染函数就不必贴出来了,就是设置顶点,设置纹理,然后DrawPrimitiveUP
if (GetAsyncKeyState('S') & 0x8000f)
{
RECT rcTex = { 0, 0, 88, 31 };
D3DXSaveSurfaceToFile("out.png", D3DXIFF_PNG, m_pSurface, 0, &rcTex);
}
m_pD3DDevice->EndScene();
m_pD3DDevice->SetRenderTarget(0, m_pOldSurface);
m_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}
哪里不对? 应该怎么改?
14 个解决方案
#1
在 m_pD3DDevice->SetRenderTarget(0, m_pOldSurface);这一句之后再执行保存的代码,同一个surface即作为Rendertarget被写入又作为surface被读取的时候,似乎会有冲突。
然后SetRenderTarget之后最好再调用一次m_pD3DDevice->Clear(),因为clear是清空当前RenderTarget的。不过视情况也可以不调用。
然后SetRenderTarget之后最好再调用一次m_pD3DDevice->Clear(),因为clear是清空当前RenderTarget的。不过视情况也可以不调用。
#2
不行,试了一下,这下保存的纹理啥都没了.
我到现在仍然对这一系列的执行过程很不理解,您能写一个正确的实现步骤么?
#3
我说的流程是这样的:
m_pD3DDevice->GetRenderTarget(0, &m_pOldSurface);
m_pD3DDevice->SetRenderTarget(0, m_pSurface);
m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, m_BackGroundColor, 1.0f, 0);
m_pD3DDevice->BeginScene();
RECT rcPos = { 0, 0, 176, 124 };
RenderObj(m_pTexture, 300, 100, &rcPos, 0xff808080); // 渲染函数就不必贴出来了,就是设置顶点,设置纹理,然后DrawPrimitiveUP
m_pD3DDevice->EndScene();
m_pD3DDevice->SetRenderTarget(0, m_pOldSurface);
if (GetAsyncKeyState('S') & 0x8000f)
{
RECT rcTex = { 0, 0, 88, 31 };
D3DXSaveSurfaceToFile("out.png", D3DXIFF_PNG, m_pSurface, 0, &rcTex);
}
#4
还是不行,
这样的话,首先运行后程序窗口全花了,然后生成的纹理是一张0xffff00ff颜色的图片
#5
程序窗口花了是因为我把present省略了,你在m_pD3DDevice->SetRenderTarget(0, m_pOldSurface)之前添上去就行。
生成纹理为什么有问题我就不清楚了,这个流程在我这边没问题。或者你检查一下Clear的位置看看。
生成纹理为什么有问题我就不清楚了,这个流程在我这边没问题。或者你检查一下Clear的位置看看。
#6
..
我改了没用,还是那个样子
#7
void CRender::RenderExample()
{
m_pD3DDevice->GetRenderTarget(0, &m_pOldSurface);
m_pD3DDevice->SetRenderTarget(0, m_pSurface);
m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, m_BackGroundColor, 1.0f, 0);
m_pD3DDevice->BeginScene();
RECT rcPos = { 0, 0, 176, 124 };
RenderObj(m_pTexture, 300, 100, &rcPos, 0xff808080);
m_pD3DDevice->EndScene();
m_pD3DDevice->Present(NULL, NULL, NULL, NULL);
m_pD3DDevice->SetRenderTarget(0, m_pOldSurface);
if (GetAsyncKeyState('S') & 0x8000f)
{
RECT rcTex = { 0, 0, 88, 31 };
D3DXSaveSurfaceToFile("out.png", D3DXIFF_PNG, m_pSurface, 0, &rcTex);
}
}
void CRender::InitData()
{
HRESULT hr = E_FAIL;
D3DXIMAGE_INFO info;
char FileName[64] = "src.png";
D3DXGetImageInfoFromFile(FileName, &info);
hr = D3DXCreateTextureFromFileEx(m_pD3DDevice, FileName, info.Width, info.Height,
D3DFMT_FROM_FILE, 0, info.Format, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_DEFAULT, 0, NULL, NULL, &m_pTexture);
D3DXCreateTexture(m_pD3DDevice, 88, 31, 0, D3DUSAGE_RENDERTARGET, info.Format, D3DPOOL_DEFAULT, &m_pDstTexture);
m_pDstTexture->GetSurfaceLevel(0, &m_pSurface);
}
代码贴出来,
和你的一样吧,
花屏,输出的纹理还是0xffff00ff色的
#8
的确奇怪。
我这边的确没问题来着,代码虽然有不同,流程是一样的:
我这边的确没问题来着,代码虽然有不同,流程是一样的:
//-----------------------------------------------------------------------------
#include <d3d9.h>
#include <d3dx9.h>
#pragma warning( disable : 4996 ) // disable deprecated warning
#include <strsafe.h>
#pragma warning( default : 4996 )
//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
LPDIRECT3D9 g_pD3D = NULL; // Used to create the D3DDevice
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; // Our rendering device
LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL; // Buffer to hold Vertices
LPDIRECT3DTEXTURE9 m_pTexture;
LPDIRECT3DTEXTURE9 m_pDstTexture;
LPDIRECT3DSURFACE9 m_pSurface;
// A structure for our custom vertex type
struct CUSTOMVERTEX
{
FLOAT x, y, z, rhw; // The transformed position for the vertex
DWORD color; // The vertex color
};
// Our custom FVF, which describes our custom vertex structure
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)
//-----------------------------------------------------------------------------
// Name: InitD3D()
// Desc: Initializes Direct3D
//-----------------------------------------------------------------------------
HRESULT InitD3D( HWND hWnd )
{
// Create the D3D object.
if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
return E_FAIL;
// Set up the structure used to create the D3DDevice
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof( d3dpp ) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
// Create the D3DDevice
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) )
{
return E_FAIL;
}
HRESULT hr = E_FAIL;
D3DXCreateTexture(g_pd3dDevice, 256, 256, 0, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pDstTexture);
m_pDstTexture->GetSurfaceLevel(0, &m_pSurface);
return S_OK;
}
//-----------------------------------------------------------------------------
HRESULT InitVB()
{
// Initialize three Vertices for rendering a triangle
CUSTOMVERTEX Vertices[] =
{
{ 150.0f, 50.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color
{ 250.0f, 250.0f, 0.5f, 1.0f, 0xff00ff00, },
{ 50.0f, 250.0f, 0.5f, 1.0f, 0xff00ffff, },
};
if( FAILED( g_pd3dDevice->CreateVertexBuffer( 3 * sizeof( CUSTOMVERTEX ),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
{
return E_FAIL;
}
// Now we fill the vertex buffer. To do this, we need to Lock() the VB to
// gain access to the Vertices. This mechanism is required becuase vertex
// buffers may be in device memory.
VOID* pVertices;
if( FAILED( g_pVB->Lock( 0, sizeof( Vertices ), ( void** )&pVertices, 0 ) ) )
return E_FAIL;
memcpy( pVertices, Vertices, sizeof( Vertices ) );
g_pVB->Unlock();
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: Cleanup()
// Desc: Releases all previously initialized objects
//-----------------------------------------------------------------------------
VOID Cleanup()
{
if( g_pVB != NULL )
g_pVB->Release();
if( g_pd3dDevice != NULL )
g_pd3dDevice->Release();
if( g_pD3D != NULL )
g_pD3D->Release();
}
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID Render()
{
LPDIRECT3DSURFACE9 m_pOldSurface;
g_pd3dDevice->GetRenderTarget(0, &m_pOldSurface);
g_pd3dDevice->SetRenderTarget(0, m_pSurface);
// Clear the backbuffer to a blue color
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 );
// Begin the scene
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 );
// End the scene
g_pd3dDevice->EndScene();
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
g_pd3dDevice->SetRenderTarget(0, m_pOldSurface);
if (GetAsyncKeyState('S') & 0x8000f)
{
D3DXSaveSurfaceToFile(L"D://out.png", D3DXIFF_PNG, m_pSurface, 0, 0);
}
}
//-----------------------------------------------------------------------------
// Name: MsgProc()
// Desc: The window's message handler
//-----------------------------------------------------------------------------
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_DESTROY:
Cleanup();
PostQuitMessage( 0 );
return 0;
}
return DefWindowProc( hWnd, msg, wParam, lParam );
}
//-----------------------------------------------------------------------------
// Name: wWinMain()
// Desc: The application's entry point
//-----------------------------------------------------------------------------
INT WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT )
{
UNREFERENCED_PARAMETER( hInst );
// Register the window class
WNDCLASSEX wc =
{
sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L,
GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,
L"D3D Tutorial", NULL
};
RegisterClassEx( &wc );
// Create the application's window
HWND hWnd = CreateWindow( L"D3D Tutorial", L"D3D Tutorial 02: Vertices",
WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
NULL, NULL, wc.hInstance, NULL );
// Initialize Direct3D
if( SUCCEEDED( InitD3D( hWnd ) ) )
{
// Create the vertex buffer
if( SUCCEEDED( InitVB() ) )
{
// Show the window
ShowWindow( hWnd, SW_SHOWDEFAULT );
UpdateWindow( hWnd );
// Enter the message loop
MSG msg;
ZeroMemory( &msg, sizeof( msg ) );
while( msg.message != WM_QUIT )
{
if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
Render();
}
}
}
UnregisterClass( L"D3D Tutorial", wc.hInstance );
return 0;
}
#9
或者,如果可以的话,你把整个项目都发给我吧,我实际调试一下看看。
silenker#live.com
把#替换成@
silenker#live.com
把#替换成@
#10
我复制了你的代码,编译之后,结果也花屏了,但是输出的纹理可以看到三角形,然而这个纹理背景也还是有花屏的颜色.
我估计这是我笔记本本身的问题,
但是你这个起码还能看到三角形,我那个直接就是一个0xffff00ff背景色.
花屏我看是没办法了.
#11
发过去了。
#12
印象中你的笔记本用的是集成显卡吧,不知道更新驱动能不能解决问题。
#13
以前是,后里又换了个独显的,但很差,ATI MOBILITY RADEON X300
机子是hp 6230
#14
还没收到- -
QQ 一七三二八一九零八
QQ 一七三二八一九零八
#1
在 m_pD3DDevice->SetRenderTarget(0, m_pOldSurface);这一句之后再执行保存的代码,同一个surface即作为Rendertarget被写入又作为surface被读取的时候,似乎会有冲突。
然后SetRenderTarget之后最好再调用一次m_pD3DDevice->Clear(),因为clear是清空当前RenderTarget的。不过视情况也可以不调用。
然后SetRenderTarget之后最好再调用一次m_pD3DDevice->Clear(),因为clear是清空当前RenderTarget的。不过视情况也可以不调用。
#2
不行,试了一下,这下保存的纹理啥都没了.
我到现在仍然对这一系列的执行过程很不理解,您能写一个正确的实现步骤么?
#3
我说的流程是这样的:
m_pD3DDevice->GetRenderTarget(0, &m_pOldSurface);
m_pD3DDevice->SetRenderTarget(0, m_pSurface);
m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, m_BackGroundColor, 1.0f, 0);
m_pD3DDevice->BeginScene();
RECT rcPos = { 0, 0, 176, 124 };
RenderObj(m_pTexture, 300, 100, &rcPos, 0xff808080); // 渲染函数就不必贴出来了,就是设置顶点,设置纹理,然后DrawPrimitiveUP
m_pD3DDevice->EndScene();
m_pD3DDevice->SetRenderTarget(0, m_pOldSurface);
if (GetAsyncKeyState('S') & 0x8000f)
{
RECT rcTex = { 0, 0, 88, 31 };
D3DXSaveSurfaceToFile("out.png", D3DXIFF_PNG, m_pSurface, 0, &rcTex);
}
#4
还是不行,
这样的话,首先运行后程序窗口全花了,然后生成的纹理是一张0xffff00ff颜色的图片
#5
程序窗口花了是因为我把present省略了,你在m_pD3DDevice->SetRenderTarget(0, m_pOldSurface)之前添上去就行。
生成纹理为什么有问题我就不清楚了,这个流程在我这边没问题。或者你检查一下Clear的位置看看。
生成纹理为什么有问题我就不清楚了,这个流程在我这边没问题。或者你检查一下Clear的位置看看。
#6
..
我改了没用,还是那个样子
#7
void CRender::RenderExample()
{
m_pD3DDevice->GetRenderTarget(0, &m_pOldSurface);
m_pD3DDevice->SetRenderTarget(0, m_pSurface);
m_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, m_BackGroundColor, 1.0f, 0);
m_pD3DDevice->BeginScene();
RECT rcPos = { 0, 0, 176, 124 };
RenderObj(m_pTexture, 300, 100, &rcPos, 0xff808080);
m_pD3DDevice->EndScene();
m_pD3DDevice->Present(NULL, NULL, NULL, NULL);
m_pD3DDevice->SetRenderTarget(0, m_pOldSurface);
if (GetAsyncKeyState('S') & 0x8000f)
{
RECT rcTex = { 0, 0, 88, 31 };
D3DXSaveSurfaceToFile("out.png", D3DXIFF_PNG, m_pSurface, 0, &rcTex);
}
}
void CRender::InitData()
{
HRESULT hr = E_FAIL;
D3DXIMAGE_INFO info;
char FileName[64] = "src.png";
D3DXGetImageInfoFromFile(FileName, &info);
hr = D3DXCreateTextureFromFileEx(m_pD3DDevice, FileName, info.Width, info.Height,
D3DFMT_FROM_FILE, 0, info.Format, D3DPOOL_DEFAULT, D3DX_FILTER_NONE, D3DX_DEFAULT, 0, NULL, NULL, &m_pTexture);
D3DXCreateTexture(m_pD3DDevice, 88, 31, 0, D3DUSAGE_RENDERTARGET, info.Format, D3DPOOL_DEFAULT, &m_pDstTexture);
m_pDstTexture->GetSurfaceLevel(0, &m_pSurface);
}
代码贴出来,
和你的一样吧,
花屏,输出的纹理还是0xffff00ff色的
#8
的确奇怪。
我这边的确没问题来着,代码虽然有不同,流程是一样的:
我这边的确没问题来着,代码虽然有不同,流程是一样的:
//-----------------------------------------------------------------------------
#include <d3d9.h>
#include <d3dx9.h>
#pragma warning( disable : 4996 ) // disable deprecated warning
#include <strsafe.h>
#pragma warning( default : 4996 )
//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
LPDIRECT3D9 g_pD3D = NULL; // Used to create the D3DDevice
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; // Our rendering device
LPDIRECT3DVERTEXBUFFER9 g_pVB = NULL; // Buffer to hold Vertices
LPDIRECT3DTEXTURE9 m_pTexture;
LPDIRECT3DTEXTURE9 m_pDstTexture;
LPDIRECT3DSURFACE9 m_pSurface;
// A structure for our custom vertex type
struct CUSTOMVERTEX
{
FLOAT x, y, z, rhw; // The transformed position for the vertex
DWORD color; // The vertex color
};
// Our custom FVF, which describes our custom vertex structure
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)
//-----------------------------------------------------------------------------
// Name: InitD3D()
// Desc: Initializes Direct3D
//-----------------------------------------------------------------------------
HRESULT InitD3D( HWND hWnd )
{
// Create the D3D object.
if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
return E_FAIL;
// Set up the structure used to create the D3DDevice
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof( d3dpp ) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
// Create the D3DDevice
if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice ) ) )
{
return E_FAIL;
}
HRESULT hr = E_FAIL;
D3DXCreateTexture(g_pd3dDevice, 256, 256, 0, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &m_pDstTexture);
m_pDstTexture->GetSurfaceLevel(0, &m_pSurface);
return S_OK;
}
//-----------------------------------------------------------------------------
HRESULT InitVB()
{
// Initialize three Vertices for rendering a triangle
CUSTOMVERTEX Vertices[] =
{
{ 150.0f, 50.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color
{ 250.0f, 250.0f, 0.5f, 1.0f, 0xff00ff00, },
{ 50.0f, 250.0f, 0.5f, 1.0f, 0xff00ffff, },
};
if( FAILED( g_pd3dDevice->CreateVertexBuffer( 3 * sizeof( CUSTOMVERTEX ),
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
{
return E_FAIL;
}
// Now we fill the vertex buffer. To do this, we need to Lock() the VB to
// gain access to the Vertices. This mechanism is required becuase vertex
// buffers may be in device memory.
VOID* pVertices;
if( FAILED( g_pVB->Lock( 0, sizeof( Vertices ), ( void** )&pVertices, 0 ) ) )
return E_FAIL;
memcpy( pVertices, Vertices, sizeof( Vertices ) );
g_pVB->Unlock();
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: Cleanup()
// Desc: Releases all previously initialized objects
//-----------------------------------------------------------------------------
VOID Cleanup()
{
if( g_pVB != NULL )
g_pVB->Release();
if( g_pd3dDevice != NULL )
g_pd3dDevice->Release();
if( g_pD3D != NULL )
g_pD3D->Release();
}
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID Render()
{
LPDIRECT3DSURFACE9 m_pOldSurface;
g_pd3dDevice->GetRenderTarget(0, &m_pOldSurface);
g_pd3dDevice->SetRenderTarget(0, m_pSurface);
// Clear the backbuffer to a blue color
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 );
// Begin the scene
if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
{
g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) );
g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 );
// End the scene
g_pd3dDevice->EndScene();
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
g_pd3dDevice->SetRenderTarget(0, m_pOldSurface);
if (GetAsyncKeyState('S') & 0x8000f)
{
D3DXSaveSurfaceToFile(L"D://out.png", D3DXIFF_PNG, m_pSurface, 0, 0);
}
}
//-----------------------------------------------------------------------------
// Name: MsgProc()
// Desc: The window's message handler
//-----------------------------------------------------------------------------
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
switch( msg )
{
case WM_DESTROY:
Cleanup();
PostQuitMessage( 0 );
return 0;
}
return DefWindowProc( hWnd, msg, wParam, lParam );
}
//-----------------------------------------------------------------------------
// Name: wWinMain()
// Desc: The application's entry point
//-----------------------------------------------------------------------------
INT WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT )
{
UNREFERENCED_PARAMETER( hInst );
// Register the window class
WNDCLASSEX wc =
{
sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L,
GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,
L"D3D Tutorial", NULL
};
RegisterClassEx( &wc );
// Create the application's window
HWND hWnd = CreateWindow( L"D3D Tutorial", L"D3D Tutorial 02: Vertices",
WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
NULL, NULL, wc.hInstance, NULL );
// Initialize Direct3D
if( SUCCEEDED( InitD3D( hWnd ) ) )
{
// Create the vertex buffer
if( SUCCEEDED( InitVB() ) )
{
// Show the window
ShowWindow( hWnd, SW_SHOWDEFAULT );
UpdateWindow( hWnd );
// Enter the message loop
MSG msg;
ZeroMemory( &msg, sizeof( msg ) );
while( msg.message != WM_QUIT )
{
if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
Render();
}
}
}
UnregisterClass( L"D3D Tutorial", wc.hInstance );
return 0;
}
#9
或者,如果可以的话,你把整个项目都发给我吧,我实际调试一下看看。
silenker#live.com
把#替换成@
silenker#live.com
把#替换成@
#10
我复制了你的代码,编译之后,结果也花屏了,但是输出的纹理可以看到三角形,然而这个纹理背景也还是有花屏的颜色.
我估计这是我笔记本本身的问题,
但是你这个起码还能看到三角形,我那个直接就是一个0xffff00ff背景色.
花屏我看是没办法了.
#11
发过去了。
#12
印象中你的笔记本用的是集成显卡吧,不知道更新驱动能不能解决问题。
#13
以前是,后里又换了个独显的,但很差,ATI MOBILITY RADEON X300
机子是hp 6230
#14
还没收到- -
QQ 一七三二八一九零八
QQ 一七三二八一九零八