Results 1 to 20 of 23

Thread: The Sturpor of OpenGL Lists

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default The Sturpor of OpenGL Lists

    Hi guys, trying to create texture font. Have the texture ready and have made a display list which has different parts of the texture mapped onto a GL Quad. I also have a 'Print' function that then prints this text to the screen. I got most of the code from NeHe, question is, how on earth do I get the correct text to display? i.e. say I do Print("abcdef", 3, 2) or whatever the function is, the text that shows up random gibberish that doesn't correlate to the string that I type. In fact, when I go to re-size the window, the text actually changes. Yes it's pointers that are used to point to the string of text which means that whatever it's pointing to is incorrect or at the very least it's pointing to some part of the memory that is dynamic/changing and not the string text pointer variable that I created. But this isn't the problem.

    My question is: if I create a list, how do I then pick out specific things from it to print out specific letters? i.e. when I want an A, how do I pick out the right quad? I've looked everywhere on the internet and can't seem to find the answer. NeHe's perspective doesn't answer my question.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: The Sturpor of OpenGL Lists

    I don't know how you expect us to help you without telling us what you actually do. If you want to print "abcdef" then "a" is the first item so if you're keeping a list of some objects representing your data, it will be the first item.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: The Sturpor of OpenGL Lists

    Ok no probs, I have the following code:

    Qt Code:
    1. for(loop=1;loop<183; loop++)
    2. {
    3. cx = float(loop%26)/26.0f;
    4. cy = float(loop/7)/7.0f;
    5. glNewList(m_iDisplaySquare+loop, GL_COMPILE);
    6.  
    7. glBegin(GL_QUADS);
    8.  
    9. //Bottom Left
    10. glTexCoord2f(cx,1-cy-0.1f); // Texture Coord (Bottom Left)
    11. glVertex2i(-15.3f,-25.6f); // Vertex Coord (Bottom Left)
    12.  
    13. //Bottom Right
    14. glTexCoord2f(cx+0.03846f,1-cy-0.1f); // Texture Coord (Bottom Right)
    15. glVertex2i(15.3f,-25.6f); // Vertex Coord (Bottom Right)
    16.  
    17. //Top Right
    18. glTexCoord2f(cx+0.03846f,1-cy); // Texture Coord (Top Right)
    19. glVertex2i(15.3f,25.6f); // Vertex Coord (Top Right)
    20.  
    21. //Top Left
    22. glTexCoord2f(cx,1-cy); // Texture Coord (Top Left)
    23. glVertex2i(-15.3f,25.6f); // Vertex Coord (Top Left)
    24.  
    25. glEnd(); // Done Building Our Quad (Character)
    26. glTranslated(30.6,0,0); // Move To The Right Of The Character
    27.  
    28. glEndList(); // Done Building The Display List
    29. }
    To copy to clipboard, switch view to plain text mode 
    This creates the list and allocates different parts of the .bmp to my quads.

    Qt Code:
    1. void GLWidget::Print(int x, int y, QString *sText, int set) //'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...
    2. {
    3. if (set>1)
    4. {
    5. set=1;
    6. }
    7.  
    8. glBindTexture(GL_TEXTURE_2D, texture[1]);
    9. glDisable(GL_DEPTH_TEST);
    10. glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
    11. glPushMatrix(); // Store The Projection Matrix
    12. glLoadIdentity(); // Reset The Projection Matrix
    13. glOrtho(0,619,0,486,-1,1); // Set Up An Ortho Screen
    14. glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
    15. glPushMatrix(); // Store The Modelview Matrix
    16. glLoadIdentity(); // Reset The Modelview Matrix
    17.  
    18. //This line positions the text
    19. glTranslated(x,y,0); // Position The Text (0,0 - Bottom Left)
    20. glListBase(m_iDisplaySquare+1-32+(128*set)); // Choose The Font Set (0 or 1)
    21. glCallLists(sText->size(),GL_UNSIGNED_BYTE,sText); // Write The Text To The Screen
    22. glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
    23. glPopMatrix(); // Restore The Old Projection Matrix
    24. glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
    25. glPopMatrix(); // Restore The Old Projection Matrix
    26. glEnable(GL_DEPTH_TEST); // Enables Depth Testing
    27. }
    To copy to clipboard, switch view to plain text mode 
    This is what I'm using to print. As I said, when I do:

    Qt Code:
    1. QString sStringText;
    2. sStringText = "abcdefg";
    3. QString *pStringPointer = &sStringText;
    4.  
    5. Print(619/4.63,400, pStringPointer, 0);
    To copy to clipboard, switch view to plain text mode 
    What I get is jibberish. I have 7 lines of text in my .bmp with each line representing a unique set (each one differs by colour). At the moment, I get random letters of random colours popping up. For some reason I keep getting 6 letters popping up despite the fact that abcdefg is obviously a string of 7 characters.

    I have gone through the tutorial by NeHe many times and nowhere do I see obvious code that define that say the 3 value in our list is c, nor do I see the evocation of that 3rd element when asking specifically for a c.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: The Sturpor of OpenGL Lists

    Why are you passing a pointer to QString to glCallLists()?

    According to the docs glCallLists accepts "the address of an array of name offsets in the display list". A pointer to QString does not conform to such specification.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: The Sturpor of OpenGL Lists

    If I understood you correctly then what you said has cleared up a few questions but has also made me question the code that NeHe provided which in itself is a worry since he knows more than me. That's where I got my code from:

    http://nehe.gamedev.net/tutorial/2d_texture_font/18002/

    I tried posting the whole piece of code without all the comments but unfortunately it ended up too big to post.

    Nowhere in there do I see an array being used and a conversion of a string to an array that would enable calling specific elements from our quad list. I was confused about how the program knew which elements from the list to pull by just putting in a string when I first saw the tutorial and no matter how many time I've reviewed it since, that mystery has eluded me. Hence my original question.
    Last edited by Atomic_Sheep; 14th January 2013 at 09:54.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: The Sturpor of OpenGL Lists

    They are using char* as the "string" which is an array of char (aka unsigned byte) elements which is ok. This is totally different than a pointer to QString.

    Copying tutorials you don't understand is not a good idea.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: The Sturpor of OpenGL Lists

    Ah I see, thanks, somewhat get it. In terms of copying, fake it till you make it . Have started reading up on char strings, didn't know that was a thing .
    Last edited by Atomic_Sheep; 14th January 2013 at 12:10.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: The Sturpor of OpenGL Lists

    The tutorial clearly states "as we did in all other font tutorials". Did you read through all those other tutorials? I'm sure the approach was explained there.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: The Sturpor of OpenGL Lists

    No I didn't read those other tutorials because I wasn't trying to create text using other techniques.

    EDIT: having read about char pointers, there's one thing I still don't understand:

    When we create a string using char i.e. an array of chars, how does that allow us to access numerical references of our quads in the texture problem? Not sure if I expressed myself comprehensibly enough, so just to make sure I've crossed the ts and dotted the i's, if I create a string using char:

    char test[] = "test";
    char *testPointer;

    how does that enable me to pull an array element of say base[15] from the 256 array elements that get created when I put in a char pointer into the print function? If my memory serves me correctly, each character has it's own 0-255 code somewhere? So all that one has to do is to create a bitmap that complies with the naming and ordering of characters?

    P.S. Many thanks, got the string length bit working perfectly now, just gotta figure out the final piece of the puzzle .
    Last edited by Atomic_Sheep; 14th January 2013 at 12:39.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: The Sturpor of OpenGL Lists

    Quote Originally Posted by Atomic_Sheep View Post
    No I didn't read those other tutorials because I wasn't trying to create text using other techniques.
    And now three days later your problem still remains unsolved.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Jun 2011
    Posts
    203
    Thanks
    7
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: The Sturpor of OpenGL Lists

    I don't disagree with what you're saying but I can only progress as much as I can, unless I'm staring the obvious right in the face and am missing the point.

Similar Threads

  1. Inputting Into Lists
    By kiyoutee in forum Newbie
    Replies: 2
    Last Post: 2nd March 2011, 07:48
  2. Hi all, some about lists and views
    By kosasker in forum Newbie
    Replies: 4
    Last Post: 24th January 2011, 12:55
  3. display lists
    By rick_st3 in forum Newbie
    Replies: 3
    Last Post: 22nd June 2008, 23:09
  4. Some problems with lists
    By gdiepen in forum Qt Programming
    Replies: 9
    Last Post: 16th January 2008, 16:54
  5. When sort the lists?
    By SkripT in forum Qt Programming
    Replies: 6
    Last Post: 14th April 2006, 16:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.