I am trying to determine the display of textures in OpenGL, and I cannot get a simple example to work.
A polygon is drawn, although it is not textured, but a solid color. Also, the bitmap loads correctly in sprite1 [], since I have successfully used glDrawPixels so far.
I use glGenTextures to get my tex name, but I noticed that it does not change texName1; this GLuint is what I initialize, even after calling glGenTextures ...
I have included GL_TEXTURE_2D.
Here is the code:
GLuint texName1 = 0; glGenTextures(1, &texName1); glBindTexture(GL_TEXTURE_2D, texName1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 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_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA_EXT, sprite1[18], sprite1[22], 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, &sprite1[54]); glColor3f(1, 1, 0); glBindTexture(GL_TEXTURE_2D, texName1); glBegin(GL_QUADS); glTexCoord2f (0.0, 0.0); glVertex3f (0.0, 0.0, -5.0f); glTexCoord2f (1.0, 0.0); glVertex3f (.5, 0.0, -5.0f); glTexCoord2f (1.0, 1.0); glVertex3f (.5, .5, -5.0f); glTexCoord2f (0.0, 1.0); glVertex3f (0.0, .5, -5.0f); glEnd();
UPDATE: I'm at a loss. Here is all I tried:
Turns out I initialized my texture before initializing OGL. The texture is initialized (glGenTextures-> glTexImage2D) in the class constructor and is drawn (glBegin-> glEnd) in the member function that is called every frame. genTextures seems to work correctly and I get the name 1.
Every possible combination of GL_RGBA8, GL_BGRA_EXT (GL_BGRA does not work on my system, I need _EXT), and I even removed the alpha channel from the bitmap and tried all the combinations GL_RGB, GL_BGR_EXT, etc. etc. Bad luck.
Tested procedural raster image creation and use of this
Make sure GL_COLOR_MATERIAL is not enabled.
Resized bitmap to 32x32.
Tried glTexEnvi instead of glTexEnvf.