polygons drawn from one side only

Hello, I have an application in which a triangle is drawn. This triangle has a black side and a red side. This is achieved by drawing the triangle twice in both colors, using backface culling:


void Scene::Init()
{
	glEnable(GL_STENCIL_TEST);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);

	glClearColor(0.3f, 0.3f, 0.6f, 1.0f);
	glClearDepth(1.0f);

	glDepthFunc(GL_LEQUAL);

	GLfloat ambient_light[]= { 1.0f, 1.0f, 2.0f, 1.0f };
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT,ambient_light);

	GLfloat	diffuse_light[]={0.5f,0.5f,0.5f,1.0f};
	glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuse_light);

	glEnable(GL_LIGHT0);

	glLoadMatrixf(SetView(rotX,rotY,zoom).MatGL().m);

	// the data is now loaded, load it into the mesh
	mesh.LoadData(mesh_data);
}
void DrawTriangle()
{
	glBegin(GL_TRIANGLES);
	glVertex3f(0.0f,2.0f,0.0f);
	glVertex3f(1.0f,0.0f,0.0f);
	glVertex3f(-1.0f,0.0f,0.0f);
	glEnd();
}
void Scene::Render()
{
	app->SetPerspective(PROJECT_3D);
	glLoadMatrixf(SetView(rotX,rotY,zoom).MatGL().m);

	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	GLfloat light_pos[]={5.0f,5.0f,-5.0f,1.0f};
	glLightfv(GL_LIGHT0,GL_POSITION,light_pos);

	glPushAttrib(GL_LIGHTING_BIT|GL_TEXTURE_BIT);
	glDisable(GL_TEXTURE_2D);
	glDisable(GL_LIGHTING);
	glBegin(GL_LINES);
	glColor3f(1.0f,0,0); glVertex3f(0,0,0); glVertex3f(5.0f,0,0); // x axis
	glColor3f(0,1.0f,0); glVertex3f(0,0,0); glVertex3f(0,5.0f,0); // y axis
	glColor3f(0,0,1.0f); glVertex3f(0,0,0); glVertex3f(0,0,5.0f); // z axis
	glEnd();
	glPopAttrib();

	glCullFace(GL_BACK);

	glColor3f(0.0f,0.0f,0.0f);

	DrawTriangle();

	glCullFace(GL_FRONT);

	glColor3f(1.0f,0,0);

	DrawTriangle();
}

Not that I can rotate the view around the triangle with my mouse. So I can look at both the black and red sides.

The code worked, both sides showed up. Recently however, I’ve been making some changes to other parts of my application. Since then the red side isn’t visible anymore. If tried several things:

  • if I set glCullFace(GL_BACK) before drawing the red side of the triangle, it appears on the screen. At the same side as the black one.

  • if I set glCullFace(GL_FRONT); before drawing the black side, there’s no more black side.

  • disabling GL_STENCIL_TEST causes the red triangle to be drawn at the same side as the black one, only one side.

I have a back up of the old application without all my recent changes and there the red face still shows. I can’t remember anymore what I changed exactly but I’m sure I didn’t change any of the lines starting with ‘gl’.

Can somebody help me solve this mystery?

new development, I rebooted my computer, recompiled, now suddenly the triangle has two sides again.

weird huh?

it happens, sometimes ram gets corrupted and things get weird