displaying an image from an array of values

Hi everyone,

I really hope someone here can help me and would greatly appreciate it. I have calculated an array of unsigned char values and i need to display them on my blank opengl window (which i created in wxwidgets using wxGLcanvas).

Each unsigned char value is supposed to be the greyscale intensity of a pixel. i am trying to create an image of 500x500 pixels with this unsigned char array.

this will really make a big difference to me. thanks very much.

If you wish to use a full screen quad in an ortho mode you can use something like this:

Texture init code


 glPixelStorei(GL_UNPACK_ALIGNMENT,1);
  glGenTextures(1,&texture_id);
  glBindTexture(GL_TEXTURE_2D,texture_id);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  glTexEnvf(GL_TEXTURE_2D,GL_TEXTURE_ENV_MODE,GL_REPLACE);

//Change parameters to fit your need  glTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE,image_width,image_height,0,GL_LUMINANCE,GL_UNSIGNED_BYTE,data);

Drawing code:


  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D,texture_id);
  glBegin(GL_TRIANGLE_STRIP);
  glTexCoord2f(0.0,0.0);
  glVertex2i(0,0);
  glTexCoord2f(1.0,0.0);
  glVertex2i(viewport_width,0);
  glTexCoord2f(0.0,1.0);
  glVertex2i(0,viewport_height);
  glTexCoord2f(1.0,1.0);
  glVertex2i(viewport_width,viewport_height); 
  glEnd();
  glDisable(GL_TEXTURE_2D);

Reshape code:


 glViewport (0, 0, (GLsizei) viewport_width, (GLsizei)viewport_height);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(0,viewport_width,0,viewport_height, -1.0, 1.0);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

Keep in mind that your texture is not power of two so you may have to change the texture target for the glTexImage2D and the texture coordinates of glTexCoord2f. If the image appear upside down change the order of parameters for glOrtho. The parameter that I give you place 0,0 at bottom left. If you want top left use glOrtho(0,viewport_width,viewport_height,0, -1.0, 1.0);.The other choice is to use glDrawPixels.

Hope that help.