PDA

View Full Version : Qt Opengl, Changing objects color



bod
1st July 2008, 15:07
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:

void GLWidget::initializeGL()
{
qglClearColor(trolltechPurple.dark());
object = makeObject();
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
}

void GLWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslated(0.0, 0.0, -10.0);
glRotated(xRot / 16.0, 1.0, 0.0, 0.0);
glRotated(yRot / 16.0, 0.0, 1.0, 0.0);
glRotated(zRot / 16.0, 0.0, 0.0, 1.0);
glCallList(object);
}

void GLWidget::resizeGL(int width, int height)
{
int side = qMin(width, height);
glViewport((width - side) / 2, (height - side) / 2, side, side);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0);
glMatrixMode(GL_MODELVIEW);
}
void GLWidget::setHighlighted(){
Purple = QColor::fromCmykF(0.25, 0.25, 0.20, 0.0);
qglColor(Purple);
//paintGL();
//,nitializeGL();
updateGL();

}

bod
2nd July 2008, 06:55
Plss help me :(

bod
2nd July 2008, 09:33
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??

bod
2nd July 2008, 12:55
will anybody help me ? :(

bod
2nd July 2008, 13:13
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:

glColor3f(0.5f,0.5f,1.0f); // Set The Color To Blue One Time Only
glBegin(GL_QUADS); // Start Drawing Quads
glVertex3f(-1.0f, 1.0f, 0.0f); // Left And Up 1 Unit (Top Left)
glVertex3f( 1.0f, 1.0f, 0.0f); // Right And Up 1 Unit (Top Right)
glVertex3f( 1.0f,-1.0f, 0.0f); // Right And Down One Unit (Bottom Right)
glVertex3f(-1.0f,-1.0f, 0.0f); // Left And Down One Unit (Bottom Left)
glEnd();