Skip to main content
gamedev.net
🔒 Locked

Texture object

Started by Silverclaw Apr 27, 2006 at 1:33 PM 3 replies 1k views
Original Post
Silverclaw
Silverclaw
I created a class that loads an object when initiated, like this:

class texture
{
public:
texture(filename);
~texture(void);
private:
void loadtga(void);
void loadbmp(void);
GLuint id;
}

The texture's ID (internal number used by OpenGL) is stored, obviously, in private member ID. I could make it public yes, but my point is I want to use the ID directly, like this: texture tex("mytexture.bmp"); glBindTexture(tex); without resorting to methods nor member designation (like tex.returnID or tex.ID). I though about overloading the unsigned int operator, but I don't know if it'll work. Thanks in advance.
Education is the progressive discovery of our own ignorance.
cwhite
cwhite
"unsigned int" is a type, not an operator, and as such, I don't think you can override it. C/C++ have a lot of black magic in them, so maybe there's some funky way you can do it, but it really doesn't make sense. The only way I think you could do it is to override the glBindTexture() function as follows:

void glBindTexture(Texture tex){     glBindTexture(tex.id);}


However, that's just gonna add extra function call overhead, and I'm not sure why anybody would want to do what you're trying to do.
Silverclaw
Silverclaw
Quote:
I'm not sure why anybody would want to do what you're trying to do.

I made an object to simplify texture loading and discard (destructor does the cleanup).

I peeked at the class to see how it's done, but the code is rather obscure. Btw, type operators CAN be overloaded, I just don't know it they'll work... If anyone has an idea how to return the ID by a call to the objects name, be kind enough to post :P thanks!
Education is the progressive discovery of our own ignorance.
oggialli
oggialli
Actually, you can overload conversion operators. Like operator unsigned int() {return id;} in this case. And it will work.

Edit: cwhite, and no, you can't overload C-linkage functions (which gl* obviously are). So that won't compile.
Olli Salli
Silverclaw
Silverclaw
Thanks oggialli, that should solve my problem. One more thing. Is my texture object approach viable? I'd rather do it this way to simplify code (and maybe put this class available). Also, I used display lists to create a font. When I compile my display lists, do I still need the texture, or can I safely remove it?
Education is the progressive discovery of our own ignorance.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.