Results 1 to 7 of 7

Thread: glColor and GL_LINES

  1. #1
    Join Date
    Aug 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default glColor and GL_LINES

    hi!.
    I'm using Qt 4.6 in GNU/Linux. i'm working with QGLWidget with kind of easiness but i've a problem when i want to change the color of the Lines.
    I've tried all the combinations that i could think.
    i've put the glColor after and befor de glBegin, use the qglColor, and glColor3f (and others glColors functions). But always it's a random color between blue and green (never red (i don't know why)).
    What am i missing?

    Qt Code:
    1. glBegin(GL_LINES);
    2. glColor3f(1.0f,0.0,0.0);
    3. glVertex2f(50,1);
    4. glVertex2f(120,1);
    5. glEnd()
    6. ;
    To copy to clipboard, switch view to plain text mode 

    this very basic code doesn't work

    Qt Code:
    1. void Plot::paintGL()
    2. {
    3. glBegin(GL_LINES);
    4. glColor3f(1.0f,0.0,0.0);
    5. glVertex2f(50,1);
    6.  
    7. glVertex2f(120,1);
    8. glEnd();
    9. }
    10.  
    11. void Plot::initializeGL()
    12. {
    13. // Also i've tried a lot of combinations here. GL_FLAT and others.
    14. glClearColor(1.0, 1.0 , 1.0, 0.0);
    15. glLoadIdentity();
    16. glTranslatef(0,0.0,0);
    17. glDisable(GL_TEXTURE_2D);
    18. glDisable(GL_LIGHTING);
    19. glShadeModel(GL_SMOOTH);
    20.  
    21. }
    22.  
    23.  
    24. void Plot::resizeGL(int w, int h)
    25. {
    26. glViewport( 0, 0, (GLint)w, (GLint)h );
    27. glMatrixMode( GL_PROJECTION );
    28. glLoadIdentity();
    29.  
    30. glOrtho( 0, 800, yMin, yMax, -5.0, 1.0 );
    31. glMatrixMode( GL_MODELVIEW );
    32.  
    33. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Dec 2009
    Posts
    24
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: glColor and GL_LINES

    I dont see any:
    glClear(GL_CLEAR_COLOR_BUFFER_BIT | GL _DEPTH_BUFFER_BIT)
    at the beginning of your paintGL() routine...

    is that on purpose?

  3. #3
    Join Date
    Aug 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: glColor and GL_LINES

    I dont see any:
    glClear(GL_CLEAR_COLOR_BUFFER_BIT | GL _DEPTH_BUFFER_BIT)
    at the beginning of your paintGL() routine...

    is that on purpose?
    yes, is on porpouse beacouse i'm writing an application that don't erase the screen every frame.
    But is the same thing with the color clearing the buffers or not :s

    Qt Code:
    1. void Plot::paintGL()
    2. {
    3. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    4. glBegin(GL_LINES);
    5. glColor3f(1.0f,0.0,0.0);
    6. glVertex2f(50,1);
    7.  
    8. glVertex2f(120,1);
    9. glEnd();
    10. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Dec 2009
    Posts
    24
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: glColor and GL_LINES

    I just copied/pasted your code into the hellogl example....and it's working as intended... (line is red)
    so the code is probably ok...

    are the Qt OpenGL examples working alright?

  5. #5
    Join Date
    Apr 2009
    Posts
    32
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: glColor and GL_LINES

    Could be a driver issue. What platform are you running on? What OpenGL driver do you use?

    Mads

  6. #6
    Join Date
    Aug 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: glColor and GL_LINES

    i'm using a x86 GNU/Linux with an ATI raden 9550 using the open-source drivers ( xf86-video-ati 6.12.4-3 )
    Mesa Version mesa 7.7-1

    i've tried in a machine with xp and works fine.

  7. #7
    Join Date
    Dec 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: glColor and GL_LINES

    if you have

    Qt Code:
    1. glEnable(GL_LIGHTING);
    To copy to clipboard, switch view to plain text mode 

    then you should have

    Qt Code:
    1. glColorMaterial ( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
    2. glEnable ( GL_COLOR_MATERIAL );
    To copy to clipboard, switch view to plain text mode 

    otherwise glColor3f() has no meaning at all..

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
  •  
Qt is a trademark of The Qt Company.