Texture mapping and display from a float image array

Hi everybody!

Sorry if this topic has been discussed previously on the web, but I have been looking for examples on the forum an internet and I have not found anything :frowning:
I have a question relative to the use of glTexture2D(…).

I have a float array which contains the value (only a single value) of a image pixel. Nowadays I display it using OpenGL primitives but it is slow, so I want to display it using Texture mapping and grayscale. But the problem is that anytime I try to use it I get nothing (blank screen).

This is what I do, hope anybody can help me because I am a beginner :slight_smile:

  1. Generate texture, textureID is defined as GLuint in init() method

glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
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_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

  1. Enable texture and draw using Texture2D in paint() method. myImage is defined as float* and is obtained after some calculus every time using calculateMyImage() function


calculateMyImage(myImage);


glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,textureID);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, tamx, tamz, 0, GL_LUMINANCE, GL_FLOAT, myImage);
    
glBegin(GL_QUADS);
    glTexCoord2f(1.0f,1.0f); glVertex3f(-1.0f, 1.0f, 1.0f);
    glTexCoord2f(1.0f,0.0f); glVertex3f( 1.0f, 1.0f, 1.0f);
    glTexCoord2f(0.0f,0.0f); glVertex3f( 1.0f, 1.0f,-1.0f);
    glTexCoord2f(0.0f,1.0f); glVertex3f(-1.0f, 1.0f,-1.0f);
glEnd();

glDisable(GL_TEXTURE_2D);

That’s it, what I am doing wrong? Can anybody help me?
Thank you very much in advance :slight_smile:

David

We may have to write some tutorials here for old OpenGL since it seems to be very common for people to omit certain important function calls.
For example, if lighting is disabled, be sure to set your color with glColor4f or glColor4ub or one of those other glColor calls.
For your texture, you should set the texture environment combiners with a call to glTexEnv.
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE)

Anyway, those are the defaults for GL, so I’ll assume the problem is elsewhere.
If you disable texturing, does a white quad appear on screen?

Thank you V-man for the fast reply.
I have set the texture with TextEnvi as you suggest me. If I disable texturing nothing happens and I still get a black screen (I have set default bakground color to black). Any ideas? Is it the code correct?

Anyway, you refered the code above as old OpenGL…how do you use new OpenGL methods for displaying a float array image using textures? The procedure is quite different? Sorry for my newness.

Thank you very much!!!
David

For rendering a fullscreen quad


glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glColor4f(1.0, 1.0, 1.0, 1.0);
and render a quad with vertices
{-1.0, -1.0, 0.0}, {1.0, -1.0, 0.0}, {1.0, 1.0, 0.0}, {-1.0, 1.0, 0.0}
and you should have a fullscreen quad on screen

glutSwapBuffers();

As for old GL vs new GL
http://www.opengl.org/wiki/Legacy_OpenGL

Deleted, I was too late :slight_smile:

Thank very much but I am not able to get it working.

I tried at first using glDrawPixels(…) in this way


glDrawPixels(myImage.width, myImage.height, GL_LUMINANCE, GL_FLOAT, myFloatArray);

and it works, but I have read it is an obsolete function and it’s much better to use glTexImage2D instead…hope anyone can guess what is going wrong…

Thank you in advance!
David

It looks to me that you are drawing a quad in the (X,Z) plane (Y is constant == 1) without setting properly the modelview transformation.
This is why you don’t see anything - the quad is there but you are not “looking” at it.

Start from V-man’s post where he tells you how to set the projection, modelview and gives you the proper quad corners to draw. You will obtain a white quad covering your viewport.

After that you may add the texture coordinates.