Render to texture problem...

Started by
9 comments, last by Evil Steve 13 years, 4 months ago
Now i realize i've asked this type of question billions of times on here, but this time everything works.......except for some reason nothing renders to the texture, i've checked support for the formats, i've created the texture and the rendertosurface and got the surface level, and still nothing gets rendered to the texture. I'm using a box mesh to try it, i'm assuming they don't have tex coords allplied to them, that's why it's not working...i have also made a screen quad and tested it on that, same thing. so here now for your viewing mispleasure is the code.

#include "IrrEngine.h"#pragma comment(lib,"IrrEngine.lib")IrrEngine::IrrRenderWindow* win = new IrrEngine::IrrRenderWindow();IrrEngine::IrrD3D9Renderer* render = new IrrEngine::IrrD3D9Renderer();IrrEngine::IrrInput*		Input = new IrrEngine::IrrInput();IrrEngine::CSprites*		Radar;IrrEngine::CSprites*		Border;IrrEngine::CSprites*		Enemy;IrrEngine::CSprites*		HealthBar;IrrEngine::CSprites*		Health;IrrEngine::Font*			font;IrrEngine::ScreenQuad*		Quad;IrrEngine::RenderTarget*	Target;int HealthPoints = 6000;int maxHealthPoint = 1000;float enemyX = 60.0f, enemyY = 60.0f;IDirect3DSurface9* sur;IDirect3DTexture9* tex;ID3DXRenderToSurface* rtSur;ID3DXEffect* m_pEffect;D3DXHANDLE pTex;D3DXHANDLE pTech;int WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in_opt LPSTR lpCmdLine, __in int nShowCmd ){		win->CreateRenderWindow("IrrGame",0,0,512,512);		render->CreateD3D9Renderer(512,512,false);	Input->CreateInput();		Quad = new IrrEngine::ScreenQuad();	Target = new IrrEngine::RenderTarget();	IrrEngine::CEntityManager* mgr = new IrrEngine::CEntityManager();	Radar = new IrrEngine::CSprites();	Radar->loadSpriteImage("Batman.jpg");	Radar->SetAlphaColor(255,255,255,255);	Radar->SetDrawRegion(0,0,300,300);	Radar->SetTransparency(255,255,255,255);	Radar->SetEntName("Batman");	Radar->SetEntPosition(0,0,0);	mgr->addEntity(Radar);	Target->CreateRenderTarget(win->getWindowWidth(),win->getWindowHeight(),1,"");			font = new IrrEngine::Font();	font->IrrCreateFont(32,0,0,0,0,0,0,0,0,0,0,0,0,L"Ariel");		Quad->CreateScreenQuad(0,0,win->getWindowWidth()-50,win->getWindowHeight());				//win->MessageLoopStart();	ID3DXMesh* Sphere;	HR(D3DXCreateBox(IrrEngine::IrrD3D9Renderer::getD3DDev9(),50,40,40,&Sphere,NULL));	HR(D3DXCreateTexture(IrrEngine::IrrD3D9Renderer::getD3DDev9(),512,512,40,D3DUSAGE_RENDERTARGET,D3DFMT_X8B8G8R8,D3DPOOL_DEFAULT,&tex));	HR(D3DXCreateRenderToSurface(IrrEngine::IrrD3D9Renderer::getD3DDev9(),512,512,D3DFMT_X8B8G8R8,TRUE,D3DFMT_D16,&rtSur));	D3DCAPS9 caps;	//render->getD3DDev9()->GetDeviceCaps(&caps);	D3DDISPLAYMODE Mode;	render->getD3D9()->GetAdapterDisplayMode(0,&Mode);	MSG msg;	while(true)	{		while(PeekMessage(&msg,NULL,NULL,NULL,PM_REMOVE))		{			TranslateMessage(&msg);			DispatchMessage(&msg);		}		if(msg.message == WM_QUIT)		{			break;		}		Input->UpdateInput();		if (Input->KeyPressed(DIK_ESCAPE))		{			break;		}		// Windowed.		if(FAILED(render->getD3D9()->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Mode.Format, 			D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_X8R8G8B8)))			PostQuitMessage(0);		if(FAILED(render->getD3D9()->CheckDepthStencilMatch(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Mode.Format,			D3DFMT_X8R8G8B8, D3DFMT_D24X8)))		 PostQuitMessage(0);		// Fullscreen.		if(FAILED(render->getD3D9()->CheckDeviceFormat(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, 			D3DUSAGE_RENDERTARGET, D3DRTYPE_TEXTURE, D3DFMT_X8R8G8B8)))			 PostQuitMessage(0);		if(FAILED(render->getD3D9()->CheckDepthStencilMatch(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8,			D3DFMT_X8R8G8B8, D3DFMT_D24X8)))			 PostQuitMessage(0);			//render->RenderBegin(0,0,0,1);					//font->IrrDrawText(100,500,D3DCOLOR_ARGB(255,255,255,255),"Hello");		//render->RenderEnd();		D3DVIEWPORT9 View;		View.X = 0;		View.Y = 0;		View.Width = 512;		View.Height = 512;		View.MinZ = 0.0f;		View.MaxZ  = 1.0f;		HR(tex->GetSurfaceLevel(0,&sur));		rtSur->BeginScene(sur,&View);		render->getD3DDev9()->Clear(0,0,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,D3DCOLOR_ARGB(0,255,255,0),1,1);		D3DXMATRIX pView2;		D3DXMATRIX pProj2;		D3DXMATRIX pWorld2;		D3DXMatrixLookAtLH(&pView2,&			D3DXVECTOR3(0,0,150),			&D3DXVECTOR3(0,0,0),			&D3DXVECTOR3(0,1,0));		render->getD3DDev9()->SetTransform(D3DTS_VIEW,&pView2);		D3DXMatrixPerspectiveFovLH(&pProj2,45,1.333,10,10000);		HR(render->getD3DDev9()->SetTransform(D3DTS_PROJECTION,&pProj2));			rtSur->EndScene(D3DX_FILTER_NONE);		render->RenderBegin(0,0,1,0);		render->getD3DDev9()->Clear(0,0,D3DCLEAR_ZBUFFER,D3DCOLOR_ARGB(255,255,255,255),1.0f,1);		D3DXMATRIX pView;		D3DXMATRIX pProj;		D3DXMATRIX pWorld;		D3DXMatrixLookAtLH(&pView,&			D3DXVECTOR3(0,0,150),			&D3DXVECTOR3(0,0,0),			&D3DXVECTOR3(0,1,0));		render->getD3DDev9()->SetTransform(D3DTS_VIEW,&pView);		D3DXMatrixPerspectiveFovLH(&pProj,45,1.333,10,10000);		HR(render->getD3DDev9()->SetTransform(D3DTS_PROJECTION,&pProj));		D3DXMatrixTranslation(&pWorld,0,0,0);		HR(render->getD3DDev9()->SetTransform(D3DTS_WORLD,&pWorld));		HR(render->getD3DDev9()->SetRenderState(D3DRS_LIGHTING,false));		render->getD3DDev9()->SetTexture(0,tex);				HR(Sphere->DrawSubset(0));render->RenderEnd();				}			return 0;}


