Thread: Textures not setting properly.

  1. #1
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071

    Textures not setting properly.

    I'd swear that I had this fixed before, but appearently not. Or maybe it was fixed, and I somehow broke it again. Either way, I can't figure out how to fix it this time.

    I have a texture class and a texture manager class (CTexture and CTextureManager respectivly) that I use for creating and applying textures in my engine.

    The problem is, that all my objects will only use the texture that was loaded last, regardless of the ID I set (you'll see how this is done in the code below).

    CTexture:
    PHP Code:
                public ref class CTexture{
                public:
                    
    String ^name;
                    
    int ilImageName;
                    
    unsigned int id;
                    
    TEX_TYPE type;
                    
    TEX_FORMAT format;

                public:
                    
    CTexture(String ^fileTEX_TYPE typeTEX_FORMAT format);
                    ~
    CTexture(){
                        
    CUtility::Log("Deleted texture '"+name+"'");
                    }
                }; 
    CTextureManager:
    PHP Code:
                public ref class CTextureManager{
                public:
                    static 
    unsigned int numTextures;
                    static array<
    CTexture^> ^textures;

                public:
                    
    CTextureManager(){
                        
    numTextures 0;
                        
    textures gcnew array<CTexture^>(MAX_TEXTURES);
                    }
                    ~
    CTextureManager(){
                        
    CUtility::Log("Killed texture manager.");
                    }

                    
    void NewTexture(String ^fileTEX_TYPE typeTEX_FORMAT format);
                    
    void SetTexture(CTexture ^texTEX_UNIT unit);
                }; 
    Those were the class defs. Here are the functions (i'm going to leave out the code for actually creating the texture (CTexture's constructor), to avoid making this post too long. I'm 99% sure that much is correct anyway).

    NewTexture and SetTexture:
    PHP Code:
    void CTextureManager::NewTexture(String ^fileTEX_TYPE typeTEX_FORMAT format){
        
    textures[numTextures] = gcnew CTexture(filetypeformat);
        
    CUtility::Log("Created texture '"+file+"'");
        
    numTextures++;
    }

    void CTextureManager::SetTexture(CTexture ^texTEX_UNIT unit){
        
    Gl::glActiveTexture(unit);
        
    Gl::glEnable(tex->type);
        
    Gl::glBindTexture(tex->typetex->id);

    Now, all I should have to do to create a texture for an object is do this:
    PHP Code:
                    this->texID[0] = CGfxCtrl::texManager->numTextures;
                    
    CGfxCtrl::texManager->NewTexture(texture_2DRGB8); 
    And set the texture like this:
    PHP Code:
    CGfxCtrl::texManager->SetTexture(CGfxCtrl::texManager->textures[obj->texID[0]], UNIT0); 
    before drawing.

    I can't figure out why this won't work, but perhaps one of you can .

    Thanks.
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  2. #2
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Hmm. Someone seems to have massacred your code. That's not C++... surely?
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    2
    As far as I can tell (at least from the supplied code), you never set the CTexture's "id" variable to it's index into the "textures" array.

  4. #4
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    The id variable in CTexture is the OpenGL texture id, set by glGenTextures. It's not used as an array index ID.

    For example, in the CTexture constructor:
    PHP Code:
    glGenTextures(1this->id);
    glBindTexture(GL_TEXTURE_2Dthis->id); 
    This binds the texture information to that id, to be used in SetTexture().

    @ahluka: I was going to include a warning with my post, but I decided it would be more amusing for me to watch your reactions to the sight of unstandard code.
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  5. #5
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    *sighs*

    Nevermind, and sorry for pulling the alarm early on this one. The problem had nothing to do with the texturing code. The problem was that SetTexture wasn't being called in my rendering code due to a typo (wrote ">" instead of ">=" when I checked to see if the object had any materials).
    M.Eng Computer Engineering Candidate
    B.Sc Computer Science

    Robotics and graphics enthusiast.

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Looks like CLI.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Textures
    By fighter92 in forum Game Programming
    Replies: 1
    Last Post: 03-21-2009, 10:57 AM
  2. Textures not texturing the way I want
    By scwizzo in forum Game Programming
    Replies: 0
    Last Post: 12-16-2008, 12:12 PM
  3. loading textures from resources (dx8/9)
    By X PaYnE X in forum Game Programming
    Replies: 1
    Last Post: 12-25-2005, 04:44 PM
  4. the effects of textures on my frame rate
    By DavidP in forum Game Programming
    Replies: 37
    Last Post: 10-03-2003, 11:24 AM
  5. Your favourite fantasy game setting?
    By fry in forum Game Programming
    Replies: 4
    Last Post: 10-16-2002, 06:26 AM