Sign in to follow this  

Drawing Primitives with DXUT

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

Has anyone had any problems drawing primitives using the DXUT framework?
I have two programs that do exactly the same thing, drawing a triangle to the screen. One uses DXUT and the other does not. The program that does not use DXUT renders the triangle fine, while using DXUT nothing gets drawn.

Not using DXUT:
------------------------------------------------------------------------------

void render()
{
d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

d3ddev->BeginScene();
// create the vertices using the CUSTOMVERTEX struct

CUSTOMVERTEX vertices[] =
{
{ 400.0f, 62.5f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
{ 650.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },
{ 150.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },
};
LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL;
d3ddev->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),
0,
CUSTOMFVF,
D3DPOOL_MANAGED,
&v_buffer,
NULL);

VOID* pVoid;
v_buffer->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, vertices, sizeof(vertices));
v_buffer->Unlock();

d3ddev->SetFVF(CUSTOMFVF);
d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

d3ddev->EndScene();
d3ddev->Present(NULL, NULL, NULL, NULL);
}

------------------------------------------------------------------------------

Using DXUT
------------------------------------------------------------------------------

void GameApp::vOnFrameRender (void) // render callback
{
DXUTGetD3D9Device ()->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
DXUTGetD3D9Device ()->BeginScene ();


CUSTOMVERTEX vertices[] =
{
{ 400.0f, 62.5f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },
{ 650.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },
{ 150.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },
};
LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL;
DXUTGetD3D9Device ()->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),
0,
CUSTOMFVF,
D3DPOOL_MANAGED,
&v_buffer,
NULL);

VOID* pVoid;
v_buffer->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, vertices, sizeof(vertices));
v_buffer->Unlock();

DXUTGetD3D9Device ()->SetFVF(CUSTOMFVF);
DXUTGetD3D9Device ()->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
DXUTGetD3D9Device ()->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);


g_HUD.OnRender( m_timer.getDelta ());
DXUTGetD3D9Device ()->EndScene();
}

------------------------------------------------------------------------------


I know the verticies should be declared in a initialization function, Im just simplifying the code for now. Help with this would be greatly appreciated.

Share this post


Link to post
Share on other sites
As the two routines you posted look all but identical, it's unlikely the problem is related to that code.

There's a big problem with both routines, by the way. You create a buffer and never release it.

Do some trouble-shooting. Does the frame render function get called?

Then start comparing other things that could affect the rendering - world, viewport, view, projection, etc.

Share this post


Link to post
Share on other sites
I know that each function gets called every frame.

I can also draw sprites and lines (LPD3DXLINE) with no problems using DXUT.

As for cleaning up the code and releasing pointers, I was going to do this after I got everything working.

What other type of trouble-shooting should I try?
I have not messed with the world, view and projection matrices.
Does DXUT initialize the camera or screen somehow that I would not see the triangle?


Share this post


Link to post
Share on other sites
Quote:
Does DXUT initialize the camera or screen somehow that I would not see the triangle?

It certainly can. If the triangle isn't within the view (camera position and direction), it won't be rendered.

Make sure you have the same settings for view and projection, including near-z and far-z settings, in your DXUT app as you do in your app that renders correctly. That may or may not be the problem, but it's a place to start.

EDIT: Actually, that's extremely likely since you've positioned your triangle a large distance away from the origin.

Quote:
releasing pointers, I was going to do this after I got everything working.

Bad, bad practice. You're trying to debug code that you know has errors in it.

Share this post


Link to post
Share on other sites
I don't think that is the problem. I set up the view and projection matrices and get the same result. I think I did it right, but here is the new code:



void GameApp::vOnFrameRender (void) // render callback

{

DXUTGetD3D9Device ()->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

DXUTGetD3D9Device ()->BeginScene ();





CUSTOMVERTEX vertices[] =

{

{ 400.0f, 62.5f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 0, 255), },

{ 650.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(0, 255, 0), },

{ 150.0f, 500.0f, 0.5f, 1.0f, D3DCOLOR_XRGB(255, 0, 0), },

};

LPDIRECT3DVERTEXBUFFER9 v_buffer = NULL;

DXUTGetD3D9Device ()->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),

0,

CUSTOMFVF,

D3DPOOL_MANAGED,

&v_buffer,

NULL);



VOID* pVoid;

v_buffer->Lock(0, 0, (void**)&pVoid, 0);

memcpy(pVoid, vertices, sizeof(vertices));

v_buffer->Unlock();



DXUTGetD3D9Device ()->SetFVF(CUSTOMFVF);

D3DXMATRIX matView;
D3DXMatrixLookAtLH(&matView,
&D3DXVECTOR3 (0.0f, 0.0f, 10.0f),
&D3DXVECTOR3 (0.0f, 0.0f, 0.0f),
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));

DXUTGetD3D9Device ()->SetTransform(D3DTS_VIEW, &matView);
D3DXMATRIX matProjection;
D3DXMatrixPerspectiveFovLH(&matProjection,
0,
(FLOAT) 800 / (FLOAT)600,
1.0f,
100.0f);

DXUTGetD3D9Device ()->SetTransform(D3DTS_PROJECTION, &matProjection);

DXUTGetD3D9Device ()->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
DXUTGetD3D9Device ()->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);


DXUTGetD3D9Device ()->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));

DXUTGetD3D9Device ()->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);


g_HUD.OnRender( m_timer.getDelta ());

DXUTGetD3D9Device ()->EndScene();

// Release the vertex Buffer!!
SAFE_RELEASE (v_buffer);

}



What should I try next?

Share this post


Link to post
Share on other sites

D3DXMatrixLookAtLH(&matView,
&D3DXVECTOR3 (0.0f, 0.0f, 10.0f),
&D3DXVECTOR3 (0.0f, 0.0f, 0.0f),
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f));

Your camera is at (0,0,10), looking at the origin (0,0,0) - and the triangle is between x=150 and x=600, way up along the y-axis. The triangle is off to the camera's left side. You won't see it.

Either move the camera closer to the center of the triangle (and back along the z-axis), or move the triangle back to the origin.

Also, the triangle is really big. For starters, just create a much smaller triangle at the origin. Something like

(1,0,0)
(0,1,0)
(-1,0,0)

Once you've got it where you can see it, then you can make changes.

EDIT: I realize that releasing the buffer wasn't the problem. The principle is that you're asking people to find problems with your code that you're being sloppy with. If you're "doing things later," there's no telling what else you may have left out but intended to "do later."

Share this post


Link to post
Share on other sites

Hi!

 

   Can you show me the variables declarations, I have the same issue, I have my code working without DXUT, I can rotate it, an do some basic stuff. 

 

Now I want to modify the code and take it to DXUT. Can you help me with the 'translation'?

 

 

Best

Share this post


Link to post
Share on other sites

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