[Qt+OpenGL]
-
wrote on 25 Mar 2022, 15:08 last edited by appdev
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 ?
-
wrote on 28 Mar 2022, 13:15 last edited by
Update: I used texture->release() function to unbind it from the currently active texture unit. Now the frame is all black
-
wrote on 1 Apr 2022, 10:52 last edited by
Update: Problem solved.
If you ever face this problem, Please tell me, I can help :D -
wrote on 1 Apr 2022, 14:35 last edited by
@appdev Eerr, care to share with us now?
-
wrote on 6 Apr 2022, 11:03 last edited by
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. ^^
1/5