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 3 of 3

Thread: Display an image array

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2008
    Posts
    4

    Display an image array

    Hello,

    I'm new in OpenGL, so I'm sorry if I ask you in an inappropiate way. I want to draw an image using opengl. My image is calculated and stored in an 1D float array and each position is a pixel and contains a value which determines the colour of this pixel. Once the image is calculated I need to draw it in the screen. Do you know what is the best way to put it in the screen? I don't know if I need to use textures or vertex buffer objects or something else or just use the opengl primitives like glVertex, etc... , so I'm confused about it and I hope you can help me. If you need more details, here I am.
    Thanks you very much.

    Greetings

  2. #2
    Member Regular Contributor trinitrotoluene's Avatar
    Join Date
    Sep 2008
    Location
    Montérégie,Québec
    Posts
    362

    Re: Display an image array

    Do your 1D float array contain data of a 2d image? When you retrieve a pixel value you use something like that: color = array[x +y*image_width]. In this case you can generate a 2d texture. Look at this tutorial on nehe web site for more information. Beware that in this tutorial the type of the texture data is GL_UNSIGNED_BYTE so you will have to change that parameter for floating point numbers. After reading the tutorial,my advise here is try to put a custom made (GLubyte data format) 2x2 texture on a quad like this one:
    Code :
    glBegin(GL_TRIANGLE_STRIP);
    glTexCoord2f(0.0,0.0);
    glVertex3f(-1.0,-1.0,0.0);
    glTexCoord2f(1.0,0.0);
    glVertex3f(1.0,-1.0,0.0);
    glTexCoord2f(0.0,1.0);
    glVertex3f(-1.0,1.0,0.0);
    glTexCoord2f(1.0,1.0);
    glVertex3f(1.0,1.0,0.0);
    glEnd();

  3. #3
    Member Regular Contributor Rosario Leonardi's Avatar
    Join Date
    Aug 2008
    Location
    Italy
    Posts
    356

    Re: Display an image array

    Also take care that if you don't use advanced technique like tone mapping your float array should contain number between zero and one or the values will be clamped.
    ~ ~ I tell you, realtime 3D is made of blood, sweat and screams! ~ ~

Posting Permissions

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