A friend of mine has this opengl code, and its a wee bit buggy. Returns a sigserver fault. Anyone see any obvious errors in the line maked //<-bug?
Code:
bool initTerrain()
{
int i;
int x, z;
//GLfloat knots[8] = {0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0};
for(i = 0; i < NUM_TERRAIN; i++)
{
terrain[i] = new Terrain;
}
terrain[0]->SetPrefs("terrain1.bmp", 256, 256, true);
//terrain[0]->SetPrefs("grass.bmp", 256, 256);
for(i = 0; i < NUM_TERRAIN; i++)
{
if(!terrain[i]->Load())
return false;
terrain[i]->Scale(0, 20);
terrainDL[i] = terrain[i]->CreateDL(0,0,0);
}
userPos.y = terrain[0]->GetHeight((int)userPos.x, (int)userPos.z)+5.0;
for(i = 0; i < NUM_TERRAIN; i++)
nurbs[i] = gluNewNurbsRenderer();
nurbCoord = (GLfloat *)malloc(sizeof(GLfloat)*terrain[0]->GetLength()*terrain[0]->GetWidth()*3);
for(x = 0; x < terrain[0]->GetLength(); x++)
{
for(z = 0; z < terrain[0]->GetWidth(); z++)
{
nurbCoord[x*terrain[0]->GetLength()+z*3] = x;
nurbCoord[x*terrain[0]->GetLength()+z*3+1] = terrain[0]->GetHeight(x, z);
nurbCoord[x*terrain[0]->GetLength()+z*3+2] = z;
}
}
gluNurbsProperty(nurbs[0], GLU_SAMPLING_TOLERANCE, 25.0);
gluNurbsProperty(nurbs[0], GLU_DISPLAY_MODE, GLU_FILL);
glNewList(DL_NURBS_1, GL_COMPILE);
GLfloat knots[8] = {0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0};
glPushMatrix();
gluBeginSurface(nurbs[0]);
gluNurbsSurface(nurbs[0], //<-BUG This is the line that crashes
8, knots, 8, knots,
terrain[0]->GetLength()*terrain[0]->GetWidth(),
3, nurbCoord,
4, 4, GL_MAP2_VERTEX_3);
gluEndSurface(nurbs[0]);
glPopMatrix();
glEndList();
return true;
}