strechrect失败了. [英] strechrect is getting failed.

查看:92
本文介绍了strechrect失败了.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此处的附加代码strechrect方法失败,并返回-ve值.我正在执行以下操作.请给我我在这里做错了什么.

1.使用CreateOffscreenPlainSurface方法获取屏幕外的表面.
2.修改平面.
3.获取表面的后部缓冲
4.使用strechrect方法将平整表面放到后缓冲区中.

Here in the attached code strechrect method is getting failed and its returning the -ve value. I am doing operations as below. please give me what wrong i am doing here.

1. Getting the offscreenplain surface using CreateOffscreenPlainSurface method.
2. modifying the plain surface.
3. Getting the back buffer of the surface
4. Putting back plain surface to the back buffer using strechrect method.

void CTriangleRenderer::LockSurfaceExtra()
{
	DWORD     bkColor;
	D3DCOLOR Color;
	HDC hdc;
	HRESULT         hr;
	D3DLOCKED_RECT  lockedRect;
	DWORD           *pMem, colorVal;
	RECT          rc, wrc, mrc,destRect;
	int             i, j, k, m, linemin, linemax, linecnt, linesDrawn = 0,pitch;
	//This will hold the back buffer
	IDirect3DSurface9* backbuffer = NULL;
	// Get the surface details
			D3DSURFACE_DESC d3dsd;
	if( NULL == m_pd3dDevice )
		return;

	g_increase=g_increase+5;
	
	m_pd3dDevice->GetBackBuffer( 0,
		0,
		D3DBACKBUFFER_TYPE_MONO,
		&backbuffer );


    //m_pd3dDevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_ARGB(0, 0,0, 0),1.0f,0);


			// Get the back buffer
		
		
	
		m_pd3dDevice->CreateOffscreenPlainSurface(1400,
                                             1100,
                                             D3DFMT_X8R8G8B8,
                                             D3DPOOL_DEFAULT,
                                             &m_pd3dRTSBackup,
                                             NULL);

		

		

		//m_pd3dDevice->UpdateSurface(m_pd3dRTS, NULL, backbuffer, NULL);

		if (m_pd3dRTSBackup != NULL)
		{
			hr = m_pd3dRTSBackup->LockRect(&lockedRect, NULL, 0);
			if (SUCCEEDED(hr))
			{
			  pitch = lockedRect.Pitch / sizeof(DWORD); // DWORD pitch - 32 bits per pixel
			  pMem = (DWORD *)lockedRect.pBits;
			}
			GetClientRect(m_hwnd,&rc);
			
			m_pd3dRTSBackup->GetDesc(&d3dsd);

			for (WORD y = 0; y <d3dsd.Height ; ++y) 
			{
			for (WORD x = 0; x < d3dsd.Width; ++x) 
			{	
				
				pMem[(pitch*y)+x] = D3DCOLOR_ARGB(255, 0,0,0);
		
			}	
			}

			m_pd3dRTSBackup->UnlockRect(); 
		}
		 
		


		 //Copy the offscreen surface to the back buffer
		// Note the use of NULL values for the source and destination RECTs
		// This ensures a copy of the entire surface to the back buffer
		
		m_pd3dDevice->BeginScene();
		
		


		hr=m_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET,   

                                        D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );


		hr=	m_pd3dDevice->StretchRect(m_pd3dRTSBackup,
		NULL,
		backbuffer,
		NULL,
		D3DTEXF_NONE );

		

		
		//D3DXLoadSurfaceFromSurface(backbuffer,NULL,NULL,m_pd3dRTSBackup,NULL,NULL,D3DX_FILTER_NONE,0xFF000000);

		//m_pd3dDevice->UpdateSurface(m_pd3dRTSBackup, NULL, backbuffer, NULL);
		backbuffer->Release();	
		m_pd3dDevice->EndScene();
		// Present the back buffer contents to the display
		m_pd3dDevice->Present ( NULL, NULL, NULL, NULL );
}

推荐答案

您是否查看过StretchRect限制部分
Have you looked at the StretchRect restrictions section here[^]? It contains valuable information as to why this call may fail.


您好,
感谢您的建议.我检查了stretchrect的所有规则,并也遵循了它们.在创建平整表面之后,我尝试将其写为图像文件,但作为主屏幕也无法正确显示.主屏幕数据会附带一些垃圾数据.没有到达我正在做错的地方.以下是主要的设备创建代码.

