Jump to content

On Screen Display


Porsche
 Share

Recommended Posts

DrawText() doesn't seem to be working properly. I keep getting the following error:

 

error C2665: 'DrawTextW' : none of the 2 overloads could convert all the argument types

 

I've tried these two implementations:

 

1.

// in struct creation
string output;

//in default constructor
output = "Default Setup";

// in game loop
DrawText(32,32,aiONE->output);

 

2.

// Before game loop
std::string text = "Hello, world!";

// in Game loop
DrawText(0, 0, text.c_str());

 

Just trying to get it to display a variable defined earlier. I am obviously not handling the string right in some way.

 

This works of course:

 

DrawText(0, 0, "Hello World");

 

 

Also, what's the easiest way to display FPS?

 

 

-Thanks,

Porsche

simpleSigPNG.png

Artist, Animator, Musician, P/T Programmer

Dual Core @ 2.6GHz per /nVidia 9600 GT/ 4 GBs DDR3 6800 / XP Pro 32/64 Bit

Photoshop CS3 / 3D Studio Max 8 / VS '08

Link to comment
Share on other sites

Hi Porsche,

 

take a look into the thread with the scrennshot command http://leadwerks.com/werkspace/index.php?/topic/293-take-screenshots/

there you have the sprintf command. But the easiest way to display FPS is with DrawText( 10, 10, "FPS: %f", FPS() );

and you have to convert (in your code above) your text.c_str() to (str) like this (str)text.c_str();

 

cu

Oliver

Windows Vista 64 / Win7 64 | 12GB DDR3 1600 | I7 965 | 2 * 280GTX sli | 2 * 300GB Raptor | 2 * 1.5TB

Link to comment
Share on other sites

The DrawTextA and DrawTextW are windows functions (or C++...).

 

to make your command work, you need to cast the const char the c_str() returns

into a char*.

 

DrawText(0, 0, (char*)text.c_str());

(Win7 64bit) && (i7 3770K @ 3,5ghz) && (16gb DDR3 @ 1600mhz) && (Geforce660TI)

Link to comment
Share on other sites

You can display STL strings in 2 ways:

#include "engine.h"
#include <string>
using namespace std;

...

int main()
{
string s="Hello World!";

...

DrawText(1,14,(str)s.c_str());
DrawText(1,28,"%s",s.c_str());
}

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

While

DrawText(1,14,(str)s.c_str());

is the bad one.

 

Any reason why it's worse than the other?

simpleSigPNG.png

Artist, Animator, Musician, P/T Programmer

Dual Core @ 2.6GHz per /nVidia 9600 GT/ 4 GBs DDR3 6800 / XP Pro 32/64 Bit

Photoshop CS3 / 3D Studio Max 8 / VS '08

Link to comment
Share on other sites

str is just a typedef for char* isn't it? So a bit redundant to explicitly cast to char*, besides, what if you have dangling pointer and non-mutable access to that particular string?

 

You should use const_cast<char*>(s.c_str()) to be 100% safe, though what Masterxilo stated about the memory problems still apply.

52t__nvidia.png nVidia 530M cpu.gif Intel Core i7 - 2.3Ghz 114229_30245_16_hardware_memory_ram_icon.png 8GB DDR3 RAM Windows7_Start.gif Windows 7 Ultimate (64x)

-----

IconVisualStudio16.png Visual Studio 2010 Ultimate google-Chrome.png Google Chrome PhotoshopLinkIndicator.png Creative Suite 5 icon28.gif FL Studio 10 MicrosoftOfficeLive.png Office 15

-----

csharp.png Expert cpp.png Professional lua_icon.png Expert BMX Programmer

-----

i-windows-live-messenger-2009.pngskype-icon16.pngaim_online.pnggmail.pngicon_48x48_prism-facebook.pngtunein-web.pngyahoo.giftwitter16.png

Link to comment
Share on other sites

str is "the null terminated C string which LE uses", it's not the same as char*, although it might be currently similar.

 

At the moment it's also unsigned char*, since not all C++ compilers work with signed chars for strings. In future str might be also unsigned int*, if there are some multibyte string functions. The whole point of declaring your own types is that your code stays compatible with all current and future OS and hardware.

 

LE uses also flt instead of float (which is used as "the floating point resolution which LE uses for GPU floating point numbers"), since GPUs might soon be all 64-bit, so you don't have to change any code then either, as the headers will then have flt defined as double.

Note that for pure mathematical functions you should always use double, as it's about twice as fast as float. bool is also twice as fast as int.

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...