PDA

View Full Version : GLCallLists Not Behavng as Expected



Atomic_Sheep
08-01-2013, 06:35 AM
Hi guys, I have the following call to the function:


glListBase(m_iTextSquare+(26 * (set-1)));
glCallLists(iArrayLength, GL_UNSIGNED_BYTE, sText);

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.

Any ideas?

carsten neumann
08-01-2013, 04:17 PM
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.

Atomic_Sheep
08-01-2013, 06:00 PM
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'.

Atomic_Sheep
08-02-2013, 01:37 AM
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().

Atomic_Sheep
08-09-2013, 12:40 AM
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?

GClements
08-09-2013, 01:13 AM
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?
Add a glTranslate() call to each list (or, for bitmap text, use the xmove/ymove parameters in the glBitmap() call).

Atomic_Sheep
08-09-2013, 01:32 AM
EDIT:

I've got the following code:

cText is defined in header as char *cText;



cText = new char[2];
cText = "testing";

qDebug() << cText;
qDebug() << &cText;
qDebug() << *cText;

int iCharArrayLength;
iCharArrayLength = sizeof(cText)/sizeof(cText[0]);

Print(1, 1, cText, MAGENTA, iCharArrayLength);
}


The print function is:



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.

GClements
08-09-2013, 04:55 PM
I've got the following code:

cText is defined in header as char *cText;



cText = new char[2];




int iCharArrayLength;
iCharArrayLength = sizeof(cText)/sizeof(cText[0]);


Anyone see any issues with this code?
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.