PDA

View Full Version : Bug: rendered objects turning black.



godhandiscen
12-10-2008, 04:08 PM
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.

trinitrotoluene
12-10-2008, 04:38 PM
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.

dletozeun
12-11-2008, 03:34 AM
Or you can also specify precomputed normals with gluNurbsSurface using GL_MAP2_NORMAL as surface type according to the end of this page (http://www.opengl.org/sdk/docs/man/xhtml/gluNurbsSurface.xml).

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.

godhandiscen
12-11-2008, 04:17 AM
Thanks. This solved my problem.