   texture2D returning black, no matter what
  Hello,I am deeply troubled by this. I have a program that I'm writing that is only supposed to do one thing: display a textured quad (comprised of two triangles). I'm loading the bmp file myself, and I'm using shaders written in GLSL. However, the quad is rendering completely in black.Here are the steps I'm following during initialization:1. I generate the texture name using glGenTextures2. I call glBindTexture, passing in GL_TEXTURE_2D and the texture name3. I set the image data (loaded from a bmp file) using glTexImage2DThat's it for setting up the texture. Now, to init the shaders:4. I create the vertex & fragment shader objects using glCreateShader5. I create the shader program object using glCreateProgram6. I set the source code for each using glShaderSource7. I compile each using glCompileShader8. I attach each to the program using glAttachShader9. I link the program using glLinkProgram10. I fetch the sample2D uniform location using glGetUniformLocationAlso keep in mind that, after compiling each shader, I fetch it's compile status and, if it's no GL_TRUE, I fetch the info log to read any errors. My shaders, as they currently are, have no compile errors.Here is the source for my vertex shader:void main(void){gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;gl_TexCoord[0] = gl_MultiTexCoord0;}And here is the source for my fragment shader:uniform sampler2D textureA;void main(void){gl_FragColor = texture2D(textureA, gl_TexCoord[0].st);}Here is what my draw function looks like:void MyClass::Draw(){glBindBuffer(GL_ARRAY_BUFFER, m_vboName);glEnableClientState(GL_VERTEX_ARRAY);glEnableClientState(GL_TEXTURE_COORD_ARRAY);glVertexPointer(3, GL_FLOAT, 5*sizeof(float), 0);glTexCoordPointer(2, GL_FLOAT, 5*sizeof(float), (GLvoid*)(3*sizeof(float)));glUseProgram(m_shaderProgramName);// Set the textureglActiveTexture(GL_TEXTURE0);glBindTexture(GL_TEXTURE_2D, m_textureName);glUniform1i(m_textureSamplerUniformLocation, 0);glDrawArrays(GL_TRIANGLES, 0, 6);glDisableClientState(GL_VERTEX_ARRAY);glDisableClientState(GL_TEXTURE_COORD_ARRAY);glBindBuffer(GL_ARRAY_BUFFER, 0);}Here are some things I've tried:A. I thought perhaps that something about my fragment shader was silently failing. To test this, I hard coded a statement assigning gl_FragColor to vec4(1.0, 0.0, 0.0, 1.0), which should result in a red quad. Indeed it did, so I concluded that my shader program was at least running.B. I wasn't sure if the texture coordinates were coming across correctly, so I modified the fragment shader as follows:uniform sampler2D textureA;void main(void){gl_FragColor = vec4(gl_TexCoord[0].st, 0.0, 1.0);}If the texture coordinates are correct, I would expect that the corner of my quad that has texture coordinates of (0,0) would be black; the corner with coordinates (1,0) would be red; the corner with coordinates (0,1) would be green; and the corner with coords (1,1) would be yellow. The colors in the middle of the quad would be interpolated from these corners. I've tested this, and this is indeed what I see, so it seems to me that the texture coordinates are coming across fine.For good measure, I hard-coded the coordinates at 0.5, 0.5. There are no black pixels in my texture image, so this should result in a non-black quad. However, the quad is still black. I tried several other hard-coded texture coordinates, all with the same result.C. So, I thought, maybe there is something wrong with my data. This is the first time that I am loading my BMP from file, after all. I set a break point at glTexImage2D to see the data going in. It definitely was no zero. I then added a call to glGetError directly after glTexImage2D, to see if there were any errors. There weren't any.So, as a last resort, I ditched the BMP loading and went with some hard-coded values. Here is that section of code:GLubyte texData[12] = {255, 0, 0,0, 255, 0,0, 0, 255,0, 0, 0};glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)texData);Again, no errors, and my quad is completely black.D. In the above call to glTexImage2D, I tried using various other values for the third parameter: 3, 4, GL_RGB, and GL_RGBA. No change.E. I double-checked the uniform name I'm passing in to glGetUniformLocation, and then triple-checked it. It seems to find the uniform just fine. Otherwise, it would return a -1, according to the OpenGL docs, but instead it returns a correct value of 0 (it being the only uniform in my program).I feel like I've exhausted all possibilities! Any ideas?   
  Wow you certainly were thorough :), sorry you're still having problems.Have you tried just rendering your texture through immediate mode to see if it displays properly? It seems like this could come down to being either a texture problem or a shader/sampler problem, and an immediate mode test should be able to narrow that down a bit.Everything looks fine just at a glance, I don't have my own code in front of me to reference though so I could be mistaken.   ;  It seems that I've forgotten to set the Min and Mag filters. Funny enough ... I didn't think that mattered. I thought it would just default to something, like NEAREST, perhaps. I guess not, though. If I set the parameter (doesn't seem to matter what ... nearest, linear, etc.), then my quad shows up. Otherwise, it doesn't.Now I'm having trouble with the colors, though. Maybe I should make a new thread? Anyway, I'll just ask it here. It seems as though glTexImage2D is doing something unexpected with the data that I supply to it.Consider this example:GLubyte texData[12] = {255, 0, 0, 0, 255, 0, 0, 0, 255, 0, 0, 0, };glTexImage2D(GL_TEXTURE_2D, 0, 3, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)texData);As you can see, I'm trying to specify a 2x2 RGB texture. The pixel colors (see my array) are red, green, blue, and black. However, this is not how the texture shows up when mapped to my object at runtime. Instead, the first two texels seem correct (showing red and green, respectively), but the last two are incorrect. Instead of blue and black, I see red (again) and then a washed-out turquoise. I can get it to show different colors simply by changing the dimensions of the texture. If I make it a 1x4 texture, then only the first texel is correct (red). The next two are red as well, and the last one is a light gray!If I make it a 4x1 texture -- again using the same data array -- the image looks correct!I experimented with different array sizes (because I suspect that in some of the examples, it is reading data outside my array). What I've found is this. Even though it correctly offsets by 3 bytes for each pixel within a row, when it comes to calculating an offset for the row itself, it assumes the pixels are 4 bytes each!So, the first row of pixels will always be correct. That's why the first 2 pixels in my 2x2 texture were correct, and the first pixel in my 1x4 texture was correct, and all the pixels in my 4x1 texture were correct!Note that the data array is flat. So, when it comes to calculating which element index corresponds to a certain x/y pixel, one would have to use the formula: y*row_offset+x*bytes_per_pixelAccording to my (obviously flawed) understanding, row_offset should be: width*bytes_per_pixelAnd bytes_per_pixel is 3 in my case.However, the way it is behaving is strange (to me, at least). For the purposes of the first formula, it correctly uses a bytes_per_pixel value of 3. But for the purposes of the row_offset sub-formula, it assumes a bytes_per_pixel value of 4. I've checked the math, and that is what it seems to be doing.   ;  You have to set the min filter because it defaults to GL_NEAREST_MIPMAP_LINEAR, and if you haven't generated mipmaps then it doesn't work. I've always found it to be a strange choice but its just something you learn to live with.For your color issues, you might want to read this:Avoiding 16 Common OpenGL PitfallsScroll down to "7. Watch Your Pixel Store Alignment" and see if that sounds right. I've never run into a situation where I've had this issue, and this might be related to your problem, but I've never used it.Quote:"By default, adjacent pixels are taken from adjacent memory locations, except that after all width pixels are read, the read pointer is advanced to the next four-byte boundary. The four-byte row alignment is specified by glPixelStore  with argument GL_UNPACK_ALIGNMENT, and it can be set to one, two, four, or eight bytes.Alternatively, just change your array to be 4 bytes per pixel and set the A to 1, see if that fixes the issue.;  just guessin, but i have had a similar error before with colors.If youre using windows, try GL_BGR as your color format, cause windows seems to use this layout instead of RGB...I hope this help you   ;  Thanks, guys. I was able to change the pack alignment (thanks karwosts), and the colors were still off. Juanxo's suggestion would have fixed it, but I already did the work of reversing the component order in my BMP loader hahahahaha.   