Porsche Posted December 12, 2009 Share Posted December 12, 2009 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 Quote 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 More sharing options...
Qbound Posted December 12, 2009 Share Posted December 12, 2009 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 Quote 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 More sharing options...
DaDonik Posted December 12, 2009 Share Posted December 12, 2009 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()); Quote (Win7 64bit) && (i7 3770K @ 3,5ghz) && (16gb DDR3 @ 1600mhz) && (Geforce660TI) Link to comment Share on other sites More sharing options...
Canardia Posted December 12, 2009 Share Posted December 12, 2009 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()); } Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Porsche Posted December 12, 2009 Author Share Posted December 12, 2009 Thanks to both of you. =] Quote 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 More sharing options...
Masterxilo Posted December 12, 2009 Share Posted December 12, 2009 You can display STL strings in 2 ways: ... While DrawText(1,14,(str)s.c_str()); is the bad one. Quote Hurricane-Eye Entertainment - Site, blog. Link to comment Share on other sites More sharing options...
Porsche Posted December 13, 2009 Author Share Posted December 13, 2009 While DrawText(1,14,(str)s.c_str()); is the bad one. Any reason why it's worse than the other? Quote 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 More sharing options...
Masterxilo Posted December 18, 2009 Share Posted December 18, 2009 Yes there is. Imagine s is "Hello %f %x %s there!, how are you?". sprintf (just as printf) would look for three parameters while you passed none. I would mess up your memory. Quote Hurricane-Eye Entertainment - Site, blog. Link to comment Share on other sites More sharing options...
TylerH Posted December 19, 2009 Share Posted December 19, 2009 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. Quote nVidia 530M Intel Core i7 - 2.3Ghz 8GB DDR3 RAM Windows 7 Ultimate (64x)----- Visual Studio 2010 Ultimate Google Chrome Creative Suite 5 FL Studio 10 Office 15 ----- Expert Professional Expert BMX Programmer ----- Link to comment Share on other sites More sharing options...
Canardia Posted December 19, 2009 Share Posted December 19, 2009 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. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Recommended Posts
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.