PDA

View Full Version : Converting an int to const GLvoid



Bobalandi
02-29-2008, 07:12 PM
I'm trying to take an integer I use for the score in a game I'm working on, and it draw it onto the screen, so I use this code:

wglUseFontBitmaps(hdc, 0, 256, 1000);
glRasterPos3f(30.0f, 300.0f,0.0f);
glListBase(1000);
glCallLists(12, GL_INT, score);
glFlush();
glDeleteLists(1000, 256);It worked when I used "GL_BYTE" and used "I like pie" instead of score, but now it isn't compiling, it gives me the error:

364 main.cpp invalid conversion from `int' to `const GLvoid*'
How can I fix this?

-NiCo-
02-29-2008, 07:19 PM
Apparently score is an int while it should be a pointer.
Where do you assign score?

e.g. "I like pie" returns a pointer to the first character.

Bobalandi
02-29-2008, 07:21 PM
Umm, it's a global.

-NiCo-
02-29-2008, 07:31 PM
You're not trying to print out an int value (score) using

glCallLists(12, GL_INT, score);

are you?

The lists contain characters (a,b,c,d,e,f,...) so if you do

glCallLists(4, GL_BYTE, "test");

it will scan the char-array "test"
So first it calls the list corresponding to 't'
then the one for e
then the one for s
then the one for t

If you want to print out score you first have to convert your int to a char-array using itoa (http://www.cplusplus.com/reference/clibrary/cstdlib/itoa.html) or sprintf and then print out the char array just like you did the others.

int score = 512;
char score_chars[100];
sprintf(score_chars,"%d",score);
glCallLists(strlen(score_chars), GL_BYTE, &score_chars[0]);

N.

Bobalandi
02-29-2008, 08:09 PM
That worked perfectly, thanks. :]

Bobalandi
02-29-2008, 08:29 PM
Sorry, there are two other things I am wondering, is it possible to increase the text size? and if so, is it also possible to center it?

-NiCo-
02-29-2008, 08:40 PM
You can't scale using bitmaps from wglUseFontBitmaps. You can change the position of the text by altering the glRasterPos parameters but you'll have to calculate the offsets for centering yourself.

If you're looking for a font renderer where all of the transformation matrices apply (scale,translate,rotate,..), I recommend quesoglc (http://quesoglc.sourceforge.net/).

N.

Bobalandi
02-29-2008, 08:54 PM
Ok, thanks :]