I success to generate the height map using VBO and IBO in openGL. The full picture of this data is shown in the figure below. What I want really show is only the data with non-black color. I put zero in z-value when the color is black.
Here is my code to generated the indexes
void triangle::getIndices(QVector<double> minmaxX_, QVector<double> minmaxY_)
{
indices.clear();
int numY = round((minmaxY_[1] - minmaxY_[0]) / minmaxY_[2]) + 1;
int numX = round((minmaxX_[1] - minmaxX_[0]) / minmaxX_[2]) + 1;
for (int row=0; row<numY-1; row++) {
if ((row&1) == 0 ) { // even rows
for ( int col=0; col<numX; col++ ) {
indices.append(col + row*numX);
indices.append(col + (row + 1)*numX);
}
}
else {
for ( int col=numX-1; col>=0; col-- ) {
indices.append(col + (row*numX));
indices.append(col + ((row + 1)*numX));
}
}
}
}
My Shader Code
const char* const frgshdr_source =
"uniform const float colorSize;\n"
"uniform vec3 colorTable[512];"
"varying float height;\n"
"uniform float heightSize;\n"
"uniform float heightMin;\n"
"void main() {\n"
" //vec3 colorTable2[int(colorSize)+1] = colorTable;\n"
" float h = (height - heightMin)/heightSize;\n"
" if (h < 0.0f || h > 1.0f) {\n"
" gl_FragColor = vec4(0.0f, 0.0f, 0.0f, 0.0f);}\n"
" else {"
" int i = 0;\n"
" while (h >= float(i + 1)/colorSize) {\n"
" i += 1;}\n"
" vec3 base = mix(colorTable[i], colorTable[i+1], colorSize*(h - (float(i)/colorSize)));\n"
" gl_FragColor = vec4(base, 1.0f);}\n"
"}\n";
Unfortunately after I clip the z-value using my projection matrix (orthographic). I still get some artifacts on the edge like in the picture below.
here is my orthographic projection matrix
m_projection.ortho( minX, maxX, minY, maxY, minZ, maxZ);
Look's like openGL recreate some triangles automatically so it makes artifacs around the edge (purple line).
Is there any method to make this edge artifacts disappear or I need to define my indexes again ?
Thank you in advance for your help.