Jump to content
  • Advertisement
Sign in to follow this  
Programmer16

Funny output with wireframe rendering

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

I've been working on my game engine's GUI and I just finished the font engine. Since I can't constantly work on the same thing I switched over for about an hour and made a RenderStateManager. So to test it I switch into wireframe and then back into solid rendering, but when I was in wireframe I noticed that instead of a wireframe I had dots for the font and some thick slanted lines for my rendered window (and I've checked to make sure that I'm using D3DFILL_WIREFRAME). Here's a screenshot of what it looks like (once with as wireframe and once as solid). As you can see it renders just fine until I do wireframe: I'm using DirectX9.0c (although the code was written with 9.0b) and C++. I'm positive that I'm setting the correct renderstate with the correct value. I do have alpha-blending enabled, but I tried it without alpha-blending with the same results. I also converted my image to a bitmap also with the same results. The system uses 1 vertex buffer and 1 index buffer (length of the string * 4 for vertex count and length of the string * 6 for index count). Also, as a side question, how come its faster to render my index buffer (as a triangle list) than it is to render my vertex buffer (as a triangle strip)? Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Ok, I figured out the wierd rendering problem, by accident actually. I wasn't taking the alpha-value of my bitmap into account, and for some reason commenting out the only part of my code that turns it on wasn't working. I changed the background color to red to see what would happen (since black is my alpha color) and it was rendering the lines.

I would still like to know why my index buffer is rendering faster than my vertex buffer.

Say for the string: "Hi, my name is Donny"
There are 20 characters, so I'd have 80 vertices and 120 indices. My vertex buffer is set up for triangles-trips and my index buffer is set up for triangle-lists. But I get about 5 (all the time, not just some if it. i.e. my frame rate was at 50-60 with the VB, while it was at 55-65 with my IB) FPS more when rendering with my index buffer.

Thanks!!!

Share this post


Link to post
Share on other sites
With so few vertices you dont want to draw any conclusions from this example. but in general, your index buffer will be faster than a generic VBuffer, strips or lists not withstanding.

Why?

In general, index buffers not only minimize the number of vertices that must be transofrmed and light, but they also take advantage of the GPU's caching system. less, cache misses means less work for the GPU == more FPS.


all that said, in this instance i'd be surprised if that were the case, instead look at your logic flow and see if the vertex buffer doesnt have some additional software overhead. maybe an extra branch or something to justify the speed difference.

Share this post


Link to post
Share on other sites
I never thought about it, but the device only supports software vertex processing, and both buffers are created with the D3DUSAGE_SOFTWAREPROCESSING flag (along with D3DUSAGE_WRITEONLY). This might have something to do with it, but I'm not sure.

If anybody is interested, here is the rendering code for the engine (I can't seem to find anything that I'm doing extra, but I'm not an expert just yet):

va_list VaList;
char pBuffer[1024];

va_start(VaList, Text);
vsprintf(pBuffer, Text.c_str(), VaList);
va_end(VaList);
Text = pBuffer;

float fOX = fX;

IDirect3DVertexBuffer9* pVBuffer = NULL;
IDirect3DIndexBuffer9* pIBuffer = NULL;
UINT nVCount = Text.size() * 4;
UINT nICount = Text.size() * 6;

FontVertex* pVertices;
WORD* pIndices;

UINT nIndex = 0;
UINT nVertex = 0;
UINT nChar = 0;
DWORD dwColor = dwColors[0];

m_pDevice->CreateVertexBuffer(nVCount * sizeof(FontVertex), D3DUSAGE_WRITEONLY, FONT_FVF, D3DPOOL_MANAGED, &pVBuffer, NULL);

pVBuffer->Lock(0, 0, (VOID**)&pVertices, 0);
for(; nVertex < nVCount, nChar < Text.size(); nVertex += 4, ++nChar)
{
char Current = Text[nChar];

if(Current == '\n')
{
fX = fOX;
fY += m_fLetterHeight;

Current = Text[++nChar];
}

if(Current == '<')
{
std::string strIndex = "";
while(Current != '>')
{
Current = Text[++nChar];
strIndex += Current;
}

dwColor = dwColors[atoi(strIndex.c_str())];
Current = Text[++nChar];
}

float fU = ((Current - 32) % m_nLettersPerRow) * m_fLetterWidth;
float fV = ((Current - 32) / m_nLettersPerRow) * m_fLetterHeight;

pVertices[nVertex] = FontVertex(fX, fY + m_fLetterHeight, dwColor, fabs(fU / m_fBitmapSize), fabs((fV + m_fLetterHeight) / m_fBitmapSize));
pVertices[nVertex + 1] = FontVertex(fX, fY, dwColor, fabs(fU / m_fBitmapSize), fabs(fV / m_fBitmapSize));
pVertices[nVertex + 2] = FontVertex(fX + m_fLetterWidth, fY + m_fLetterHeight, dwColor, fabs((fU + m_fLetterWidth) / m_fBitmapSize), fabs((fV + m_fLetterHeight) / m_fBitmapSize));
pVertices[nVertex + 3] = FontVertex(fX + m_fLetterWidth, fY, dwColor, fabs((fU + m_fLetterWidth) / m_fBitmapSize), fabs(fV / m_fBitmapSize));

fX += m_fLetterWidth;
}
pVBuffer->Unlock();
m_pDevice->SetFVF(FONT_FVF);
m_pDevice->SetStreamSource(0, pVBuffer, 0, FONT_SIZE);

m_pDevice->CreateIndexBuffer(nICount * sizeof(WORD), D3DUSAGE_WRITEONLY | D3DUSAGE_SOFTWAREPROCESSING, D3DFMT_INDEX16, D3DPOOL_MANAGED, &pIBuffer, NULL);

pIBuffer->Lock(0, 0, (VOID**)&pIndices, 0);
for(nVertex = 0; nIndex < nICount; nIndex += 6, nVertex += 4)
{
pIndices[nIndex] = nVertex;
pIndices[nIndex + 1] = nVertex + 1;
pIndices[nIndex + 2] = nVertex + 2;
pIndices[nIndex + 3] = nVertex + 1;
pIndices[nIndex + 4] = nVertex + 3;
pIndices[nIndex + 5] = nVertex + 2;
}
pIBuffer->Unlock();
m_pDevice->SetIndices(pIBuffer);
m_pDevice->SetTexture(0, m_pFont);

m_pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, nVCount, 0, nICount / 3);

pVBuffer->Release();
pIBuffer->Release();




If anybody has any suggestions, please post them!
Thanks!

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!