Jump to content
  • Advertisement
Sign in to follow this  

Simple vertex buffer problem :S

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

Don't know if this would help
did you set the projection and view using SetTransform with D3DTS_VIEW & D3DTS_PROJECTION?

g_d3d_device->SetTransform(D3DTS_VIEW, &view_matrix);
g_d3d_device->SetTransform(D3DTS_PROJECTION, &projection_matrix);

Share this post

Link to post
Share on other sites
I still haven't found the problem, I think that the coordinates should be in 0-1023 and 0-767 format, so I still use that. The -1 to 1 theory didn't work.

Since the vertexbuffer code seems good I'm leaning more towards that this has to be a problem where the triangle is rendered but I'm not facing towards it (or similar). However I thought you always faced screen space primitives. Well well, I've added this code that completely disables the camera functions (of course).

	d3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
d3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);

D3DXMatrixRotationYawPitchRoll(&mRotate, 0.0f, 0.0f, 0.0f);
D3DXMatrixTranslation(&mTrans, 0.0f, 0.0f, 0.0f);
D3DXMatrixScaling(&mScale, 1.0f, 1.0f, 1.0f);
mWorld = mRotate * mScale * mTrans;
d3dDevice->SetTransform(D3DTS_WORLD, &mWorld);

D3DXMatrixLookAtLH(&mView, &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &D3DXVECTOR3(0.0f, 0.0f, 5.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
d3dDevice->SetTransform(D3DTS_VIEW, &mView);

D3DXMatrixPerspectiveFovLH(&mProj, D3DX_PI/4, 1024.0f / 768.0f, 1.0f, 1000.0f);
d3dDevice->SetTransform(D3DTS_PROJECTION, &mProj);


So the near clip plane is at 1.0f and the far at 1000.0f. I guess this does _not_ affect screen space primitives? Since I'm drawing my triangle at z = 0.0f (rhw = 1.0f) that would be in front of the clipping plane.

Culling and lighting is disabled. The world matrix is not doing any rotation, translation or scaling. The view matrix makes the "camera" be at 0,0,0 looking towards positive z coords which in a LH system would be into the screen? The projection matrix is about as basic as it can be...

Share this post

Link to post
Share on other sites
You can try this:

D3DMATRIX mWorld,mProj;

d3dDevice->SetTransform(D3DTS_WORLD, &mWorld);
d3dDevice->SetTransform(D3DTS_VIEW, &mWorld);
d3dDevice->SetTransform(D3DTS_PROJECTION, &mProj);


Share this post

Link to post
Share on other sites
Thanks, but it doesn't work with those matrices either.

However, I've made some "progress" or at least I've done something :)

I took Drunken Hyenas vertex buffer tutorial and took the vertex data from him, it is as follows (I commented the first part "Fan 1", since it doesn't affect my application).

GuiVertex verts[]={
// {100,100,1,1,0xFF000000},{ 0, 0,1,1,0xFFFF0000},{200, 0,1,1,0xFF00FF00},
// {100,100,1,1,0xFF000000},{200, 0,1,1,0xFF00FF00},{200,200,1,1,0xFF0000FF},
// {100,100,1,1,0xFF000000},{200,200,1,1,0xFF0000FF},{ 0,200,1,1,0xFFFFFFFF},
// {100,100,1,1,0xFF000000},{ 0,200,1,1,0xFFFFFFFF},{ 0, 0,1,1,0xFFFF0000},
{ 75,350,1,1,0xFFFFFFFF},{ 0,225,1,1,0xFFFF0000},{ 50,215,1,1,0xFF7F7F00},
{ 75,350,1,1,0xFFFFFFFF},{ 50,215,1,1,0xFF7F7F00},{ 75,205,1,1,0xFF00FF00},
{ 75,350,1,1,0xFFFFFFFF},{ 75,205,1,1,0xFF00FF00},{125,215,1,1,0xFF007F7F},
{ 75,350,1,1,0xFFFFFFFF},{125,215,1,1,0xFF007F7F},{150,235,1,1,0xFF0000FF},
{250,150,1,1,0xFFFF0000},{300, 50,1,1,0xFF00FF00},{350,150,1,1,0xFF0000FF},
{300, 50,1,1,0xFF00FF00},{400, 50,1,1,0xFFFF0000},{350,150,1,1,0xFF0000FF},
{400, 50,1,1,0xFFFF0000},{450,150,1,1,0xFF7F7F00},{350,150,1,1,0xFF0000FF},

This data (including Fan1) looks as this when I run it:

So I added this data to my application, I commented Fan 1 as it didn't make any difference. Then I got this result:
Picture 1:

Progress! That is something in the upper left corner of my screen, it's totally black even though none of the vertices should be black, but there still is something there. Since I render this as a TriangleList (it was rendered in the same way in the Drunken Hyena example) I guessed that one line is three vertices, which is one triangle. So I started to comment line after line until I could isolate a single triangle that was visible. So from the top I commented Line #1 in Fan 2. Resulting in this:
Picture 2:

So I removed a triangle, great work. And then I removed another one:
Picture 3:

Ok, we got something here, almost half of the original rectangle is gone. Now I thought that if I removed all lines, except the first two in Fan 2 (the ones that I just commented) I would get the area that is now cleared, to be filled by those two triangles. Suprise suprise, if I comment all lines, except the two I removed from picture 1 to 3, I get _nothing_. Not even a single black pixel.

So by removing two lines I removed about a square centimeter of blackness. But by removing all other triangles and adding those two again, they did not fill the same area.

And I tried to multiply all x and y coordinates with 10, 100 and 1000. It doesn't change a thing. I tried to change z-value to 10.0f, didn't do anything. I tried to set rhw to 0.0f, didn't change anything.

Then I was almost certain that my computer played tricks on me so I compiled and ran the code on both my laptop and a friends computer. Same result.

Any ideas are very welcome :)

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!