Is there Any Error

Started by
3 comments, last by Buckeye 16 years, 2 months ago
Hi Im new to DX I try to Program with it but something was wrong, I didnt know how to fix So I post it in here , and have you look it up for me THanks I couldnt see my triangle but a blue windows 800x600 My Triangle lies on Plane X0Y , My Camera floating above and look down to XOY Plane , it has 0,0,1 Vector is a Up Vector; #define CUSTOMFVF (D3DFVF_XYZ|D3DFVF_DIFFUSE) struct CVertex { float x,y,z; DWORD Diff; };
Quote: void Init() { CVertex Data[3]={{-50,0,0,D3DCOLOR_XRGB(255,0,0)},{50,0,0,D3DCOLOR_XRGB(0,255,0)},{0,0,100,D3DCOLOR_XRGB(0,0,255)}}; d3ddev->CreateVertexBuffer(3*sizeof(CVertex),0,CUSTOMFVF,D3DPOOL_MANAGED,&Buffer,NULL); void *p; Buffer->Lock(0,0,&p,0); memcpy(p,Data,sizeof(Data)); Buffer->Unlock(); D3DXMATRIX MatView; D3DXMatrixLookAtLH(&MatView,&D3DXVECTOR3(100,100,100),&D3DXVECTOR3(0,0,0),&D3DXVECTOR3(0,0,1)); d3ddev->SetTransform(D3DTS_VIEW,&MatView); D3DXMATRIX Proj; D3DXMatrixPerspectiveFovLH(&Proj,60,float(WID)/HI,1,100); d3ddev->SetTransform(D3DTS_PROJECTION,&Proj); }
Quote: void Render() { d3ddev->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(91,148,217),1.0,0); d3ddev->BeginScene(); d3ddev->SetStreamSource(0,Buffer,0,sizeof(CVertex)); d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST,0,1); d3ddev->EndScene(); d3ddev->Present(NULL,NULL,NULL,NULL); }
Advertisement
Try setting CULLMODE to CULL_NONE or reverse the first 2 vertices in your vertex data. Looks like you have a right-handed triangle in a left-handed system.

Also, increase the far depth in your projection matrix to 1000.0f. Your eyepoint is just at the far limit of the frustum.

Also, change your projection matrix fov from 60 to 1.046. The field-of-view value must be in radians, not degrees.

Post again if you still have difficulties.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Thanks , it turned out that I had to change RenderState to cull CW or Did what you said.

Two more stupid questions:

1- When Ever I change to FullScreen Mode my program take 100% CPU ,what I did was
WS_POPUP|WS_CLIPSIBLINGS|WS_CLIPCHILDREN
BackBuffer --> A8R8G8B8;
BackBuffer High and Wid = 800 and 600
Window = FALSE;

In Window Mode that only took 7-9 %CPU

2- with the same task , OpenGL only took 2-4 %CPU , So is there any cure for DirectX

PS : Why do we have to SetFVF(CUSTOMFVF) everytime we render but yet we already :
CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),0,CUSTOMFVF,….)
In windowed mode, your application's framerate is probably being limited by vertical sync, whereas in full screen mode it can run unthrottled. Read about the D3DPRESENT_INTERVAL_* defines here (particularly IMMEDIATE and DEFAULT/ONE), and double check any relevant settings in your video card driver control panel.
Quote:
PS : Why do we have to SetFVF(CUSTOMFVF) everytime we render but yet we already :
CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),0,CUSTOMFVF,….)<br><!–QUOTE–></td></tr></table></BLOCKQUOTE><!–/QUOTE–><!–ENDQUOTE–><br><br>If you &#111;nly render <b>one</b> type of vertex throughout your app, you &#111;nly need to set FVF &#111;nce.<br><br>However, as good programming practice, it's a good habit to get into to set the format for each buffer. Most applications will render several different kinds of vertex formats and, in that case, the format has to be set for each buffer.<br><br>Compared to rendering a buffer, the time it takes to set the FVF is trivial.<br>

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

This topic is closed to new replies.

Advertisement