PDA

View Full Version : How to render a GLU NURB into a Display List



gui24a
08-11-2008, 08:19 AM
Guys, sorry for creating another thread for this, but I would like to know how is the way to proper render a NURBS into a Display List. I tried but the problem is the surface doesn't render correctly (it stays buggy, malformed) inside a display list. When I render normally (at display func, i.e) it works well, with the exactly same steps as rendering to a display list. The function is as follow:


void DisplayList_Montanha()
{
GLUnurbsObj *theNurb;

GLfloat ctlpoints[4][4][3];
GLfloat knots[8] = {0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0};

/* Define o material da montanha */
GLfloat MMatSpecular[4] = { 1, 1, 1, 1 };
GLfloat MMatDifuseAmbient[4] = {0.5, 0.5, 0.5, 1.0};
GLfloat MMatShininess[1] = { 40 };
GLfloat MMatEmissao[4] = {0, 0, 0, 1.0};

int u, v;

for (u = 0; u < 4; u++) {
for (v = 0; v < 4; v++) {
ctlpoints[u][v][0] = 2.0*((GLfloat)u - 1.5);
ctlpoints[u][v][1] = 2.0*((GLfloat)v - 1.5);

if ( (u == 1 || u == 2) &amp;&amp; (v == 1 || v == 2))
ctlpoints[u][v][2] = 3.0;
else
ctlpoints[u][v][2] = -3.0;
}
}

theNurb = gluNewNurbsRenderer();
gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 25.0);
gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL);
//gluNurbsProperty(theNurb, GLU_AUTO_LOAD_MATRIX, GLU_FALSE);

Dl_Montanha = glGenLists(1);
glNewList(Dl_Montanha,GL_COMPILE);

/* seta o material para a montanha */
glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, MMatEmissao);
glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, MMatSpecular);
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, MMatDifuseAmbient);
glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, MMatShininess);

gluBeginSurface(theNurb);
gluNurbsSurface(theNurb,8, knots, 8, knots, 4*3, 3, &amp;ctlpoints[0][0][0], 4, 4, GL_MAP2_VERTEX_3);
gluEndSurface(theNurb);

glEndList();

gluDeleteNurbsRenderer(theNurb);

}


regards!