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

Started by
4 comments, last by Igilima 21 years, 6 months ago
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!
Advertisement
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,
http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
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
I guess it is time to learn about the sprite class.
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.

  #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 );  

This topic is closed to new replies.

Advertisement