Only problem is, it only ever prints ‘a’. If I select a different set (these are for different colours) I do get the appropriate corresponding colour, however doesn’t print everything else. If I get text to the screen, I get the following results:
sText gets back “testing” which is exactly what I wanted it to display,
*sText gets ‘t’
&sText brings back:
0x28bc7c
0x28bc5c
Curiously, it returns these memory locations in an alternating manner.
sText gets back “testing” which is exactly what I wanted it to display,
Hmm, I’m confused, if it does print what you want, what is your problem again?
Without knowing the types (and values) of the variables in your code snippet it’s difficult to say anything.
sText is a pointer to my char string which has ‘testing’ in it, however ita only ever printing the letter ‘a’ from appropriate set. It should atthe very least be printing the lettwr ‘t’ which is rather strance since the string is definitely pointing to a ‘t’ or ‘testing’.
Did some more experimenting, tried calling glCallList(list) and it returns exactly what I expect (the correct letter from the correct set), so definitely something wierd happening when I call glCallLists().
Hi Guys, figured out what was happening, looks like when I call the lists, all it does is draw all the lists one on top of each other. If I call glCallList, everything is working as expected. Question now is, how do I offset after each list item is called by glCalllists?
void GLWidget::Print(int iRow, int iColumn, char *sText, int set, int iArrayLength) //'set' is used for selecting the font set i.e. we can have a set of bold, a set of italicized, as set of normal fonts etc...
{
glPushMatrix();
glListBase(m_iTextSquare+(26 * (set-1)));
qDebug() << iArrayLength;
glCallLists(iArrayLength, GL_UNSIGNED_BYTE, sText);
glPopMatrix();
}
Anyone see any issues with this code? When I run the program, for some reason, the array length is stuck to 4 regardless of what value I allocate to the array when I write ‘new’ etc. if I write debug() << sText, it always returns the correct char array.
int iCharArrayLength;
iCharArrayLength = sizeof(cText)/sizeof(cText[0]);
Anyone see any issues with this code?[/QUOTE]
Yes. sizeof(cText) is the size of the pointer, not the size of the array.
An array allocated with “new” doesn’t store its size (at least, not in a way that’s accessible to the program). If you want to know how many characters are in the string, use strlen() or std::find(). If you want an array which keeps track of its size, use std::string or std::vector.