D3D and WinApi

Posts 1–9 of 9 · Page 1 of 1
D3D and WinApi
I have recently got into DirectX programming. I made a simple app that just draws a triangle on the screen, but then when i told the window to print hello in the center it wouldn't do it. I did it by the DrawTextA() function in the WM_PAINT message in the winproc. Does this mean that if i use d3d in a windows application that i can't use winapi stuff?
"it wouldn't do it" is ambiguous. What do you mean by that? That the text was not drawn at all? Or that it was drawn in an unexpected location?
Quote Originally Posted by freedompeace View Post
"it wouldn't do it" is ambiguous. What do you mean by that? That the text was not drawn at all? Or that it was drawn in an unexpected location?
I mean it didn't draw the text at all.
Quote Originally Posted by 258456 View Post
I mean it didn't draw the text at all.
It probably draw but D3D drawn over it. Try using
"LPD3DXFONT". I dont think windows stuff will draw on DirectX and put it in Render :O
DirectX will redraw over the window buffer at your sync rate in windowed mode, so it'll be overwritten =/
Quote Originally Posted by freedompeace View Post
DirectX will redraw over the window buffer at your sync rate in windowed mode, so it'll be overwritten =/
yea,.. that kinda and more since and in very high detail what I said.



This should work.... It have a few extra things because i kinda copy it out of my Menu Tester so yeaaaa But that the way we do shit in D3D


[highlight="CPP"]
#define STRICT
#define WIN32_LEAN_AND_MEAN

#include "gui.h"

//-----------------------------------------------------------------------------
// GLOBALS
//-----------------------------------------------------------------------------
HWND g_hWnd = NULL;
LPDIRECT3D9 g_pD3D = NULL;
LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
LPD3DXFONT g_pd3dxFont = NULL;
LPDIRECT3DVERTEXBUFFER9 g_pVertexBuffer = NULL;
LPDIRECT3DTEXTURE9 g_pTexture = NULL;

float g_fDistance = 4.0f;
float g_fSpinX = 0.0f;
float g_fSpinY = 0.0f;

struct Vertex
{
float x, y, z;
float tu, tv;

enum FVF
{
FVF_Flags = D3DFVF_XYZ | D3DFVF_TEX1
};
};

Vertex g_quadVertices[] =
{
{-1.0f, 1.0f, 0.0f, 0.0f,0.0f },
{ 1.0f, 1.0f, 0.0f, 1.0f,0.0f },
{-1.0f,-1.0f, 0.0f, 0.0f,1.0f },
{ 1.0f,-1.0f, 0.0f, 1.0f,1.0f }
};

enum FilterTypes
{
FILTER_TYPE_NONE = 0,
FILTER_TYPE_POINT,
FILTER_TYPE_LINEAR,
FILTER_TYPE_ANISOTROPIC
};



//-----------------------------------------------------------------------------
// PROTOTYPES
//-----------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow);
LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);

void init(void);
void shutDown(void);
void render(void);

//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: The application's entry point
//-----------------------------------------------------------------------------
int WINAPI WinMain( HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow )
{
WNDCLASSEX winClass;
MSG uMsg;

memset(&uMsg,0,sizeof(uMsg));

winClass.lpszClassName = "MY_WINDOWS_CLASS";
winClass.cbSize = sizeof(WNDCLASSEX);
winClass.style = CS_HREDRAW | CS_VREDRAW;
winClass.lpfnWndProc = WindowProc;
winClass.hInstance = hInstance;
winClass.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_GUI);
winClass.hIconSm = LoadIcon(hInstance, (LPCTSTR)IDI_SMALL);
winClass.hCursor = LoadCursor(NULL, IDC_ARROW);
winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
winClass.lpszMenuName = NULL;
winClass.cbClsExtra = 0;
winClass.cbWndExtra = 0;

if( !RegisterClassEx(&winClass) )
return E_FAIL;

g_hWnd = CreateWindowEx( NULL, "MY_WINDOWS_CLASS",
"Direct3D (DX9) - Texturing Filtering",
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0, 0, 640, 480, NULL, NULL, hInstance, NULL );

if( g_hWnd == NULL )
return E_FAIL;

ShowWindow( g_hWnd, nCmdShow );
// UpdateWindow( g_hWnd );

init();

while( uMsg.message != WM_QUIT )
{
if( PeekMessage( &uMsg, NULL, 0, 0, PM_REMOVE ) )
{
TranslateMessage( &uMsg );
DispatchMessage( &uMsg );
}
else
render();
}

shutDown();

UnregisterClass( "MY_WINDOWS_CLASS", winClass.hInstance );

return uMsg.wParam;
}

//-----------------------------------------------------------------------------
// Name: WindowProc()
// Desc: The window's message handler
//-----------------------------------------------------------------------------
LRESULT CALLBACK WindowProc( HWND hWnd,
UINT msg,
WPARAM wParam,
LPARAM lParam )
{
static POINT ptLastMousePosit;
static POINT ptCurrentMousePosit;
static bool bMousing;

switch( msg )
{
case WM_KEYDOWN:
{
switch( wParam )
{
case VK_ESCAPE:
PostQuitMessage(0);
break;

case 38: // Up Arrow Key
g_fDistance -= 0.1f;
break;

case 40: // Down Arrow Key
g_fDistance += 0.1f;
break;
}
}
break;

case WM_LBUTTONDOWN:
{
ptLastMousePosit.x = ptCurrentMousePosit.x = LOWORD (lParam);
ptLastMousePosit.y = ptCurrentMousePosit.y = HIWORD (lParam);
bMousing = true;
}
break;

case WM_LBUTTONUP:
{
bMousing = false;
}
break;

case WM_MOUSEMOVE:
{
ptCurrentMousePosit.x = LOWORD (lParam);
ptCurrentMousePosit.y = HIWORD (lParam);

if( bMousing )
{
g_fSpinX -= (ptCurrentMousePosit.x - ptLastMousePosit.x);
g_fSpinY -= (ptCurrentMousePosit.y - ptLastMousePosit.y);
}

ptLastMousePosit.x = ptCurrentMousePosit.x;
ptLastMousePosit.y = ptCurrentMousePosit.y;
}
break;

case WM_CLOSE:
{
PostQuitMessage(0);
}

case WM_DESTROY:
{
PostQuitMessage(0);
}
break;

default:
{
return DefWindowProc( hWnd, msg, wParam, lParam );
}
break;
}

return 0;
}


