I have a task to prepare a hipsometric globe in OpenGL. Besides of the colours of the vertices, I need some vertices to be higher (mountains), some to be lower.
Currently, I have a program which generates a globe, only with points (every 1 degree), all on the same height, I am doing that by passing latitude ang longitude to my program in GLSL, and it calculates translation matrix for each vertex.
Now, I can easily imagine how to move vertices higher and lower - I will just add another uniform variable "height", and in GLSL I will do the rest. The same easy thing is with passing color - no problem.
However, I have no idea, how to create a whole map using triangles (well, quadrangles composed from two triangles). The best solution I have, is that when I have four vertices (x1, x2, x3, x4) which create a quadrangle, I could just transform a quadrangle (which was previously in the buffer) in that way, to produce a quadrangle which has corners in my four vertices (x1, x2, x3, x4). Then, I just pass it to GLSL and render it.
However, I don't know how to transform a quadrangle to create a new quadrangle with corners in my vertices. Is it possible? Or maybe another idea how to realize this quadrangles?
Additional info:
I am using OpenGL 3.3.
This is how I render points:
for (double lng = 0; lng < 360; lng++) {
for (double lat = 0; lat < 180; lat++) {
draw_dots(MVP, lat, lng);
}
}
// draw_dots function:
glUniform1f(latID, lat);
glUniform1f(lngID, lng);
glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]);
glDrawElements(GL_POINTS, 1, GL_UNSIGNED_INT, field1_location);
This is my vertex shader:
gl_Position = MVP * transl_mtx * vec4(vertexPosition_modelspace, 1);
where transl_mtx is translation matrix calculated from uniform variables "lat" and "lng".