Could anyone give me a clear explanation why this occurs. In my code
Code :
#include <iostream>
#include <GL/glut.h>
 
int Window_Width(500), Window_Height(500);
double X_mouse, Y_mouse;
 
// Glut functions
void setup();
void Mouse_Movement(int x, int y);
void Display();
void glutIdle();
void Reshape(int, int);
 
int main(int argc, char** argv)
{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); 
	glutInitWindowSize(Window_Width, Window_Height);
	glutInitWindowPosition(100, 100);
	glutCreateWindow("Camera Test");
	setup();
	glutDisplayFunc(Display);
	glutReshapeFunc(Reshape);
	glutIdleFunc(glutIdle);
	glutPassiveMotionFunc(Mouse_Movement);
 
	glutMainLoop();
	return 0;
}
 
void setup()
{
	glClearColor(1.0, 1.0, 1.0, 0.0);
	glEnable(GL_DEPTH_TEST);
 
}
 
void Mouse_Movement(int x, int y)
{
	// X & Y coordinates in Viewport space (2D)
	X_mouse = (double)x;
	Y_mouse = (double)y;
}
 
void Display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
	/*glMatrixMode(GL_PROJECTION);
	glLoadIdentity();*/
 
	glColor3f(1.0f, 0.0f, 0.0f);
	glBegin(GL_TRIANGLES);
		glVertex3f(-0.5, 0.0, 0.0);
		glVertex3f( 0.5, 0.0, 0.0);
		glVertex3f( 0.0, 0.5, 0.0);
	glEnd();
	glutSwapBuffers();  
}
 
void Reshape(int w, int h)
{
	glViewport(0, 0, (GLsizei)w, (GLsizei)h);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0, (float)w/(float)h, 0.1, 500.0);
	glMatrixMode(GL_MODELVIEW);
}
 
void glutIdle()
{
	glutPostRedisplay();
}

There is nothing drawn but if I uncomment glMatrixMode(GL_PROJECTION) in Display function, the triangle will be drawn. I have a lot of examples work without inserting glMatrixMode(GL_PROJECTION) inside the display function.