Jump to content
  • Advertisement
Sign in to follow this  
vNistelrooy

Rendering problems

This topic is 4842 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Alright I am setting up all the matrices like that:
	D3DXMATRIX WorldTransformationMatrix;
	D3DXMatrixIdentity(&WorldTransformationMatrix);
	d3d->SetTransform(D3DTS_WORLD,&WorldTransformationMatrix);

	D3DXVECTOR3 vEyePt(0.0f,0.0f,0.0f);
	D3DXVECTOR3 vLookatPt(0.0f,0.0f,1.0f);
	D3DXVECTOR3 vUpVec(0.0f,1.0f,0.0f);
	D3DXMATRIX ViewMatrix;
	D3DXMatrixLookAtLH(&ViewMatrix,&vEyePt,&vLookatPt,&vUpVec);
	d3d->SetTransform(D3DTS_VIEW,&ViewMatrix);

	D3DXMATRIX ProjectionMatrix;
	D3DXMatrixPerspectiveFovLH(	&ProjectionMatrix,
					45.0f*PI/180.0f,
					800.0f/600.0f,
					0.05f,
					100.0f);
	d3d->SetTransform(D3DTS_PROJECTION,&(D3DXMATRIX)ProjectionMatrix);

I'm creating the vertex buffer like this:
	VER	vertices[3];
	vertices[0].color=0xff908070;
	vertices[0].x=1.50;
	vertices[0].y=1.50;
	vertices[0].z=10.0;
	vertices[1].color=0xff908070;
	vertices[1].x=1.00;
	vertices[1].y=1.50;
	vertices[1].z=10.0;
	vertices[2].color=0xff908070;
	vertices[2].x=1.50;
	vertices[2].y=1.00;
	vertices[2].z=10.0;

	d3d->CreateVertexBuffer(3*sizeof(VER),0,FVF,D3DPOOL_DEFAULT,&vb,NULL);

	VER *pvert;
	hr=vb->Lock(0,0,(void**)&pvert,0);
	memcpy(pvert,vertices,3*sizeof(VER));
	vb->Unlock();

And render this way:
	d3d->BeginScene();
	d3d->SetStreamSource(0,vb,0,sizeof(VER));
	d3d->SetFVF(FVF);
	d3d->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
	d3d->EndScene();

FVF and VER are declared this way:
struct CUSTOMVERTEX
{
	float		x,y,z;
	D3DCOLOR	color;
};

#define	FVF		D3DFVF_XYZ|D3DFVF_DIFFUSE

The problem: Nothing shows up. Rendering the D3DFVF_XYZRHW way is ok, so I guess something is with the matrices. Anything I missed? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
I can't see anything obviously wrong with your fragments of code, but a few things to think about:


  1. Are you clearing the depth buffer correctly on each frame? clearing to 0.0f can stop things being drawn, as could not clearing it at all.
  2. Try moving the camera back and changing the near plane - values for the near plane that are less than 1.0f (yours is 0.05f) are known to cause numerical instabilities in the projection matrix.
  3. What does the debug output tell you? is it complaining about a failed call - my guess is that it is [smile] crank up the output to maximum and see if it's giving you any clues. Check the link in my signiture below if you're not sure how to do this.


hth
Jack

Share this post


Link to post
Share on other sites
I have already tried the consulting the debug output, as well as manually checking the HRESULT of all d3d functions. Nothing. I tried moving the near plane to 1.0f, no luck. Anyway OpenGL renders correctly with the near plane at 0.05f. I have moved the eye point to (0,0,-10), same result. [crying]

Share this post


Link to post
Share on other sites
I clear this way:
d3d->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,D3DCOLOR_RGBA(0,0,255,0),1.0f,0);

and swap the buffers this way:
d3d->Present(NULL,NULL,hWnd,NULL);

Share this post


Link to post
Share on other sites
And if this helps at all I create the d3d device with the following flags:
D3DCREATE_MULTITHREADED,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
D3DCREATE_PUREDEVICE,
D3DCREATE_NOWINDOWCHANGES

PS: tjsmith, I have brought you back to the light side. [smile]

Share this post


Link to post
Share on other sites
Quote:
Original post by tjsmith
Also, for debugging your app make sure all culling is disabled and D3D lighting is off.

I hadn't thought of the winding order... I'm never any good at working those out from pure code (always need a pen and paper to draw it!).

If you set D3DRS_CULLMODE to D3DCULL_NONE and your triangle appears then you know it's your 3 vertices that are in the wrong order.

If that does turn out to be the issue, then you can just go through the vertices[] lines and swap the 0/1/2 values around until the triangle appears as expected.


hth
Jack

Share this post


Link to post
Share on other sites
Quote:
Original post by jollyjeffers
I hadn't thought of the winding order... I'm never any good at working those out from pure code (always need a pen and paper to draw it!).

If you set D3DRS_CULLMODE to D3DCULL_NONE and your triangle appears then you know it's your 3 vertices that are in the wrong order.

If that does turn out to be the issue, then you can just go through the vertices[] lines and swap the 0/1/2 values around until the triangle appears as expected.


hth
Jack


I'll be beating the dead body of the next person I meet for 24 hours stright. [flaming][flaming][flaming]
Let's see if I can rate both of you up again. Thanks.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!