I'm trying to map a generated 2D texture on a quad. So far the quad is rendered, but it is gray if I don't set a color and if I set colors for the vertices it shows the colors, yet the texture is not shown.
The reason for using fixed pipeline instead of shaders is that in order to generate the texture I would have to pass too much data to the shaders to generate the texture efficiently. So ideally I do not want to have a shader for something that should be as simple as rendering a texture on a quad. Although the program uses shaders extensively.
I tried using GLubyte for passing the data to glTexImage2D but got the same result. Also I tried various positions to call glEnable(GL_TEXTURE_2D), glBindTexture, glTexParameteri and glTexImage2D. Furthermore, I commented glTexEnvf, glBindTexture (unbinding), glDisable(GL_TEXTURE_2D) and glDeleteTextures(...). All with the same result.
Maybe it is not possible to use fixed pipeline texture rendering in a program that also uses shaders? Or did I make a mistake in my code? As far as I can see and according to Google the code below should render the texture on the quad. It is bugging me for a few days nows and probably it is a simple mistake...
glGetError returns 0 at all positions in the snippet.
std::cout<<glGetError()<<std::endl;
GLuint texName;
glGenTextures(1, &texName);
glBindTexture(GL_TEXTURE_2D, texName);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
std::cout<<glGetError()<<std::endl;
GLfloat image[64][64][4];
for(unsigned int i = 0; i<64; i++)
{
for(unsigned int j = 0; j<64; j++)
{
image[i][j][0] = 1.0f;
image[i][j][1] = 0.5f;
image[i][j][2] = (float)i/64;
image[i][j][3] = 1.0f;
}
}
std::cout<<glGetError()<<std::endl;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64,
64, 0, GL_RGBA, GL_FLOAT,
image);
std::cout<<glGetError()<<std::endl;
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
glBindTexture(GL_TEXTURE_2D, texName);
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(10, 10);
glTexCoord2f(0, 1); glVertex2i(10, 110);
glTexCoord2f(1, 1); glVertex2i(110, 110);
glTexCoord2f(1, 0); glVertex2i(110, 10);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
glDeleteTextures(1, &texName);
std::cout<<glGetError()<<std::endl;