Bug: rendered objects turning black.

I am rendering a NURBS patch and some control points. As soon as I render the control points the NURBS patch goes completely dark.


void drawNURB() {
	
	glPushMatrix();

	GLfloat diffuseColor[] = {0.8, 0.8, 1.0, 1.0};

	glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseColor);
	glMatrixMode(GL_MODELVIEW);

	gluBeginSurface(nurbRenderer);

		gluNurbsSurface(nurbRenderer,

				sKnotCount, sKnot,

				tKnotCount, tKnot,

				sStride, tStride,

				ctlArray,

				sOrder, tOrder,

				GL_MAP2_VERTEX_3);

	gluEndSurface(nurbRenderer);
	glPopMatrix();

}

void drawCtl() {
	glPushMatrix();

	GLfloat diffuseColor[] = {0.8, 0.8, 1.0, 1.0};

	glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseColor);
	glMatrixMode(GL_MODELVIEW);

	int i; 

	
	for (i = 0; i < ctlNum; i++) {

		glPushMatrix();

			glTranslatef(ctlArray[(3*i)], ctlArray[(3*i)+1], ctlArray[(3*i)+2]);
			glutSolidSphere(.5, 4, 4);

		glPopMatrix();	

	}
	glPopMatrix();
}

void display (void) {

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_MODELVIEW);

	setUpLight();

	setUpView();


	drawNURB();
	drawCtl();	


	glutSwapBuffers();

}

Am I doing anything bad in these calls? Thanks in advance for the help.

Do you call glEnable(GL_AUTO_NORMAL) somewhere to enable the generation of normal vectors for the NURBS? I have tried something similar to your code and it work well.

Or you can also specify precomputed normals with gluNurbsSurface using GL_MAP2_NORMAL as surface type according to the end of this page.

You got a black surface, because with lighting is enabled and when you call glutSolidSphere, this one set the sphere normals. Then when you draw the nurb surface without specifying vertex normals, the last specified normal (from the sphere) is used and could lead to unexpected results.

Thanks. This solved my problem.