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.

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

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.

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

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
}

Thank you!

You must suply Mag nad Mig filters to current texture.

I think Deiussum solved your problem, right?

Side note: avoid using the multi-dimensional

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.

GLubyte texels[64643];

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

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

[quote]

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.

GLubyte texels[64643];

[/b][/QUOTE]

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.