Results 1 to 9 of 9

Thread: total newb problems with texturing

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2011
    Location
    Australia
    Posts
    5

    total newb problems with texturing

    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
    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

    loadBMP function

    drawModel function

    my shaders

    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

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: total newb problems with texturing

    http://www.opengl.org/wiki/Common_Mi...ting_a_Texture
    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!!!

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2011
    Location
    Australia
    Posts
    5

    Re: total newb problems with texturing

    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.

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: total newb problems with texturing

    Have you tried disabling mipmaps, to be sure ? GL_LINEAR for GL_MIN

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2011
    Location
    Australia
    Posts
    5

    Re: total newb problems with texturing

    yep, to no avail=[

  6. #6
    Junior Member Newbie
    Join Date
    Jan 2012
    Posts
    7

    Re: total newb problems with texturing

    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.

  7. #7
    Junior Member Newbie
    Join Date
    Dec 2011
    Location
    Australia
    Posts
    5

    Re: total newb problems with texturing

    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.

  8. #8
    Junior Member Newbie
    Join Date
    Dec 2009
    Posts
    12

    Re: total newb problems with texturing

    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 ?

  9. #9
    Junior Member Newbie
    Join Date
    Dec 2011
    Location
    Australia
    Posts
    5

    Re: total newb problems with texturing

    it did work previously but it must have been altered in some way.
    I have determined that the test:

    Code :
     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

Similar Threads

  1. simple texturing problems
    By marty_arts in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-16-2006, 12:13 PM
  2. texturing problems
    By d-monster in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 11-23-2005, 05:48 PM
  3. Texturing problems;
    By LordOfTheUniverse in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 12-03-2002, 02:39 PM
  4. Problems with Multi-Texturing
    By Xero_Tolerance in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-14-2002, 02:22 AM
  5. Texturing problems
    By King Fuzzy in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 08-22-2001, 11:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean