static void cwk2_terrain_render_patch (Shape *terrain, int x, int y, int size) { Cwk2TerrainData *data = terrain->private_data; int i, index = (y*data->size)+x; if (data->textured) glBindTexture (GL_TEXTURE_2D, data->texture); glBegin (GL_TRIANGLE_FAN); /* Centre */ if (data->textured) glTexCoord2f (size/2, size/2); glColor3fv (terrain->vcolours[index]); glNormal3fv (terrain->vnormals[index]); glVertex3fv (terrain->vertices[index]); /* Top-right -> Top-left */ index -= (size * data->size) - size; for (i = 0; i < size * 2; i++, index--) { if (terrain->vertices[index][3] > 0) { if (data->textured) glTexCoord2f (size - (i/2), 0); glColor3fv (terrain->vcolours[index]); glNormal3fv (terrain->vnormals[index]); glVertex3fv (terrain->vertices[index]); } } /* Top-left -> Bottom-left */ for (i = 0; i < size * 2; i++, index+=data->size) { if (terrain->vertices[index][3] > 0) { if (data->textured) glTexCoord2f (0, i/2); glColor3fv (terrain->vcolours[index]); glNormal3fv (terrain->vnormals[index]); glVertex3fv (terrain->vertices[index]); } } /* Bottom-left -> Bottom-right */ for (i = 0; i < size * 2; i++, index++) { if (terrain->vertices[index][3] > 0) { if (data->textured) glTexCoord2f (i/2, size); glColor3fv (terrain->vcolours[index]); glNormal3fv (terrain->vnormals[index]); glVertex3fv (terrain->vertices[index]); } } /* Bottom-right -> Top-right */ for (i = 0; i <= size * 2; i++, index-=data->size) { if (terrain->vertices[index][3] > 0) { if (data->textured) glTexCoord2f (size, size - (i/2)); glColor3fv (terrain->vcolours[index]); glNormal3fv (terrain->vnormals[index]); glVertex3fv (terrain->vertices[index]); } } glEnd (); }