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

Started by
5 comments, last by abeltherock007 13 years, 5 months ago
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!
Advertisement
LessBread gives the easiest way to do this.
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 );
Quote:Original post by Aardvajk
LessBread gives the easiest way to do this.


Thanks! =) It work fine! =)
You want to consider using OutputDebugString() instead.
Here is a simple debugging console for windows that you might find of use:
#if ( __DEBUG_CONSOLE__ )#include <cstdio>#endifclass 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
Quote:Original post by Aardvajk
LessBread gives the easiest way to do this.


the link doesnt exist or no information found.. i need a DOS console window to debug in DX10

This topic is closed to new replies.

Advertisement