Sign in to follow this  

Is there Any Error

This topic is 3567 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

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); }

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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,[color="Red"]CUSTOMFVF[/color],....)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Quote:

PS : Why do we have to SetFVF(CUSTOMFVF) everytime we render but yet we already :
CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),0,[color="Red"]CUSTOMFVF[/color],....)


If you only render one type of vertex throughout your app, you only need to set FVF once.

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.

Compared to rendering a buffer, the time it takes to set the FVF is trivial.

Share this post


Link to post
Share on other sites

This topic is 3567 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this