[Qt+OpenGL]
-
Hey,
I tried to modify the cube example in Qt by adding a coordinate system and changing the texture.
These are the line codes to draw the frame:
void MainWidget::draw_frame()
{ glLineWidth(8.0f);glBegin(GL_LINES); //X_axis glColor3f( (1.0, 0.0, 0.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(4.0, 0.0, 0.0); // arrow glVertex3f(4.0, 0.0f, 0.0f); glVertex3f(3.75, 0.25f, 0.0f); glVertex3f(4.0, 0.0f, 0.0f); glVertex3f(3.75, -0.25f, 0.0f); //Y_axis glColor3f (0.0, 1.0, 0.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 4.0, 0.0); // arrow glVertex3f(0.0, 4.0f, 0.0f); glVertex3f(0.25, 3.75f, 0.0f); glVertex3f(0.0, 4.0f, 0.0f); glVertex3f(-0.25, 3.75f, 0.0f); //Z_axis glColor3f (0.0, 0.0, 1.0); glVertex3f(0.0, 0.0, 0.0); glVertex3f(0.0, 0.0, 4.0); // arrow glVertex3f(0.0, 0.0f ,4.0f ); glVertex3f(0.0, 0.25f ,3.75f ); glVertex3f(0.0, 0.0f ,4.0f ); glVertex3f(0.0, -0.25f ,3.75f ); glEnd();
}
Each axis is supposed to have a specific color ( for example x: red, y: green, z:blue).
However the axes have the same color as the cube texture.
Any idea on how to fix the problem ?
-
Sure with great pleasure,
After disabling texture and shader program, you should specify the matrix mode in glMatrixMode:
glMatrixMode(GL_PROJECTION) then load the projection matrix you used (call glLoadMatrixf)
glMatrixMode(GL_MODELVIEW) then load the modelview matrix. Transform it to identity.
Finally you can draw the coordinate system or any other object. In this case, the texture of the first object won't have any effect on any other object rendered after. ^^