I'll also supply a picture of the out put if asked (I'll undoubtedbly will, just a formality) god....other graphics engines always nail this subject down....WOE IS ME?
Advertisement
Quote:Original post by Enerjak
I'm using a box mesh to try it, i'm assuming they don't have tex coords allplied to them, that's why it's not working
Correct. From the documentation:
Quote:This function creates a mesh with the D3DXMESH_MANAGED creation option and D3DFVF_XYZ | D3DFVF_NORMAL flexible vertex format (FVF).


Quote:Original post by Enerjak
I have also made a screen quad and tested it on that, same thing. so here now for your viewing mispleasure is the code.
By "same thing", you mean it's not working? What does it show up as? Black? Yellow? No quad? Does Pix show anything interesting / relevant?
the quad shows up black when the texture is applied, here is the pic of the output

render.png?t=1292332271
What does Pix show? Does the texture look ok when you render the quad? Does the quad have texture coordinates?
yes it does, the quad still looks black, the pic shows the cube with the texture applied to it, now if u'll wait a moment i'll take a pic with the screen quad applied and the quad's texture co-ordnates + vertex layout.

 		QuadBuffer->Lock(0,0,(void**)&QuadVerts,0);		QuadVerts[0] = VertexPCT(X,Y,1.0,1.0,0.0f,0.0f);		QuadVerts[1] = VertexPCT(Width,Y,1.0,1.0,0.0,1.0);		QuadVerts[2] = VertexPCT(Y, Height,1.0,1.0,1.0,0.0);		QuadVerts[3] = VertexPCT(Width, Height,1.0f,1.0f,1.0,1.0);		QuadBuffer->Unlock();


and it shows up on screen, but again it shows as black. I've seen in another deom by frank luna he uses two triangles, i used 4 so it was eaier to specefy the top left and right bottom corners
[link]http://img.photobucket.com/albums/v238/adarksoul/ateempt_2.png?t=1292357300[/link]

here is the link reguarding usage of the screen quad with the render target.

EDIT: always forget the code tags, image tags.... wish there was buttons to just insert them automatically
you know what, i'm just going to use the rendertotex example from Frank'd book and try to add my own stuff to it without breaking it down.........
...and what does Pix show? Does it show that the render target has what you expect on it?
i totally forgot about pix lol
Just ran pix and since i've never used it before i'm a bit confused about the output.

This topic is closed to new replies.

Advertisement