# How do I do meshes?

Hello, how does OpenGL support meshes, something similar to DirectX’s mesh interfaces and DrawSubset functions?

openGL draws polygons. meshs are composed of polygons. Use either display lists, vertex arrays or glBegin/glEnd pairs to draw them.

No, OGL doesn’t have a standard mesh handling functions. U must provide your hown function to load/display meshes.

There are a lot of libraries out there to play with, for example 3dslib.

Now I use the simple way to generate mesh.
class 3DGrid{
double x,y,z;

}

3DGrid*** grid;

grid=new 3DGrid**[Nx];
for(i=0;i<Nx;i++)
grid[i]=new double*[Ny];

for(i=0;i<Nx;i++)
for(j=0;j<Ny;j++)
{
grid[i][j]=new double[Nz];
}

void Line(…)
{
glBegin(GL_LINES)
glVertex(x1,y1,z1);
glVertex(x2,y2,z2);
glEnd();
}

//Draw mesh
for( k=0;k<Nz;k++)
{
//vertical line-y
for(i=0;i<Nx;i++)
for(j=0;j<(Ny-1);j++)
{
x1=grid[i][j][k].x;
y1=grid[i][j][k].y;
z1=grid[i][j][k].z;
x2=grid[i][j+1][k].x;
y2=grid[i][j+1][k].y;
z2=grid[i][j+1][k].z;

``````          Line(x1,y1,z1,
x2,y2,z2);
}
//horizontal line-x
for(j=0;j&lt;Ny;j++)
for(i=0;i&lt;(Nx-1);i++)
{
x1=grid[i][j][k].x;
y1=grid[i][j][k].y;
z1=grid[i][j][k].z;
x2=grid[i+1][j][k].x;
y2=grid[i+1][j][k].y;
z2=grid[i+1][j][k].z;

Line(x1,y1,z1,
x2,y2,z2);
}
``````

//Dept line-z
if(k!=(Nz-1)//to cancel at k==(Nz-1)
for(i=0;j<Nx;i++)
for(j=0;j<(Ny);j++)
{
x1=grid[i][j][k].x;
y1=grid[i][j][k].y;
z1=grid[i][j][k].z;
x2=grid[i][j][k+1].x;
y2=grid[i][j][k+1].y;
z2=grid[i][j][k+1].z;

``````          Line(x1,y1,z1,
x2,y2,z2);
}
``````

}