1

So I'm building this game engine thinggy, and found it to be VERY hard to create some kind of an overlay with debug information into the main game window with D3D11 or at all draw text, so I thought I'd create an other window to contain my debug data.

I got the window created fine and all, but I have no idea how to write my debug info into it. I do not want to use the windows form designer as that would have to convert my project into a CLR project which I do not want.

I have been googling now for 3 hours at least (honest) and tried various solutions but none of them really seemed practical to use/they were not working.

The debug info I'd like to write originates from global float values. An example would be CAM_POS_X which holds a floating point value which indicates at which X co ordinate the camera is currently at.

Something like this is desired:

|SiriusAlpha 0.1 Debug window_ |
|Current X position: CAM_POS_X|
|Current Y position: CAM_POS_Y|
|Current Z position: CAM_POS_Z|
|Current YAW: CAM_YAW______|
|Current PITCH: CAM_PITCH___|
|Current FPS: CUR_FPS_______|

All of these values are not nescessarily floating point variables. They could be strings, doubles, integers or even booleans.

If anyone would be willing to explain to me how to do this in D3D11 and I could skip the whole debug window schenennigans I'd be even happier.

Otherways, I'd be delighted if somebody could explain to me how this is done.

Axel Latvala
  • 576
  • 3
  • 7
  • 21
  • 1
    Maybe this helps? http://stackoverflow.com/questions/5979632/d3d11-how-to-draw-gdi-text-to-a-gxdi-surface-without-d2d – Aesthete Jul 20 '12 at 13:47
  • I looked at that one earlyer, but that was before I dropped the hope of D3D doing this text thing. I guess I'll have to take a closer look at it. – Axel Latvala Jul 20 '12 at 14:06
  • That one seemed a little bit incomplete, I would need something that explains everything from the very basics. I started learning D3D11 3 days ago... – Axel Latvala Jul 20 '12 at 14:49

1 Answers1

0

Have you tried TextOut()? Read the article on msdn. You should already have a device context, the rest is quick and easy.

The TextOut function writes a character string at the specified location, using the currently selected font, background color, and text color.

Printing to a string is trivial.

wchar buf[128];
swprintf(buf, "Current X Position: %f", CAM_X_POS);
TextOut(yourDC, screenXPos, screenYPos, &buf, sizeof(buf));

I haven't tested this, but from the MSDN documentation this should work fine.

Aesthete
  • 18,622
  • 6
  • 36
  • 45
  • I have, and it wasn't practical. I can't seem to figure out how to combine strings and floats to result as a `LPCWSTR`. Also I would have to know the length of the strings which is bullshit because that is not flexible... Damn this is hard... – Axel Latvala Jul 20 '12 at 14:04
  • You can use `swprintf()` (string wide print formatted) to print to a string buffer. You can read about it here: http://msdn.microsoft.com/en-us/library/ybk95axf(v=vs.71).aspx – Aesthete Jul 20 '12 at 23:37
  • There is no problem getting the length of the string, just use sizeof on the string you've made. See my edits, does this make more sense? – Aesthete Jul 20 '12 at 23:48
  • Ok thank you. I will try that one later. Would you mind explaining to me the %f? How does that work? – Axel Latvala Jul 21 '12 at 13:47
  • It's called a token. It specifies that it should be replaced with a value (in this case an int). Read everything here: http://www.cplusplus.com/reference/clibrary/cstdio/printf/ – Aesthete Jul 21 '12 at 15:09
  • Allright, thanks a lot! One more question. Is `sprintf()` the standard way in C++ to create strings out of other data types? In PHP (Which is my strongest language) you could do something like this:`$number = 50000.00;$string = 'myString1';$variable = 'myVar1';$Output = $String . " Another string containing a $variable " . ' another string NOT containing a $variable ' . $number;` And output would have been the following: `myString1 Another string containing a myVar1 another string NOT containing a $variable 50000.00` – Axel Latvala Jul 21 '12 at 15:41
  • There are alot of _easier_ (for some) ways to do this stuff in classes like `std::string` and `std::sstream`. But since you are working with D3D you're going to see, and have to write lower level code like this anyway. It's faster, and has less overhead than other string manipulation classes. – Aesthete Jul 21 '12 at 15:47
  • And you'd probably do well to forget _nearly_ everything you know about PHP before writing a D3D11 rendering engine in C++. – Aesthete Jul 21 '12 at 15:48
  • The thing about stringstream is that I've had trouble converting the result to the appropriate form (namely LPCWSTR) – Axel Latvala Jul 21 '12 at 17:50
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/14230/discussion-between-aesthete-and-akke) – Aesthete Jul 22 '12 at 02:07
  • These questions are off topic. See if you can write text to a window using the answer I gave, and if it works - accept it. Good luck. – Aesthete Jul 22 '12 at 02:09
  • I'll try it out. But I'm really busy right now so it might take a day or 2. – Axel Latvala Jul 22 '12 at 14:51