Skip to main content
gamedev.net
🔒 Locked

Error Rendering.

Started by snoddas14 4 replies 500+ views
Original Post
snoddas14
snoddas14
hey. this is the SECOND time i don understand the Render error. can some one Help me and Explain in a Easy understanding way? The DirectX code
 
bool InitD3D()
{
	if(NULL == (pD3D = Direct3DCreate9(D3D_SDK_VERSION) ) )
	{
		MessageBox(NULL,"Error - Wrong SDK","Error",MB_OK);
		return FALSE;
	}
	D3DDISPLAYMODE d3ddm;
	d3ddm.Format = D3DFMT_X8R8G8B8;
	d3ddm.Height = 480;
	d3ddm.RefreshRate = 0;
	d3ddm.Width = 640;
	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory(&d3dpp,sizeof(d3dpp));
	d3dpp.BackBufferCount = 1;
	d3dpp.BackBufferFormat = d3ddm.Format;
	d3dpp.BackBufferHeight = 480;
	d3dpp.BackBufferWidth = 640;
	d3dpp.hDeviceWindow = wndHandle;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.Windowed = TRUE;

	if(FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wndHandle,D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice)))
	{
		MessageBox(NULL,"Error - Creating Device","Error",MB_OK);
		return FALSE;
	}
	pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
	VertexBuffer();

	return TRUE;
}
void RenderD3D(void)
{
	D3DXMATRIX matView;
	D3DXMATRIX matProj;
	pd3dDevice->Clear(0,NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f,0);
	pd3dDevice->BeginScene();
	pd3dDevice->SetFVF(VertexFVF);
	pd3dDevice->SetStreamSource(0,pD3DVB,0,sizeof(VERTEX));
	pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
	D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3 (0.0f,0.0f,-10.0f),
		&D3DXVECTOR3 (0.0f, 0.0f, 0.0f),
		&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));
	pd3dDevice->SetTransform(D3DTS_VIEW, &matView);
	D3DXMatrixPerspectiveFovLH(&matProj, D3DXToRadian(45), (FLOAT)640/(FLOAT)480, 1.0f, 100.0f);
	pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);
	pd3dDevice->EndScene();
	pd3dDevice->Present(NULL,NULL,NULL,NULL);
}
void Exit()
{
	pd3dDevice->Release();
	pD3D->Release();
	pD3DVB->Release();
}
void VertexBuffer()
{

	VERTEX Verts[] =
	{
		{320.0f, 10.0f, 5.0f, D3DCOLOR_ARGB(100,255,0,0),},
		{160.0f, 400.0f, 5.0f, D3DCOLOR_ARGB(100,0,255,0),},
		{480.0f, 400.0f, 5.0f, D3DCOLOR_ARGB(100,0,0,255),},
	};




	VOID *Void;
	if(D3D_OK(pd3dDevice->CreateVertexBuffer(sizeof(VERTEX)*3,0,D3DFVF_XYZ | D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &pD3DVB, NULL)))
	{
    pD3DVB->Lock(0,0,(void**)&Void, 0);
    memcpy(Void, Verts, sizeof(Verts));
    pD3DVB->Unlock();
	}


}

janta
janta
What is the error ???...

Anyways, you should setup you matrix *before* rendering.
Also, you should create your vertex buffer in the D3DPOOL_MANAGED unless you intend to modify your triangle's shape every frame "on the CPU" (that is not using vertex shader but I don't want to confuse you yet)
What is the value of "VertexFVF" ? Should be = "D3DFVF_XYZ | D3DFVF_DIFFUSE" which you pass to CreateVertexBuffer when you create your vertex buffer.
snoddas14
snoddas14
sorry the error is that it dosent shows anything!
but thanks i gona try it out!

and no, it dident work! i chaged the code to this!

 void VertexBuffer(){		VERTEX Verts[] =	{		{320.0f, 10.0f, 5.0f, D3DCOLOR_ARGB(100,255,0,0),},		{160.0f, 400.0f, 5.0f, D3DCOLOR_ARGB(100,0,255,0),},		{480.0f, 400.0f, 5.0f, D3DCOLOR_ARGB(100,0,0,255),},	};	VOID *Void;	pd3dDevice->CreateVertexBuffer(3*sizeof(VERTEX),0,D3DFVF_XYZ | D3DFVF_DIFFUSE, D3DPOOL_MANAGED, &pD3DVB, NULL);    pD3DVB->Lock(0,0,(void**)&Void, 0);    memcpy(Void, Verts, sizeof(Verts));    pD3DVB->Unlock();	}bool InitD3D(){	if(NULL == (pD3D = Direct3DCreate9(D3D_SDK_VERSION) ) )	{		MessageBox(NULL,"Error - Wrong SDK","Error",MB_OK);		return FALSE;	}	D3DPRESENT_PARAMETERS d3dpp;	ZeroMemory(&d3dpp,sizeof(d3dpp));	d3dpp.BackBufferCount = 1;	d3dpp.BackBufferFormat = D3DFMT_A8R8G8B8;	d3dpp.BackBufferHeight = 480;	d3dpp.BackBufferWidth = 640;	d3dpp.hDeviceWindow = wndHandle;	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;	d3dpp.Windowed = TRUE;	if(FAILED(pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wndHandle,D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &pd3dDevice)))	{		MessageBox(NULL,"Error - Creating Device","Error",MB_OK);		return FALSE;	}		VertexBuffer();	pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);	return TRUE;}void RenderD3D(void){	D3DXMATRIX matView;	D3DXMATRIX matProj;	D3DXMATRIX matRotateY;	pd3dDevice->Clear(0,NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f,0);	pd3dDevice->BeginScene();	pd3dDevice->SetFVF(VertexFVF);	D3DXMatrixRotationY(&matRotateY, D3DXToRadian(45));	pd3dDevice->SetTransform(D3DTS_WORLD, &matRotateY);	D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3 (0.0f,0.0f,-10.0f),		&D3DXVECTOR3 (0.0f, 0.0f, 0.0f),		&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));	pd3dDevice->SetTransform(D3DTS_VIEW, &matView);	D3DXMatrixPerspectiveFovLH(&matProj, D3DXToRadian(45), (FLOAT)640/(FLOAT)480, 1.0f, 100.0f);	pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);		pd3dDevice->SetStreamSource(0,pD3DVB,0,sizeof(VERTEX));	pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);	pd3dDevice->EndScene();	pd3dDevice->Present(NULL,NULL,NULL,NULL);}void Exit(){	if(pd3dDevice != NULL)	pd3dDevice->Release();	if(pD3D !=NULL)	pD3D->Release();	if(pD3DVB !=NULL)	pD3DVB->Release();}
Evil Steve
Evil Steve
You're not looking at your triangle, you're looking over it's shoulder.

Your view matrix has the camera at (0, 0, -10), looking at (0, 0, 0), but your triangle is way off to the bottom right of the camera; the closest edge extends from (160, 400, 5) to (320, 10, 5).

Try moving your camer back to around -1000 (And change your projection matrix so the far clip plane is past that, like 1100 or so, and you should see it.
snoddas14
snoddas14
HAHAHAHAHAHAHAHAHAHAHA
What an smart ass i am!
nemesisgeek
nemesisgeek
I'm a GL-head myself - never done much DX - but I made the same mistake all too many times when I was starting out.
hackerkey://v4sw7+8CHS$hw6+8ln6pr8O$ck4ma4+9u5Lw7VX$m0l5Ri8ONotepad++/e3+8t3b8AORTen7+9a17s0r4g8OP

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.