PDA

View Full Version : Display an image array



kaplox
11-14-2008, 04:40 AM
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

trinitrotoluene
11-14-2008, 08:32 AM
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 (http://www.opengl.org/sdk/docs/man/xhtml/glTexImage2D.xml). Look at this tutorial (http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06) 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:


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();

Rosario Leonardi
11-15-2008, 05:40 AM
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.