Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: How to output a ".tiff" image in 3d mesh in OpenGL.

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2018
    Posts
    5

    How to output a ".tiff" image in 3d mesh in OpenGL.

    Code cpp:
    for (int i = 0; i < height; i++)
        {
            for (int j = 0; j < width; j++)
            {
                glVertex3f(x_pos[j], y_pos[i], z);
                glColor3ub(image_p[k + 2], image_p[k + 1], image_p[k]);
                k++;
            }
        }

    I randomly put the height value (z value).
    However, it does not form a 3d mesh on the screen.
    How do you convert an imported image to a 3d mesh?
    please help me
    Thank you
    Last edited by Dark Photon; 12-04-2018 at 05:20 AM.

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,569
    In this old, deprecated method of sending vertices to the GPU (called OpenGL immediate mode), for each vertex, you set all vertex attributes besides position first (e.g. glColor*()), and then register the vertex position (glVertex*()). That latches all of the registered vertex attributes for that vertex and gets ready for the next vertex.

    In other words, swap your glVertex3f() and glColor3ub() lines.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2018
    Posts
    5
    Thank you very much
    Should I use a triple for statement to form a mesh with z values?
    ex)
    for (int x = 0; x < height; x++)
    {
    for (int y = 0; y < width; y++)
    {
    for (int z = 0; z < width; z++)
    {
    }
    }
    }
    Last edited by Hurricane_RusH; 12-04-2018 at 06:18 PM.

  4. #4
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,971
    No, you would just feed vertex z with your height data. Another a loop would be for volumetric data not a surface with height. Using your approach to draw an image is massively inefficient and is what you might call "micropolygons", I used this technique before texture hardware was a thing, but for your needs you could draw one quad with a single texture applied to it instead of per vertex coloring and a vertex for each image sample.

  5. #5
    Super Moderator OpenGL Guru dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,971
    To draw a mesh you must also input a series of points in an order suited to the primitive type you intend to draw. For GL_POINTS you would just touch every vertex once, for a surface you need to issue the points to create a triangle that fills the space between points. w*h is not enough, and for a GL_TRIANGLE_STRIP for example you need to issue 2 vertices for each triangle, spanning outer_loop increment to outer_loop+1. Then handle the switch back to inner loop reset either with degenerates or primitive input restart (a new glBegin).

    This makes it usefully clear:

    http://www.learnopengles.com/tag/triangle-strips/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •