Answer the question
In order to leave comments, you need to log in
Why doesn't the z-axis draw?
Good afternoon!
I can not understand why the z-axis does not draw. The x and y axes draw.
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(1200, 800);
glutCreateWindow("OpenGL lesson 5");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glutKeyboardFunc(processNormalKeys);
glutSpecialFunc(processSpecialKeys);
glutMainLoop();
return 0;
}
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-20, 20, -20, 20,-20, 20);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(1, 1, 1, 0);
}
void display()
{
float left = -15;
float right = 15;
float bottom = -15;
float top = 15;
float znear =15;
float zfar = -15;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0);
glPushMatrix();
glBegin(GL_LINES);
glColor3f(0, 0, 1);//x
glVertex3f(left, 0, 0);
glVertex3f(right, 0, 0);
glColor3f(0, 1, 0);//y
glVertex3f(0, bottom,0);
glVertex3f(0, top,0);
glColor3f(0, 1, 1);//z
glVertex3f(0, 0,znear);
glVertex3f(0, 0,zfar);
glEnd();
glColor3f(1.0, 0.0, 0.0);
glutWireTeapot(5);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
Answer the question
In order to leave comments, you need to log in
To begin with, it is worth considering the general system for identifying axes in 3D space. The axes X, Y, Z
are labeled with color channels R, G, B
in a one-to-one correspondence. The axis X
is always and everywhere red. The axis Y
is green. And the axis Z
is blue.
glVertex3f(0, 0,znear);
glVertex3f(0, 0,zfar);
X
and Y
from zero (at least by 1pt), change the color of the axis Z
, then it will become a little better visible.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question