Thread: Why doesn't glbindtexture recognize the texture id I pass it?

  1. #1
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968

    Why doesn't glbindtexture recognize the texture id I pass it?

    Down below in the code snippet you will see that I load a texture, then bind the ID.

    I will complete this operation multiple times before finally using the actual id to texture map my cube.
    Currently I'm completing these operations in the global scope like so:
    Code:
    	typedef ResourceManager<ResourceTexture> TexManager;
        TexManager Manager;    
    	TexManager::Handle hTex0 = Manager.LoadResource( "axe.bmp" );
        TexManager::Handle hTex1 = Manager.LoadResource( "grass.bmp" );
        TexManager::Handle hTex0Again = Manager.LoadResource( "axe.bmp" );    
    	const ResourceTexture &Tex0 = Manager.GetResource( hTex0 );
        const ResourceTexture &Tex1 = Manager.GetResource( hTex1 );
        const ResourceTexture &Tex0Again = Manager.GetResource( hTex0Again );
    I have stepped through the process multiple times, I can confirm that each handle has a unique texture ID created by the function below, with glBindTexture.

    Now I try to texture map:

    glBindTexture(GL_TEXTURE_2D, Tex0.GetID());

    When the program runs, I get no errors, and I would if something was amiss with the code I have.
    The cube I have drawn on the screen that the function glBindTexture applies to comes up solid white, no texturing.


    I was reading documentation on glBindTexture, and I found this snippet:

    "Texture names are unsigned integers. The value zero is
    reserved to represent the default texture for each texture
    target. Texture names and the corresponding texture
    contents are local to the shared display-list space (see
    glXCreateContext) of the current GL rendering context; two
    rendering contexts share texture names only if they also
    share display lists."

    I feel that this might have something to do with the problem, but I am unsure how to resolve it.

    Code:
    bool        
    ResourceTexture::LoadResource( const std::string &filename )
    {
        assert( 0 == m_Texture );
    	//add texture loading process here.
    	Bitmap image;									// Create Storage Space For The Textures
    	image.Load(filename);
     
    	// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
    	if ( image.GetImg() != NULL )		// If Texture Image Exists
    	{
    		glGenTextures(1, &m_Texture);						// Create The Texture
     
    		// Typical Texture Generation Using Data From The Bitmap
    		glBindTexture(GL_TEXTURE_2D, m_Texture);
    		glTexImage2D(GL_TEXTURE_2D, 0, 3, image.GetWidth(), image.GetHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, image.GetImg());
    		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    		SetFilename( filename );
    		return true;
    	}
    	else
    		return false;      
    }
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  2. #2

    Join Date
    May 2005
    Posts
    1,042
    Are you trying to load the textures before OpenGL is initialized?
    I'm not immature, I'm refined in the opposite direction.

  3. #3
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Oh bob, you know me all too well.

    hahahahaha.

    Hey look here they are right at the top of the main cpp file!

    Code:
    #include "NeHeGL.h"
    #include "Camera.h"
    #include "Scene_Manager.h"
    #include "Math3d.h"
    #include "Resource_Manager.h"
    #include "RCTexture.h"
    #ifndef CDS_FULLSCREEN		// CDS_FULLSCREEN Is Not Defined By Some
    #define CDS_FULLSCREEN 4	// Compilers. By Defining It This Way,
    #endif						// We Can Avoid Errors
    
    GL_Window*	g_window;
    Keys*		g_keys;
    bool	keys[256];			// Array Used For The Keyboard Routine
    // User Defined Variables
    	
    UINT	MouseX, MouseY;		// Coordinates for the mouse
    UINT	CenterX, CenterY;	// Coordinates for the center of the screen.
    
    Camera Cam;				// Our Camera for moving around and setting prespective
    							// on things.
    
    void CheckMouse(void);		// Function Prototypes
    void CheckKeys(void);
    
    	typedef ResourceManager<ResourceTexture> TexManager;
        TexManager Manager;    
    	TexManager::Handle hTex0 = Manager.LoadResource( "axe.bmp" );
        TexManager::Handle hTex1 = Manager.LoadResource( "grass.bmp" );
        TexManager::Handle hTex0Again = Manager.LoadResource( "axe.bmp" );    
    	const ResourceTexture &Tex0 = Manager.GetResource( hTex0 );
        const ResourceTexture &Tex1 = Manager.GetResource( hTex1 );
        const ResourceTexture &Tex0Again = Manager.GetResource( hTex0Again );
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

  4. #4

    Join Date
    May 2005
    Posts
    1,042
    So I take it that fixed it? I only thought of that because I've done the same thing.
    I'm not immature, I'm refined in the opposite direction.

  5. #5
    Absent Minded Programmer
    Join Date
    May 2005
    Posts
    968
    Well, I'm positive that it would fix it.

    But I hate to move things into classes until they have a permanent home :\

    And I'm not quite sure where to put this bit of functionality yet.
    Sometimes I forget what I am doing when I enter a room, actually, quite often.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. d3d9 c++ texture wrapper... again...
    By yaya in forum Game Programming
    Replies: 0
    Last Post: 04-01-2009, 01:08 PM
  2. D3d Texture Wrapper == ARRRGGGGHHH
    By yaya in forum Game Programming
    Replies: 1
    Last Post: 03-25-2009, 06:41 PM
  3. Speed test result
    By audinue in forum C Programming
    Replies: 4
    Last Post: 07-07-2008, 05:18 AM
  4. OpenGL - look trough surface -nehe lesson
    By GanglyLamb in forum Game Programming
    Replies: 8
    Last Post: 08-24-2006, 11:06 PM
  5. Pong is completed!!!
    By Shamino in forum Game Programming
    Replies: 11
    Last Post: 05-26-2005, 10:50 AM