Sign in to follow this  
Tano_ITA

[VS 2008, DX9] Use a dos console to debug.

Recommended Posts

Tano_ITA    126
Hi to everyone, i've a "simple" question: I'm working on DirectX9 without problem, but sometime i need to write something on my DOS console to watch some values.. When i worked with Ogre3D, i had the windows for render and a window for my console..

How can i do that in directx 9? I've changed my subsystem in Console (/SUBSYSTEM:CONSOLE) but if i use this subsystem i can't use
int WINAPI WinMain()
as entry point. So, how can i do to use a console?

thanks for any suggets :). And sorry for my english!

Share this post


Link to post
Share on other sites
Dawoodoz    461
When you can print to the console using printf, you can output error messages from the shader compiler to printf instead of the debug window so that you can see the message when testing the final product on another computer.

In DirectX 11 you would replace

if( pErrorBlob != NULL )
OutputDebugStringA( (char*)pErrorBlob->GetBufferPointer() );
SAFE_RELEASE( pErrorBlob );


with

if( pErrorBlob != NULL )
printf("\nHLSL: %s", (char*)pErrorBlob->GetBufferPointer() );
SAFE_RELEASE( pErrorBlob );

Share this post


Link to post
Share on other sites
Necrolis    1464
Here is a simple debugging console for windows that you might find of use:

#if ( __DEBUG_CONSOLE__ )
#include <cstdio>
#endif

class Console
{
protected:
HANDLE hConsole;

public:
Console()
{
#if ( __DEBUG_CONSOLE__ )
AllocConsole();
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
#endif
}

~Console()
{
#if ( __DEBUG_CONSOLE__ )
FreeConsole();
#endif
}

inline DWORD Write(const char* szMessage) const
{
#if ( __DEBUG_CONSOLE__ )
DWORD dwWritten;
WriteFile(hConsole,szMessage,strlen(szMessage),&dwWritten,NULL);
return dwWritten;
#else
return 0;
#endif
}

inline DWORD Writef(const char* szFormat, ...) const
{
#if ( __DEBUG_CONSOLE__ )
va_list pArgs;
va_start(pArgs,szFormat);
char pBuffer[2048] = {0};
DWORD dwWritten;
int nSize = _vsnprintf(pBuffer,sizeof(pBuffer),szFormat,pArgs);
WriteFile(hConsole,pBuffer,nSize,&dwWritten,NULL);
return dwWritten;
#else
return 0;
#endif
}
};

and btw, printf should output to this too, I prefer using methods though to enable/disable for debug/release mode

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this