//-----------------------------------------------------------------------------
// Name: init()
// Desc:
//-----------------------------------------------------------------------------
void init( void )
{
g_pD3D = Direct3DCreate9( D3D_SDK_VERSION );

D3DDISPLAYMODE d3ddm;

g_pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm );

D3DPRESENT_PARAMETERS d3dpp;

ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = d3ddm.Format;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;

g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, &g_pd3dDevice );


g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

HDC hDC;
int nHeight;
int nPointSize = 9;

hDC = GetDC( NULL );

nHeight = -( MulDiv( nPointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72 ) );

ReleaseDC( NULL, hDC );
D3DXCreateFont( g_pd3dDevice, nHeight-3, 0, FW_BOLD, 0, TRUE,
ANSI_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY,
VARIABLE_PITCH | FF_DONTCARE, TEXT("Garamond"),
&g_pd3dxFont );



}

//-----------------------------------------------------------------------------
// Name: shutDown()
// Desc:
//-----------------------------------------------------------------------------
void shutDown( void )
{
if( g_pd3dDevice != NULL )
g_pd3dDevice->Release();

if( g_pD3D != NULL )
g_pD3D->Release();
}


void DrawTexBox(LPDIRECT3DDEVICE9 pDevice,
LPDIRECT3DTEXTURE9 pTexture,
int x,
int y,
int w,
int h)
{
struct tVertex
{
float X, Y, Z, RHW;
float IU, IV;
enum FVF
{
FVF_Flags = (D3DFVF_XYZRHW | D3DFVF_TEX1)
};

};

tVertex Veri[4] =
{
{(float)x ,(float)y , 0.0f, 1.0f, 0.0f, 0.0f },
{(float)(x+w) ,(float)y , 0.0f, 1.0f, 1.0f, 0.0f },
{(float)x ,(float)(y+h) , 0.0f, 1.0f, 0.0f, 1.0f },
{(float)(x+w) ,(float)(y+h) , 0.0f, 1.0f, 1.0f, 1.0f },
};

pDevice->SetTexture( 0, pTexture );
//
// Credit mmbob for helping fixing the problem
//
pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
pDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
pDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TEXTURE );
pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 );
pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE );
//
// Credit mmbob for helping fixing the problem
//
pDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );
pDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
////////////////////////////////////

pDevice->SetRenderState( D3DRS_LIGHTING, FALSE);
pDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW);
pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
pDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );
pDevice->SetRenderState( D3DRS_FOGENABLE, false );

pDevice->SetFVF( tVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,Veri,sizeof (tVertex));
}

void DrawBox(LPDIRECT3DDEVICE9 pDevice,
int x,
int y,
int w,
int h,
DWORD color1=0x20ff0000,
DWORD color2=0x20ff0000,
DWORD color3=0x20101010,
DWORD color4=0x20101010)
{
struct sVertex
{
float x, y, z, ht;
DWORD color;

enum FVF
{
FVF_Flags = (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
};
};
sVertex Veri[4] =
{
{(float)x ,(float)y , 0.0f, 0.0f, color1},
{(float)(x+w) ,(float)y , 0.0f, 0.0f, color2},
{(float)x ,(float)(y+h) , 0.0f, 0.0f, color3},
{(float)(x+w) ,(float)(y+h) , 0.0f, 0.0f, color4},
};


pDevice->SetTexture( 0, NULL );

pDevice->SetRenderState( D3DRS_LIGHTING, FALSE);
pDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CCW);
pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
pDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );
pDevice->SetRenderState( D3DRS_FOGENABLE, false );

pDevice->SetFVF( sVertex::FVF_Flags );
pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP,2,Veri,sizeof (sVertex));
}

//-----------------------------------------------------------------------------
// Name: render()
// Desc:
//-----------------------------------------------------------------------------

void DrawFont(LPD3DXFONT font,SHORT x, SHORT y, SHORT w, SHORT h,PCHAR text,DWORD type, DWORD color)
{
if(font==0)return;
RECT rec = {x,y,x+w,y+h};
//font->DrawTextA(0,text,-1,&rec,DT_CALCRECT | type ,color);
font->DrawTextA(0,text,-1,&rec, type ,color);
}

void render( void )
{
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f), 1.0f, 0 );


g_pd3dDevice->BeginScene();

DrawFont(g_pd3dxFont,10,50, 300,300, "Topblast is Cool",DT_CENTER | DT_NOCLIP, 0xFF000000/* BLACK */);

g_pd3dDevice->EndScene();
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}

[/highlight]
Quote Originally Posted by freedompeace View Post
"it wouldn't do it" is ambiguous. What do you mean by that? That the text was not drawn at all? Or that it was drawn in an unexpected location?
WHAT The WAllHAck
Quote Originally Posted by dhilah View Post
WHAT The WAllHAck
uhm . lolwut
Sure you can use winapi,the source @topblast Wrote for you above is win32
Posts 1–9 of 9 · Page 1 of 1

Post a Reply

Tags for this Thread

None

Talk with us