Results 1 to 9 of 9

Thread: Texture objects?

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2000
    Posts
    10

    Texture objects?

    Iīm trying to write a textureclass/wrapper thing but I canīt get it to work with texture objects. Here is some code:
    class CTextureObject {
    GLubyte texels[64][64][3];
    GLuint name;
    void bind();
    void fix();
    CTextureObject();
    };

    void CTextureObject::CTextureObject()
    {
    glGenTextures(1, &name);
    bind();
    }

    void CTextureObject::bind()
    {
    glBindTexture(GL_TEXTURE_2D, name);
    }

    void CTextureObject::fix()
    {
    bind();
    setTextureParams();
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, texels);
    }

    My idea is to make/load a texture into texels[64][64][3] and then call fix(). Then when I need the texture I just call bind(). But this doesnīt work. When I do this itīs only the last texture fix(ed) that is binded. If I call fix() every time I need a texture all is fine.

  2. #2
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,450

    Re: Texture objects?

    No idea.
    Side note: If you call glGenTextures in a constructor, you should call glDeleteTextures in a destructor.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Aug 2000
    Location
    Ocoee, Florida, USA
    Posts
    150

    Re: Texture objects?

    I had a very similar problem. glGetError() (is that right?) helped me figure out what I was doing wrong. You cant call Bind() within glBegin()/glEnd() Check to make sure you aren't doing this.

  4. #4
    Junior Member Newbie
    Join Date
    Dec 2000
    Posts
    10

    Re: Texture objects?

    Relic: Thanks for that, I always forget to clean up my mess
    BwB: I did as you suggested but there was no GL_ERROR. Thanks anyway.

    Anyone else? Please

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Oct 2000
    Location
    Fargo, ND
    Posts
    1,753

    Re: Texture objects?

    When are your objects created? If you try and use gl* calls before you've created a window with a valid pixelformat, they won't work. So for instance if you did something like so...

    CTextureObject g_object; // Global object
    // object will be created
    // and try to use gl* calls
    // when program is first started

    void main()
    {
    // ... glut init stuff
    glutCreateWindow(); // Window won't be created until here
    // so any GL calls prior to this
    // (Such as your constructor in the global object)
    // will have failed
    }
    Deiussum
    Software Engineer and OpenGL enthusiast

  6. #6
    Junior Member Newbie
    Join Date
    Dec 2000
    Posts
    10

    Re: Texture objects?

    Thank you!

  7. #7
    Guest

    Re: Texture objects?

    You must suply Mag nad Mig filters to current texture.

  8. #8
    Senior Member Frequent Contributor
    Join Date
    Feb 2000
    Location
    London
    Posts
    503

    Re: Texture objects?

    I think Deiussum solved your problem, right?

    Side note: avoid using the multi-dimensional

    Code :
    GLubyte texels[64][64][3];
    notation when specifying bitmap data. Some compilers (including some versions of MSVC in Debug mode IIRC) allocate extra "guard bytes" before and after array storage in order to detect out-of-range pointer errors, which means that you'll get junk after each line and possibly after each pixel and your texure will wind up looking corrupted. Use a one dimensional array instead, i.e.

    Code :
    GLubyte texels[64*64*3];


    [This message has been edited by MikeC (edited 03-19-2001).]

  9. #9
    Senior Member Regular Contributor
    Join Date
    Apr 2000
    Location
    Redlands, CA, USA
    Posts
    233

    Re: Texture objects?

    Originally posted by MikeC:
    Side note: avoid using the multi-dimensional

    Code :
    GLubyte texels[64][64][3];
    notation when specifying bitmap data. Some compilers (including some versions of MSVC in Debug mode IIRC) allocate extra "guard bytes" before and after array storage in order to detect out-of-range pointer errors, which means that you'll get junk after each line and possibly after each pixel and your texure will wind up looking corrupted. Use a one dimensional array instead, i.e.

    Code :
    GLubyte texels[64*64*3];
    Pardon me, but it is just pure nonsense.
    And if you can prove otherwise - well, than maybe Earth is flat after all...

    btw, memory manager in the debug version of the run-time library usually uses special "guard" blocks before and after each memory block allocated by new/malloc.
    It has nothing to do with structure/array packing, and doesn't matter from C & C++ standards point of view.

Similar Threads

  1. Texture manager (always ready texture objects)
    By endrelidal in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 08-15-2005, 02:26 AM
  2. Sharing texture objects and buffer objects
    By Paul Martz in forum OpenGL: Windows
    Replies: 7
    Last Post: 06-11-2005, 07:37 PM
  3. Texture Objects and texture management
    By alh in forum OpenGL ES
    Replies: 4
    Last Post: 02-13-2005, 02:19 PM
  4. TEXTURE OBJECTS
    By mwanderson in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 05-29-2001, 01:33 AM
  5. how can i put texture on several objects?...
    By Kondrat in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-15-2001, 12:27 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