Archived

This topic is now archived and is closed to further replies.

Drawing menu and other GUI surfaces on the foreground of 3D space

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

Hi. I am working on creating the GUI for my game. I was planning to create and perhaps texture quads for things such as panels, menu backgrounds, buttons and dialogs etc. So basically I want those to render right up front, "in your face" so to speak. The thing is, I don''t know what coordinates to give the corner vertices of a quad that I want to have appear at say the center of the screen and only the size of a small dialog with two buttons on it. As I type this, I am staring to suspect that I am supposed to do some sort of matrix transformation in order to set the quad on the near clipping plane and resize it to some proportion or other. The question is, how many units across do I have at the near plane? I think I am starting to figure this out but any help or advice would be great!

Share this post


Link to post
Share on other sites
hi,

for guis and other menu stuffs, i think the best way is to use pretransformed vertices, this way, you could place them in exact screen coordinates,

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Here''s a snippet of some of my GUI code. It may help you know where to look.

Header:
LPD3DXSPRITE chatBox;
LPDIRECT3DTEXTURE8 chatBoxTexture;

Init:
D3DXCreateSprite(m_pd3dDevice,&chatBox);
chatBoxTexture=LoadTexture( m_pd3dDevice, "Chatbox.bmp";

Render:
chatBox->Draw( chatBoxTexture, NULL, NULL, NULL, 0.0f, &D3DXVECTOR2(0.0f,0.0f), 0xFFFFFFFF );

LB

Share this post


Link to post
Share on other sites
It works perfectly for me. Alpha is easy to implement as well. I''m using Magenta (255,0,255) as my alpha color in my bitmaps. No need to have an alpha channel with this approach.

Share this post


Link to post
Share on other sites

  
#define UIVERT_FLAGS (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1) // The key here is the XYZRHW


.......

UIVert verts[] =
{
{ 0.0f, (float)SCREEN_HEIGHT - 100.0f, 0.9f, 1.0f,
D3DCOLOR_ARGB(255,255,255,255), 0.0f, 0.0f },
{ 0.0f, (float)SCREEN_HEIGHT, 0.9f, 1.0f,
D3DCOLOR_ARGB(255,255,255,255), 0.0f, 1.0f },
{ (float)SCREEN_WIDTH, (float)SCREEN_HEIGHT - 100.0f, 0.9f, 1.0f,
D3DCOLOR_ARGB(255,255,255,255), 1.0f, 0.0f },
{ (float)SCREEN_WIDTH, (float)SCREEN_HEIGHT, 0.9f, 1.0f,
D3DCOLOR_ARGB(255,255,255,255), 1.0f, 1.0f },
};

if( FAILED( g_pGame->GetDevice()->CreateVertexBuffer( 4 * sizeof(UIVert), 0,
UIVERT_FLAGS, D3DPOOL_DEFAULT, &m_uiVBuff ) ) )
return;

void* pVerts = NULL;
if( FAILED( m_uiVBuff->Lock( 0, 0, (BYTE**)&pVerts, 0 ) ) )
return;
memcpy( pVerts, verts, sizeof(verts) );
m_uiVBuff->Unlock();

m_uiTex = g_pGame->GetTexMan()->GetTexture( "ui.tga" );

.......

g_pGame->GetDevice()->SetTexture( 0, m_uiTex->GetTex() );
g_pGame->GetDevice()->SetStreamSource( 0, m_uiVBuff, sizeof(UIVert) );
g_pGame->GetDevice()->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

Share this post


Link to post
Share on other sites