Jump to content

  • Log In with Google      Sign In   
  • Create Account


C++ / opengl/glut - Text rendering


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 WunderStrudel   Members   -  Reputation: 141

Like
0Likes
Like

Posted 03 October 2013 - 12:35 PM

Hiii guys (: 

I dont know if this is the right place, but i thought of it as pretty basic, which just makes this more embaresing d: 

i have tried some functions for displaying text, and i made a couple of them work. Cant remember excatly how i wrote it but something like; 

void DrawText(float x, float y, char *string, ...)
{
    int len = (int)strlen(string);
    for (int i = 0; i < len; i++)
    {
         glutBitmapCharacter(Thefont, (int)string[i]);
    }
}


u should get the idea ^^
Anyways i made it work "kinda", it shows the text, but i cant make it show my vars' like;
 

DrawText(200, 200, "MouseX; %d", mouseX);

Then it just types "MouseX %d" on the screen (:
Anyfixes? ^^
Sincerly Wunder..



Sponsor:

#2 SimonForsman   Crossbones+   -  Reputation: 5456

Like
0Likes
Like

Posted 03 October 2013 - 02:38 PM

you'll have to do a text replacement yourself in your drawtext function (replace the first %d with the first extra argument passed to the function). Since you are using C++ however you should probably just use stringstream to construct an appropriate string before passing it to the function rather than using old and highly unsafe C practices. (There is usually no need to use functions with a variable number of arguments in C++)
I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#3 WunderStrudel   Members   -  Reputation: 141

Like
0Likes
Like

Posted 03 October 2013 - 03:47 PM

Thank you for anwsering, although i'm not sure really sure which approach to take from here. 

Just cant figur out how to cheat it into displaying that freakin variable d; 

 

Btw. sry for my bad english, i'm kinda sleep "depribed"? idk, have been lookin at this freakin code in like 18 - 24 hours now d:   



#4 SimonForsman   Crossbones+   -  Reputation: 5456

Like
1Likes
Like

Posted 03 October 2013 - 04:33 PM

If you absolutely insist on doing it the C way look at the snprintf function. with c++ you should use std::string and std:stringstream rather than char pointers unless you have a very good reason not to.
I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#5 WunderStrudel   Members   -  Reputation: 141

Like
0Likes
Like

Posted 03 October 2013 - 08:02 PM

Ohhhh (: 

Actualy started out using "string", but then it didn't work with displaying the variables, so i though that maybe they had to be "char" becos those you loop through, if that makes any sense :D 



#6 farmdve   Members   -  Reputation: 194

Like
0Likes
Like

Posted 04 October 2013 - 11:33 AM

C way:

char buf[256]; // increase for more data, but this should be enough for a few stuff
snprintf(buf, 256, "MouseX; %d", mouseX);
DrawText(200, 200, buf);

Refactor your function for this to work.

 

As for C++, it probably has better and easier ways to do this.


Edited by farmdve, 04 October 2013 - 11:39 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS