View Full Version : total newb problems with texturing

01-03-2012, 02:10 AM
hey guys, I'm writing a beginner program which uses an ADT to draw a textured polygon in a 2d plane, but whenever i try to draw, the texture appears as pure black.

I've been searching for a few hours and i can't figure out what my problem is, nor any hints from people having had a similar problem. As far as i can tell i'm loading and using the texture correctly, but perhaps there is something i've missed.

the most important parts should be that i do
these things (http://pastebin.com/84HWFJUD)
in order

my texture is 128x128 pixels and the vertex/uv arrays are squares between -0.5 and 0.5

here is my code in more detail:
my ADT (http://pastebin.com/CmA2h4pf)

loadBMP function (http://pastebin.com/wrHUWKJf)

drawModel function (http://pastebin.com/pjQfAZws)

my shaders (http://pastebin.com/QYrNasZY)

nb: i am using a slightly unorthodox shader where positions are vec2 to use bandwidth more efficiently, since everything is drawn in a 2d plane with z = 0, this shouldn't really affect anything substantial

01-03-2012, 05:25 AM
Looks like you forgot to generate the mipmaps for your texture,

try calling this when texture is loaded :
glGenerateMipmap(GL_TEXTURE_2D); //Generate mipmaps now!!!

01-03-2012, 06:46 AM
I put that line in, but nothing changed. I also added in all the relevant glTexParameteri and preceeded it with glenable(GL_TEXTURE_2D).

the wiki page states that glgeneratemipmap has no effect on some ATI drivers(i have an an ATI), but I've had success texturing things before, so i think that is probably not the issue.

01-03-2012, 06:52 AM
Have you tried disabling mipmaps, to be sure ? GL_LINEAR for GL_MIN

01-03-2012, 07:13 AM
yep, to no avail=[

Captain Code
01-04-2012, 01:10 PM
What debugging steps have you done:

E.g. Have you tried outputting a solid colour instead of the texture - in the shader code. Just to check this works as expected.
Have you tried printing your texture coordinates to the screen/file to ensure they are valid.
Have you tried querying the GLSL attributes to check they have valid values - it they match the shader source code.
Have you double checked your texture loading is correct.

01-05-2012, 05:56 PM
i have tried displaying a solid color in the shader code, it works as expected

i have tried printing the texture coordinates to screen, they seem fine

i dont know what you mean by querying glsl attributes, like i say i'm extremely new to this, but everything seems in order, and wouldn't it cause a run time error if there was any kind of mismatch?

I have double and triple checked my texture loading, the function i use at the moment is taken directly from an online tutorial and i have used it successfully in the past to texture a cube in a different program.

after i added in those extra parameters i think i'm making progress because now instead of plain black i'm seeing this:

do glsl uniforms default to zero? is that driver dependant?
I seem to get this result whether or not i set the "Texture" uniform to zero myself.

01-06-2012, 01:09 AM
I had the same kind of texture mapping going just yesterday. It turned out that I was reading the data from the texture file incorrectly. I had and offset of 1 byte and it messed everything up. Is the current BMP you are using one of the ones that worked previously ?

01-07-2012, 06:41 PM
it did work previously but it must have been altered in some way.
I have determined that the test:

if ( *(int*)&(header[0x1C])!=24 ) {
printf("Not a correct BMP file\n");
return 0;

fails even though i have saved and resaved the bitmap and specified 24bpp each time. All the same, header[0x1c] stays as 32.

loading it as a 32bpp bitmap and dropping the alpha bits when i buffer it into graphics memory fixes my problem=D
turns out that function i downloaded (and the original one i wrote) assumes all bitmaps are 24 bpp, i shall fix this when i write my own function in a few minutes=D

thanks for all your help, guys, rapzophs comment about one byte offsets ultimately led me to the solution, it seems so obvious now=p