Sign in to follow this  
varon89

problem drawing primitives

Recommended Posts

I'm working on a program titled "MyBlockGame," and I'm having trouble rendering the blocks. The 2D blocks, generated from four-point trianglestrips, show up, but they're not totally filled in. They show up as a bunch of dots, like pointillism. Also, as the blocks move down the grid that they're supposed to be in, horizontal strips of the blocks disappear and reappear. Lastly, the leftmost block doesn't show up at all. This is some of the source code. Note that I'm only working with red blocks atm. #define RED 0xff0000 . . . void renderFrame() { . . . // translation matrix D3DXMATRIX matTranslate; // repeatedly call D3DXMatrixTranslation on the matTranslate matrix, // SetTransform to that matrix, and draw a square int firstPoint; // the index of first point in a primitive for (int row = 0; row < GRID_HEIGHT; ++row) { for (int cell = 0; cell < GRID_WIDTH; ++cell) { int col = pController->GetColor(row, cell); switch (col) { case(RED): firstPoint = 0; break; case(GREEN): firstPoint = 4; break; case(BLUE): firstPoint = 8; break; case(YELLOW): firstPoint = 12; break; default: firstPoint = -1; break; } if (firstPoint != -1) { D3DXMatrixTranslation(&matTranslate, (float)(20 * cell - SCREEN_WIDTH / 256), (float)(-20 * row + SCREEN_HEIGHT / 256), 0.0f); pd3ddev->SetTransform(D3DTS_WORLD, &matTranslate); pd3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP, firstPoint, 2); } } void initGraphics() { // create the vertices using the CUSTOMVERTEX struct CUSTOMVERTEX t_vert[] = { // a red square { -10.0f, 10.0f, 0.0f, D3DCOLOR_XRGB(0xff, 0x00, 0x00), }, { 10.0f, 10.0f, 0.0f, D3DCOLOR_XRGB(0xff, 0x00, 0x00), }, { -10.0f, -10.0f, 0.0f, D3DCOLOR_XRGB(0xff, 0x00, 0x00), }, { 10.0f, -10.0f, 0.0f, D3DCOLOR_XRGB(0xff, 0x00, 0x00), }, // a green square . . . // a blue square . . . // a yellow square . . . }; // create a vertex buffer interface called pt_buffer pd3ddev->CreateVertexBuffer(16 * sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &pt_buffer, NULL); VOID *pVoid; // lock pt_buffer and load the vertices into it pt_buffer->Lock(0, 0, (void**) &pVoid, 0); memcpy(pVoid, t_vert, sizeof(t_vert)); pt_buffer->Unlock(); }

Share this post


Link to post
Share on other sites
<gazes into crystal ball and makes an educated guess>

At the start of your frame do:
pd3ddev->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);


My guess is your application has a Z buffer (EnableAutoDepthStencil in your D3DPRESENT_PARAMETERS). If you haven't changed the Z buffer render states then it's likely that Z testing is enabled by default. The Z value of each pixel in the polygon being rendered is tested against the Z values in the Z buffer, if the result of the comparison is a pass the pixel is rendered otherwise it's not.

So what Z values are in the Z buffer when your D3D device is created? The answer is "it's undefined". In the case of the Z buffer, 'undefined' usually means whatever random stuff was left in that part of video memory - which in a Z buffer will look like random points, holes, streaks etc and occasionally noticable shapes.

Share this post


Link to post
Share on other sites

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