Results 1 to 5 of 5

Thread: Qt Opengl, Changing objects color

  1. #1
    Join Date
    Jun 2008
    Posts
    32
    Qt products
    Qt4

    Default Qt Opengl, Changing objects color

    Hi,
    I'm trying to do a program which includes an opengl widget on the left and a tree on the right. So when the user selects the object from the tree, The object in the left shhould be highlighted or change color or smth else u offer me to do which is easier.
    I thought that changing its color would be the easiest one. But I didnot managed to succeed it.
    It seems correct. I don't understand where is the mistake.
    Here is my code:
    Qt Code:
    1. void GLWidget::initializeGL()
    2. {
    3. qglClearColor(trolltechPurple.dark());
    4. object = makeObject();
    5. glShadeModel(GL_FLAT);
    6. glEnable(GL_DEPTH_TEST);
    7. glEnable(GL_CULL_FACE);
    8. }
    9.  
    10. void GLWidget::paintGL()
    11. {
    12. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    13. glLoadIdentity();
    14. glTranslated(0.0, 0.0, -10.0);
    15. glRotated(xRot / 16.0, 1.0, 0.0, 0.0);
    16. glRotated(yRot / 16.0, 0.0, 1.0, 0.0);
    17. glRotated(zRot / 16.0, 0.0, 0.0, 1.0);
    18. glCallList(object);
    19. }
    20.  
    21. void GLWidget::resizeGL(int width, int height)
    22. {
    23. int side = qMin(width, height);
    24. glViewport((width - side) / 2, (height - side) / 2, side, side);
    25.  
    26. glMatrixMode(GL_PROJECTION);
    27. glLoadIdentity();
    28. glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
    29. glMatrixMode(GL_MODELVIEW);
    30. }
    31. void GLWidget::setHighlighted(){
    32. Purple = QColor::fromCmykF(0.25, 0.25, 0.20, 0.0);
    33. qglColor(Purple);
    34. //paintGL();
    35. //,nitializeGL();
    36. updateGL();
    37.  
    38. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jun 2008
    Posts
    32
    Qt products
    Qt4

    Default Re: Qt Opengl, Changing objects color

    Plss help me

  3. #3
    Join Date
    Jun 2008
    Posts
    32
    Qt products
    Qt4

    Default Re: Qt Opengl, Changing objects color

    http://doc.trolltech.com/4.3/opengl-hellogl.html
    im using this example for my base type. When I use the rotation functions in my slot function, it works. However I want to change the objects color.
    There is a signal called "xRotationChanged" in the implementation of setXrotation() function. There must be a function to change the color in the same way.
    But I couldn't find it, anybody can help me pls??
    Last edited by bod; 2nd July 2008 at 11:07.

  4. #4
    Join Date
    Jun 2008
    Posts
    32
    Qt products
    Qt4

    Default Re: Qt Opengl, Changing objects color

    will anybody help me ?

  5. #5
    Join Date
    Jun 2008
    Posts
    32
    Qt products
    Qt4

    Default Re: Qt Opengl, Changing objects color

    I couldn't find anycode for at least drawing also. So I decided to use "c".
    It compiles but it does not draw my objects on to the widget.
    Anybody has an idea why it does not do that?
    here is my c code inside "setHighligthed()" slot function:
    Qt Code:
    1. glColor3f(0.5f,0.5f,1.0f); // Set The Color To Blue One Time Only
    2. glBegin(GL_QUADS); // Start Drawing Quads
    3. glVertex3f(-1.0f, 1.0f, 0.0f); // Left And Up 1 Unit (Top Left)
    4. glVertex3f( 1.0f, 1.0f, 0.0f); // Right And Up 1 Unit (Top Right)
    5. glVertex3f( 1.0f,-1.0f, 0.0f); // Right And Down One Unit (Bottom Right)
    6. glVertex3f(-1.0f,-1.0f, 0.0f); // Left And Down One Unit (Bottom Left)
    7. glEnd();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Dynamically changing QFrame color
    By Doug Broadwell in forum Newbie
    Replies: 6
    Last Post: 16th October 2008, 09:22
  2. how to change backgroup color, button color and shape?
    By lzha022 in forum Qt Programming
    Replies: 10
    Last Post: 16th June 2008, 23:25
  3. changing color of push button
    By babu198649 in forum Newbie
    Replies: 1
    Last Post: 2nd March 2008, 13:55
  4. Changing QTabWidget's tabs color
    By troorl_ua in forum Qt Programming
    Replies: 1
    Last Post: 14th May 2007, 22:49
  5. prob with changing QLineEdit background color
    By Ahmad in forum Qt Programming
    Replies: 2
    Last Post: 30th April 2007, 13:44

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.