Skip to main content
GameDev.net gamedev.net
🔒 Locked

DrawText()

Started by ironbox Jun 26, 2004 at 6:30 PM 1 replies 400+ views
Original Post
ironbox
ironbox
I dont now what the problem is with drawtext(). Instead of: "You need a special key." I get this: "YcYcYcYcYcYcYcYcYcYcYcYc" NOTE: "c"=1/2 an o It was made with DX 8.1 SDK ,but run in DX 9. Is there a bug with DX9 or is it something else?
Pipo DeClown
Pipo DeClown
Quote:
Original post by ironbox
I dont now what the problem is with drawtext(). Instead of:
"You need a special key."
I get this:
"YcYcYcYcYcYcYcYcYcYcYcYc"

NOTE: "c"=1/2 an o

It was made with DX 8.1 SDK ,but run in DX 9.
Is there a bug with DX9 or is it something else?

Your problem is clear, but we can't do anything with just an example. Could you maybe give us some code?

- How do you set up the character array?
- How do you call DrawText()?
A complete snippet would be even better.
ironbox
ironbox
these functions are in the game engine:


//////////////////////////////////////////////////////
// PaintPlaque()
//////////////////////////////////////////////////////
void CEngine::PaintPlaque()
{
unsigned char *vb_vertices;
IDirect3DVertexBuffer8* pSquare;
vertex m_square_vertices[] =
{
{ 192.0f, 340.0f, 0.0f, 1.0f, 0.0f, 1.0f }, /* Lower left corner */
{ 192.0f, 152.0f, 0.0f, 1.0f, 0.0f, 0.0f }, /* Upper left corner */
{ 448.0f, 340.0f, 0.0f, 1.0f, 1.0f, 1.0f }, /* Lower right corner */
{ 448.0f, 152.0f, 0.0f, 1.0f, 1.0f, 0.0f } /* Upper right corner */
};

// Create a font.
LPD3DXFONT pFont = NULL;
LOGFONT LogFont = {16, 0, 0, 0, FW_NORMAL, false, false, false,
DEFAULT_CHARSET,OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS,
PROOF_QUALITY, DEFAULT_PITCH, "Times New Roman"};
D3DXCreateFontIndirect(m_Direct3D.GetDevice(), &LogFont, &pFont);
// Calculate the size of a rectangle that can hold the text.
RECT r;
r.left = 0;
r.top = 0;
r.right = 0;
r.bottom = 0;
pFont->DrawText(m_pstrPlaqueMsg, -1, &r, DT_CALCRECT, 0xff000000);
int iWidth = r.right - r.left;
int iHeight = r.bottom - r.top;
r.left = (640 - iWidth) / 2;
r.right = r.left + iWidth;
r.top = (480 - iHeight) / 2;
r.bottom = r.top + iHeight;

// Create and load the vertex buffer.
HRESULT hResult = m_Direct3D.GetDevice()->
CreateVertexBuffer(4*sizeof(vertex),D3DUSAGE_WRITEONLY,
D3D8T_CUSTOMVERTEX, D3DPOOL_MANAGED, &pSquare);
hResult = pSquare->Lock(0, 0, &vb_vertices, 0);
memcpy(vb_vertices, m_square_vertices, sizeof(m_square_vertices));
pSquare->Unlock();
// Display the plaque texture.
m_Direct3D.GetDevice()->SetTextureStageState(0,
D3DTSS_COLOROP, D3DTOP_SELECTARG1);
m_Direct3D.GetDevice()->SetTextureStageState(0,
D3DTSS_COLORARG1, D3DTA_TEXTURE);
m_Direct3D.GetDevice()->SetTextureStageState(0,
D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
m_Direct3D.GetDevice()->SetTextureStageState(0,
D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
m_Direct3D.GetDevice()->SetRenderState(D3DRS_SRCBLEND,
D3DBLEND_SRCALPHA);
m_Direct3D.GetDevice()->SetRenderState(D3DRS_DESTBLEND,
D3DBLEND_INVSRCALPHA);
m_Direct3D.GetDevice()->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
if(SUCCEEDED(m_Direct3D.GetDevice()->BeginScene()))
{
m_Direct3D.GetDevice()->SetVertexShader(D3D8T_CUSTOMVERTEX);
m_Direct3D.GetDevice()->SetStreamSource(0, pSquare, sizeof(vertex));
m_Direct3D.GetDevice()->SetTexture(0, m_Direct3D.GetTexture());
m_Direct3D.GetDevice()->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
pFont->DrawText(m_pstrPlaqueMsg, -1, &r, DT_CENTER, 0xff000000);
m_Direct3D.GetDevice()->EndScene();
}
pSquare->Release();
pFont->Release();
}

//////////////////////////////////////////////////////
// TurnOnPlaque()
//////////////////////////////////////////////////////
void CEngine::TurnOnPlaque(char* msg)
{
strcpy(m_pstrPlaqueMsg, msg);
m_bShowingPlaque = TRUE;
}


-----------
in another file:
this is a place wher it is called:

g_Engine.TurnOnPlaque("You need a special key.");



NOTE: I also had the exact same problem with the examples that came with the 8.1 SDK.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.