HRESULT
CRenderer :: Init(IDirect3D9 * pD3D,IDirect3D9Ex * pD3DEx,HWND hwnd,UINT uAdapter)
{
HRESULT hr = S_OK;

D3DPRESENT_PARAMETERS d3dpp;
/* ZeroMemory(& d3dpp,sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.BackBufferHeight = 1100;
d3dpp.BackBufferWidth = 1000;
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY; */


memset(& d3dpp,0,sizeof(D3DPRESENT_PARAMETERS));
d3dpp.BackBufferCount = 1;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.MultiSampleQuality = 0;
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
d3dpp.hDeviceWindow = hwnd;
d3dpp.Flags = 0;
d3dpp.FullScreen_RefreshRateInHz = 0; //窗口模式为0
d3dpp.PresentationInterval = D3DPRESENT_DONOTWAIT;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.EnableAutoDepthStencil = FALSE;
d3dpp.AutoDepthStencilFormat = D3DFMT_UNKNOWN;
d3dpp.Windowed = TRUE;
d3dpp.BackBufferWidth = 1100;
d3dpp.BackBufferHeight = 1000;


D3DCAPS9盖帽;
DWORD dwVertexProcessing;
IFC(pD3D-> GetDeviceCaps(uAdapter,D3DDEVTYPE_HAL,& caps));

如果((caps.DevCaps& D3DDEVCAPS_HWTRANSFORMANDLIGHT)== D3DDEVCAPS_HWTRANSFORMANDLIGHT)
{
dwVertexProcessing = D3DCREATE_HARDWARE_VERTEXPROCESSING;
}
其他
{
dwVertexProcessing = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
}

如果(pD3DEx)
{
IDirect3DDevice9Ex * pd3dDevice = NULL;
IFC(pD3DEx-> CreateDeviceEx(
uAdapter,
D3DDEVTYPE_HAL,
hwnd,
dwVertexProcessing | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
& d3dpp,
NULL,
& m_pd3dDeviceEx
));

IFC(m_p​​d3dDeviceEx-> QueryInterface(__ uuidof(IDirect3DDevice9),reinterpret_cast< void **>(& m_pd3dDevice))));
}
其他
{
assert(pD3D);

IFC(pD3D-> CreateDevice(
uAdapter,
D3DDEVTYPE_HAL,
hwnd,
dwVertexProcessing | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
& d3dpp,
& m_pd3dDevice
));
}

清理:
返回hr;
}
Hi,
Thanks for suggestions. I checked all the rules for stretchrect and following them also. Here after creating the plain surface i tried to write as image file, its also not coming correct as the main screen. some junk data is coming with the main screen data. Not getting where i am doing mistake. Below is the main device creation code.

HRESULT
CRenderer::Init(IDirect3D9 *pD3D, IDirect3D9Ex *pD3DEx, HWND hwnd, UINT uAdapter)
{
HRESULT hr = S_OK;

D3DPRESENT_PARAMETERS d3dpp;
/* ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.BackBufferCount=1;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
d3dpp.BackBufferHeight = 1100;
d3dpp.BackBufferWidth = 1000;
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;*/


memset(&d3dpp, 0, sizeof(D3DPRESENT_PARAMETERS));
d3dpp.BackBufferCount = 1;
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.MultiSampleQuality = 0;
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
d3dpp.hDeviceWindow = hwnd;
d3dpp.Flags = 0;
d3dpp.FullScreen_RefreshRateInHz = 0; // 0 for windowed mode
d3dpp.PresentationInterval = D3DPRESENT_DONOTWAIT;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.EnableAutoDepthStencil = FALSE;
d3dpp.AutoDepthStencilFormat = D3DFMT_UNKNOWN;
d3dpp.Windowed = TRUE;
d3dpp.BackBufferWidth = 1100;
d3dpp.BackBufferHeight = 1000;


D3DCAPS9 caps;
DWORD dwVertexProcessing;
IFC(pD3D->GetDeviceCaps(uAdapter, D3DDEVTYPE_HAL, &caps));

if ((caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == D3DDEVCAPS_HWTRANSFORMANDLIGHT)
{
dwVertexProcessing = D3DCREATE_HARDWARE_VERTEXPROCESSING;
}
else
{
dwVertexProcessing = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
}

if (pD3DEx)
{
IDirect3DDevice9Ex *pd3dDevice = NULL;
IFC(pD3DEx->CreateDeviceEx(
uAdapter,
D3DDEVTYPE_HAL,
hwnd,
dwVertexProcessing | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
&d3dpp,
NULL,
&m_pd3dDeviceEx
));

IFC(m_pd3dDeviceEx->QueryInterface(__uuidof(IDirect3DDevice9), reinterpret_cast<void**>(&m_pd3dDevice)));
}
else
{
assert(pD3D);

IFC(pD3D->CreateDevice(
uAdapter,
D3DDEVTYPE_HAL,
hwnd,
dwVertexProcessing | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
&d3dpp,
&m_pd3dDevice
));
}

Cleanup:
return hr;
}



ss我检查了表面修饰,并且还可以将其保存到.jpg文件中,以查看更改.我来使用Stretchrect方法时遇到错误.
我是否还要处理一个平面对象,这又是一个疑问,该对象是否包含更新后的表面,或者它只是一个没有任何数据的平面?
谢谢你的建议.:)

ss i checked the surface modification and i was able to see the changes by saving to the .jpg file also. ones i come to stretchrect method i am getting the error.
One more doubt I have if I take a plain surface object, is that object contains the updated surface or its an just a plain surface without any data.?
thanks for ur suggestiom.:)


这篇关于strechrect失败了.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