i'm learning opengl programming for study purposes and i'm using openscenegraph wrapper around opengl.
My first goal is to render a 3d grid in which heights data is stored in a file as 2d matrix. First question:can i use TRIANGLE_STRIP to render that grid which can have concave or convex zones?
Second question: Is there a particular alghoritm to render 3d grids (terrains) for this purpose?
I started from a very simple grid data:
10 10 10 10 10
10 10 10 10 10
10 10 5 10 10
10 10 10 10 10
10 10 10 10 10
it is a very simple 5x5 heights grid, but the result, using triangle_strip is follow:
as u can see there is a extra-line that i cant drop from my triangle_Strip algorithm.
the code i used is follow (consider it is openscenegraph code).
in rows and columns vars (int) i store grid dimensions.
data is a osg::Vec3**
pointer in which previously i read plain values.
m_rpTerrainData is a osg::ref_ptr<osg::Vec3Array>
in which i load, in correct order (as triangle_strip wants) the vertices.
for(x=0;x<rows;x++)
{
for(y=0;y<columns;y++)
{
if(x<rows-1 && y<columns-1){
this->m_rpTerrainData->push_back(data[x][y]);
this->m_rpTerrainData->push_back(data[x+1][y]);
}
/*degenerate triangle because we at last of a column*/
if(x<rows-1 && y==columns-1 ){
this->m_rpTerrainData->push_back(data[x][y]);
this->m_rpTerrainData->push_back(data[x+1][y]);
this->m_rpTerrainData->push_back(data[x+1][y]);
this->m_rpTerrainData->push_back(data[x+1][0]);
}
}
}
//drop last element
this->m_rpTerrainData->pop_back();