Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Problem with text

Author
Message
dede
19
Years of Service
User Offline
Joined: 17th Feb 2005
Location: France
Posted: 21st Jul 2005 07:33
I think there is a very simple answer at my question but I can't find a solution on my own so...
I want to print a variable float on the screen and I tooke the code to show the FPS but it dosen't print the right values of my variable.



Thanks for your futur help
kamelito
19
Years of Service
User Offline
Joined: 25th Dec 2004
Location: France
Posted: 21st Jul 2005 08:16
Hi,

You can do it that way

float pi = 3.14; //float to be displayed
char sz[3]; //array to store the converted float (should be equal to your float
sprintf(sz, "%G", pi); //do the conversion
dbText (0, 400, sz); // print it to the screen.

You could probably do it also using dbStr() but its more a basic stuff than C/C++.

sprintf() needs stdio (so #include <stdio.h> is required!

I hope this help
Regards
Kamelito

/kml
dede
19
Years of Service
User Offline
Joined: 17th Feb 2005
Location: France
Posted: 21st Jul 2005 08:47
I haven't include stdio but complex and apparently it's the same.
But i've found my error :

I've use printf like that : sprintf
Quote: "( czVariable , "Var %d" , fltVariable);"


But I sould use printf like that
Quote: "sprintf ( czVariable , "%G" , fltVariable);"


Now, I can see the values of my variables thanks!!
matt rochon
21
Years of Service
User Offline
Joined: 15th Mar 2003
Location: Canada
Posted: 21st Jul 2005 13:27
kamelito:
you need to allocate enough space for all of the characters + 1

Quote: "
float pi = 3.14; //float to be displayed
char sz[3]; //array to store the converted float (should be equal to your float
sprintf(sz, "%G", pi); //do the conversion
dbText (0, 400, sz); // print it to the screen.
"


this would cause an access violation because "3.14" is 4 characters plus the null terminator. you would need to make sz an array of 5 characters

they beat it into our heads in school
kamelito
19
Years of Service
User Offline
Joined: 25th Dec 2004
Location: France
Posted: 21st Jul 2005 21:18
You're right.

I put 4 in the first place but change it at the last second as I didn't have an error while compiling it that way. I though that sz[3] was 0 to 3, but its 0 to 2.

Good catch

/kml
dede
19
Years of Service
User Offline
Joined: 17th Feb 2005
Location: France
Posted: 16th Aug 2005 19:06
I can now print all th e variables what I want, but I got another problem :
In my 3D game my variables print fine, but if I want to print some changing variables in a menu (for example), the value of the variables will be print over the old value, so it's unreadable.
Can you understand my problem?
If you can, do you have a solution?
Thank you
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 16th Aug 2005 19:43
dbSetTextOpaque

Come to the third DarkBasic Pro Sci Fi Con - Be there and be square
Blog:http://spaces.msn.com/members/BouncyBrick/
Web Site:http://www.nicholaskingsley.co.uk
dede
19
Years of Service
User Offline
Joined: 17th Feb 2005
Location: France
Posted: 16th Aug 2005 20:38
Euh it works, but now the background of the text is... opaque!
So if I want to print my variable over a bitmap or in my game, it's a problem...

You don't have another solution?

And I don't understand why changing variables print fine in my game but not fine whith a bitmap in background?
OSX Using Happy Dude
21
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 16th Aug 2005 23:16
Its because of graphic rendering orders...

Come to the third DarkBasic Pro Sci Fi Con - Be there and be square
Blog:http://spaces.msn.com/members/BouncyBrick/
Web Site:http://www.nicholaskingsley.co.uk
dede
19
Years of Service
User Offline
Joined: 17th Feb 2005
Location: France
Posted: 16th Aug 2005 23:42
OK, so if I want to create a chat, I have to make it in 3D in order to haven't opacity behind the text?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Aug 2005 15:05
No. The screen content is totally under your control.



If you draw over your bitmap, it is *your* responsibility to undo what you have done for the next frame. The above code is one of many ways to do this.

*** Coming soon - Network Plug-in - Check my site for info ***
For free Plug-ins and source code http://www.matrix1.demon.co.uk
dede
19
Years of Service
User Offline
Joined: 17th Feb 2005
Location: France
Posted: 18th Aug 2005 04:03
Thank you IanM!!

I didn't "dbSetCurrentBitmap" command.
I've tried to texture a plain with my image and to position the plain as it was load with "dbLoadBitmap". The result was not so bad, but your solution is much better.

Login to post a reply

Server time is: 2024-11-19 01:33:51
Your offset time is: 2024-11-19 01:33:51