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