Results 1 to 4 of 4

Thread: OpenGL Texture problem...

  1. #1

    OpenGL Texture problem...

    Hi all,

    Im having a very annoying problem, i have an opengl engine with a texture list class. When i add a texture, all seems to go through ok, and no problems with creating the texture.

    How ever no matter what i do the texture will not bind, all i get is a blank image, i copy the pixels to an sdl surface and save it and the texture is there.

    Below i have included the code i am using:

    Creating the texture:
    [pascal]
    function TXTexture.GLCreate(const Index: Cardinal): Boolean;
    var
    Target: TXTarget;
    W,H: Integer;
    begin
    glGenTextures(1, @Frames[Index].Index);
    Log.Debug('Generating OpenGL texture '''+MClassname+''' ['+InttoStr(ID)+'/'+InttoStr(Frames[Index].Index)+']', 'XTexture');

    H := Propertise.GetInt('height', 0);
    W := Propertise.GetInt('width', 0);

    Target := TXTarget(Propertise.GetInt('target', 1));
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, Frames[Index].Index);

    // gluBuild2DMipmaps(XTarget(Target), 3, W, H, GL_BGR, GL_UNSIGNED_BYTE, Frames[Index].Pixels);
    // gluBuild2DMipmaps(XTarget(Target), GL_BGRA, W, H, GL_BGRA, GL_UNSIGNED_BYTE, Frames[Index].Pixels);
    glTexImage2D(GL_TEXTURE_2D, 0, 3, W, H, 0, GL_BGR, GL_UNSIGNED_BYTE, Frames[Index].Pixels);

    If (Target = xt1D) Or (Target = xt2D) Or (Target = xt3D) Then
    Begin
    // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    // glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    // glTexParameteri(XTarget(Target), GL_TEXTURE_MAG_FILTER, XMagFilter(TXMagFilter(Propertise.GetInt('filter.m ag', 0))));
    // glTexParameteri(XTarget(Target), GL_TEXTURE_MIN_FILTER, XMinFilter(TXMinFilter(Propertise.GetInt('filter.m in', 1))));
    End Else
    Begin
    glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, XMagFilter(TXMagFilter(Propertise.GetInt('filter.m ag', 0))));
    glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, XMinFilter(TXMinFilter(Propertise.GetInt('filter.m in', 0))));
    End;

    Result := (Frames[Index].Index > 0);
    end;
    [/pascal]

    I have changed the code a little to see if i can figure out the problem.

    Bind:
    [pascal]
    Target := TXTarget(Propertise.GetInt('target', 1));
    glEnable(XTarget(Target));
    glBindTexture(XTarget(Target), Frames[0].Index);
    // glBindTexture(XTarget(Target), Frames[Frame].Index);
    [/pascal]

    I have been trying to figure this out for the last 2 days but have not got anywhere.

    Many thanks
    Nic
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  2. #2

    OpenGL Texture problem...

    change:

    Code:
    glTexImage2D&#40;GL_TEXTURE_2D, 0, 3, W, H, 0, GL_BGR, GL_UNSIGNED_BYTE, Frames&#91;Index&#93;.Pixels&#41;;
    to

    Code:
    glTexImage2D&#40;GL_TEXTURE_2D, 0, 3, W, H, 0, GL_BGR, GL_UNSIGNED_BYTE, @Frames&#91;Index&#93;.Pixels&#41;;
    if pixels is array, use:

    Code:
    glTexImage2D&#40;GL_TEXTURE_2D, 0, 3, W, H, 0, GL_BGR, GL_UNSIGNED_BYTE, @Frames&#91;Index&#93;.Pixels&#91;0&#93;&#41;;
    but if it is bind problem, then debug your app with gldebugger.
    This is my game project - Top Down City:
    http://www.pascalgamedevelopment.com...y-Topic-Reboot

    My OpenAL audio wrapper with Intelligent Source Manager to use unlimited:
    http://www.pascalgamedevelopment.com...source+manager

  3. #3

    OpenGL Texture problem...

    The pixels are already stored as a pointer, (PByteArray), i have tried both your suggestions and nothing seems to change.

    I am using SDL to load the image, and then im copying the pixel data from the sdl surface to my own pixel pointer, i have tried using both my pixel data and the sdl surface pixel data in the glTexImage2D but with no effect.

    I will try glDebugger, can you tell me where to get it from?

    Thanks

    Edit:

    I have downloaded gDEBugger from gremedy, and have debugged my program & engine, it seemed the textures are created without a problem (the only problem being they are upside down), so now im even more lost, i can not see where it can be going wrong anywhere :s
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

  4. #4

    OpenGL Texture problem...

    ahh finally figured it out,

    i made a really dumb/stupid mistake..

    It ended up because i was setting the resolution to fit a window, and i was still using some test code that i forgot about, so i replaced it with SDL_SetVideoMode and now all works create

    Thanks again
    M109uk
    <br />--------------------------------------------------------
    <br />www.pulse-soft.oneuk.com

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •