I’m creating VOXELGRIDSIZE display lists from range
VoxelGridDispBase,VoxelGridDispBase + 1,…,VoxelGridDispBase + VOXELGRIDSIZE - 1,ok?
Actually I wrote wrongly my code.The correct code is(copy form cpp file):
for(int x = voxelgrid_size - 1; x>=0; x--)
{
glNewList(VoxelGridDispBase + x,GL_COMPILE);
...
glEndList();
}
In the loop I’m counting from VOXELGRIDSIZE - 1 to 0 including 0 and add the counter to VoxelGridDispBase. So I create exactly as many lists as I generated.
I don’t use wglShareLists.Maybe if I post the whole function will help you?
#ifdef _BITVOXELGRID
void BuildVoxelGridDispList(const bit_vector *voxelgrid,GLint voxelgrid_size,GLfloat *voxelgrid_center,GLfloat voxelgrid_length)
#else
void BuildVoxelGridDispList(const bool *voxelgrid,GLint voxelgrid_size,GLfloat *voxelgrid_center,GLfloat voxelgrid_length)
#endif
{
HWND hDlg = NULL;
char message[128]={NULL};
// Create progress bar Dialog box
hDlg = CreateDialog(Hinst,MAKEINTRESOURCE(IDD_VXLPROGRESS),Hwnd,ProgressDialogProc);
// Setup progress bar
SendDlgItemMessage(hDlg,IDC_PROGRESS1,PBM_SETPOS,(WPARAM)0,0);
SendDlgItemMessage(hDlg,IDC_PROGRESS1,PBM_SETRANGE,0,MAKELPARAM(0,voxelgrid_size));
SendDlgItemMessage(hDlg,IDC_PROGRESS1,PBM_SETSTEP,(WPARAM)1,0);
// Set progress bar to start
SendDlgItemMessage(hDlg,IDC_PROGRESS1,PBM_SETPOS,(WPARAM)0,0);
// Generate new display lists in
// memory and return a pointer to them
if(VoxelGridDispBase != 0)
glDeleteLists(VoxelGridDispBase,voxelgrid_size);
if(VoxelGridDispLists) delete[] VoxelGridDispLists;
// Allocate space for display lists
VoxelGridDispLists = new GLuint[voxelgrid_size];
// clean memory
memset(VoxelGridDispLists,0,voxelgrid_size * sizeof(GLuint));
if(!(VoxelGridDispBase = glGenLists(voxelgrid_size))) // generate display lists
{
MessageBox(Hwnd,"Could not Generate Display lists","OpenGL Error",NULL);
// Disable Voxel Grid rendering
EnableMenuItem(GetMenu(Hwnd),ID_VOXELIZATION_RENDER_VOXELGRID,MF_GRAYED);
}
GLfloat vxlCenter[3] = {0.0f , 0.0f , 0.0f}; // temp variable for storing each voxel's center
// Render every voxel
for(int x = voxelgrid_size - 1; x>=0; x--)
{
// Build message string set it
// to label above progress bar
sprintf(message,"Building Voxel Display Lists(%4.1f %%)",(100.0f - ((float)x/(float)voxelgrid_size * 100)));
SetDlgItemText(hDlg,IDC_LABEL,message);
SendDlgItemMessage(hDlg,IDC_PROGRESS1,PBM_STEPIT,0,0);
if(!glIsList(VoxelGridDispBase + x))
{
MessageBox(Hwnd,"Not a list!!",NULL,NULL);
break;
}
VoxelGridDispLists[x] = VoxelGridDispBase + x;
glNewList(VoxelGridDispBase + x,GL_COMPILE);
for(int y = voxelgrid_size - 1; y >= 0; y--)
for(int z = voxelgrid_size - 1; z >= 0; z--)
{
#ifdef _BITVOXELGRID
if((*voxelgrid)[voxelgrid_size * voxelgrid_size * x + voxelgrid_size * y + z])
#else
if(*(voxelgrid + voxelgrid_size * voxelgrid_size * x + voxelgrid_size * y + z))
#endif
{
CalcVoxelCenter(x,y,z,voxelgrid_center,voxelgrid_size,voxelgrid_length,vxlCenter);
glTranslatef(vxlCenter[0],vxlCenter[1],vxlCenter[2]);
glutSolidCube(voxelgrid_length / voxelgrid_size);
glTranslatef(-vxlCenter[0],-vxlCenter[1],-vxlCenter[2]);
}/*
else // useful debugging code do NOT DELETE
{
glColor3f(0.5f,0.5f,0.5f);
CalcVoxelCenter(x,y,z,vgrid_center,vgrid_length,vxlCenter);
glTranslatef(vxlCenter[0],vxlCenter[1],vxlCenter[2]);
glutWireCube(vgrid_length / VOXELGRIDSIZE);
glTranslatef(-vxlCenter[0],-vxlCenter[1],-vxlCenter[2]);
}*/
}
glEndList();
}
// Set progress bar to 100%
SendDlgItemMessage(hDlg,IDC_PROGRESS1,PBM_SETPOS,(WPARAM)voxelgrid_size,0);
// Close Dialog box
if(hDlg) DestroyWindow(hDlg);
}
Finally I delete like this:
if(VoxelGridDispBase != 0)
{
glDeleteLists(VoxelGridDispBase,VOXELGRIDSIZE);
VoxelGridDispBase = 0;
}
if(VoxelGridDispLists)
{
delete[] VoxelGridDispLists;
VoxelGridDispLists = NULL;
}