开发者

surface area calculation

I use glDrawArrays(GL_POINTS,...) to draw harmonic wave. I would like to know the order in which the surfaces (triangles?) are generated by openGL while rendering based on the vertices and in such a way calculate the surface 开发者_如何学运维area? Can I do it and if yes how.


I will try to explain it better

I have 2D array of values and perform uv-mapping on it.( i generate harmonic wave) and draw the surface accepted using glDrawArrays. I want to calculate the surface area,which i visualize. I think I should "translate" the problem to be easier for such calculation by creating a grid of triangles , which is suitable for points drawing - this will simplify my calculation.


I use glDrawArrays(GL_POINTS,...) to draw harmonic wave.

Points have no surface.

I would like to know the order in which the surfaces (triangles?) are generated by openGL while rendering based on the vertices and in such a way calculate the surface area? Can I do it and if yes how.

OpenGL doesn't generate traiangles. It rasterizes the triangles you send it. In the very same order in which you specify them. glDrawArrays(mode, first, count) behaves exactly like

myDrawArrays(GLenum mode, GLuint first, GLuint count)
{
    GLuint *indices = malloc(count * sizeof(GLuint));
    /* just assume malloc never fails, OpenGL doesn't have to alloc here, of course) */
    for(int i=0; i<count; i++)
        indices[i] = first + i;
    glDrawElements(mode, count, GL_UNSIGNED_INT, indices);
    free(indices);
}

The primitives are rasterized in the order they are specified.

So you want to know a surface area, but are drawing points. As already told, points (mathematically) have no surface. However they cover at least one (sub-)pixel. So could it be that you actually want to know the pixel coverage?

Then OpenGL provides you a method called "occlusion query" using which it returns you, how many (screen/framebuffer) pixels got touched by drawing the primitives within the query.

http://www.opengl.org/registry/specs/ARB/occlusion_query.txt


The geometry shading stage contains the information about drawn polygon, so you can calculate the surface amount from there. In order to get the sum of it you can render into 1x1 R_32F framebuffer object with additive blending, then read the value into system memory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