Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: GLCallLists Not Behavng as Expected

  1. #1
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    14

    GLCallLists Not Behavng as Expected

    Hi guys, I have the following call to the function:

    Code :
            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?

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    751
    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.

  3. #3
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    14
    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'.

  4. #4
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    14
    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().

  5. #5
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    14
    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?
    Last edited by Atomic_Sheep; 08-09-2013 at 01:22 AM.

  6. #6
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    490
    Quote Originally Posted by Atomic_Sheep View Post
    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).

  7. #7
    Junior Member Newbie
    Join Date
    May 2012
    Posts
    14
    EDIT:

    I've got the following code:

    cText is defined in header as char *cText;

    Code :
            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:

    Code :
    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.
    Last edited by Atomic_Sheep; 08-09-2013 at 03:41 AM.

  8. #8
    Member Regular Contributor
    Join Date
    Jun 2013
    Posts
    490
    Quote Originally Posted by Atomic_Sheep View Post

    I've got the following code:

    cText is defined in header as char *cText;

    Code :
            cText = new char[2];

    Code :
            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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •