PDA

View Full Version : Texture objects?



qonjure
03-19-2001, 06:48 AM
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.

Relic
03-19-2001, 07:59 AM
No idea.
Side note: If you call glGenTextures in a constructor, you should call glDeleteTextures in a destructor.

BwB
03-19-2001, 08:46 AM
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.

qonjure
03-19-2001, 09:31 AM
Relic: Thanks for that, I always forget to clean up my mess http://www.opengl.org/discussion_boards/ubb/biggrin.gif
BwB: I did as you suggested but there was no GL_ERROR. Thanks anyway.

Anyone else? Please http://www.opengl.org/discussion_boards/ubb/wink.gif

Deiussum
03-19-2001, 12:34 PM
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
}

qonjure
03-19-2001, 12:47 PM
Thank you! http://www.opengl.org/discussion_boards/ubb/biggrin.gif

03-19-2001, 12:48 PM
You must suply Mag nad Mig filters to current texture.

MikeC
03-19-2001, 04:35 PM
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[64*64*3];




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

Serge K
03-23-2001, 09:22 PM
Originally posted by MikeC:
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[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.