Results 1 to 8 of 8

Thread: QGLWidget Not Drawing Outside Of paintGL()

  1. #1
    Join Date
    Oct 2012
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Question QGLWidget Not Drawing Outside Of paintGL()

    Hello There,

    I am trying to create a level editor for my game using a QGLWidget but I have run into a slight problem. When I use the standard paintGL() function like this:
    Qt Code:
    1. void GLWidget::paintGL()
    2. {
    3. glClear(GL_COLOR_BUFFER_BIT);
    4. glBegin(GL_TRIANGLES);
    5. glVertex2f(0,0);
    6. glVertex2f(0,50);
    7. glVertex2f(50,0);
    8. glEnd();
    9. }
    To copy to clipboard, switch view to plain text mode 

    everything works fine. However, if I try and use my own function to draw a triangle:

    Qt Code:
    1. void GLWidget::DrawAlphaTile(int x, int y)
    2. {
    3. glColor3f(1,0,0);
    4. glBegin(GL_TRIANGLES);
    5. glVertex2f(x,y);
    6. glVertex2f(x + 32, y);
    7. glVertex2f(x + 32,y - 32);
    8. glVertex2f(x,y - 32);
    9. glEnd();
    10. }
    To copy to clipboard, switch view to plain text mode 

    It does not work. Is there a way around this because there is a lot of user input involved with the integer parameters?

    Thanks,
    Matt

  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: QGLWidget Not Drawing Outside Of paintGL()

    Why can't you just put that code in paintGL()?
    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
    Oct 2012
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget Not Drawing Outside Of paintGL()

    Quote Originally Posted by wysota View Post
    Why can't you just put that code in paintGL()?
    Because it needs to be calledmultiple times with different parameters.

  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: QGLWidget Not Drawing Outside Of paintGL()

    Quote Originally Posted by steadi View Post
    Because it needs to be calledmultiple times with different parameters.
    So call it from within paintGL(). I'm assuming this method is not public, is it?
    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
    Oct 2012
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget Not Drawing Outside Of paintGL()

    Quote Originally Posted by wysota View Post
    So call it from within paintGL(). I'm assuming this method is not public, is it?
    I am sorry but I have no idea where you are going with this mate. I need to be able to load in a .txt file of tile locations and z values and then draw them accordingly. How does one go about doing this? You cannot call a function from outside paintGL().

    What would be the point of calling it from within if it needs to iterate through many QStringListItems, convert them and then call a function that will one by one sort through them and draw them to the screen at given coordinates.

  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: QGLWidget Not Drawing Outside Of paintGL()

    Quote Originally Posted by steadi View Post
    What would be the point of calling it from within if it needs to iterate through many QStringListItems, convert them and then call a function that will one by one sort through them and draw them to the screen at given coordinates.
    No, it doesn't need to do all that. If the function is about drawing an entity then it draws the entity, it doesn't load it, parse it, play the violin and do all other possible stuff. If you want a function to load some data, then do exactly that -- implement a function to load the data and when the data is loaded ask the UI to update itself (by calling update() or updateGL()). Eventually it will call paintGL() which can call a function of your choice that will draw the data parsed earlier.
    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
    Oct 2012
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGLWidget Not Drawing Outside Of paintGL()

    Quote Originally Posted by wysota View Post
    No, it doesn't need to do all that. If the function is about drawing an entity then it draws the entity, it doesn't load it, parse it, play the violin and do all other possible stuff. If you want a function to load some data, then do exactly that -- implement a function to load the data and when the data is loaded ask the UI to update itself (by calling update() or updateGL()). Eventually it will call paintGL() which can call a function of your choice that will draw the data parsed earlier.
    Okay. Lemme simplify this to something we can both understand:
    I want to draw a square onto a QGLWidget everytime I press a button, but I cannot because the press button event is outside of paintGL()... How do i go about solving this?

  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: QGLWidget Not Drawing Outside Of paintGL()

    Quote Originally Posted by steadi View Post
    Okay. Lemme simplify this to something we can both understand:
    I want to draw a square onto a QGLWidget everytime I press a button, but I cannot because the press button event is outside of paintGL()... How do i go about solving this?
    Exactly like I said, make the "addButton" method add a button to an internal list of added buttons and call updateGL(). In paintGL() iterate over the list and draw the buttons.
    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.


Similar Threads

  1. call drawing function out of paintGL
    By CyrilQt in forum Qt Programming
    Replies: 12
    Last Post: 16th June 2012, 10:17
  2. Why paintGL() in QGLWidget is called twice
    By xiangxw in forum Qt Programming
    Replies: 5
    Last Post: 29th February 2012, 10:06
  3. QGLWidget's PaintGl Method
    By beginQT in forum Newbie
    Replies: 5
    Last Post: 25th September 2011, 12:48
  4. Replies: 7
    Last Post: 1st July 2011, 01:21
  5. QGLWidget, toolbox and paintGL()
    By mickey in forum Qt Programming
    Replies: 3
    Last Post: 21st March 2006, 01:05

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.