Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003
    Location
    Sweden
    Posts
    20

    Texture class problem.

    So, I'm trying to utilize the texture class from the vtm inside another program. My problem is, it won't load the textures. It doesn't even try to load it (I added errors to all the functions in loadTGA() so I can see if it atleast tries to load).

    Here's the funny bit... it loads the texture fine OUTSIDE the constructor in that class but not inside the contstructor of that class. It's not an include problem, but I am almost positive that it's some sort of scope problem, that it knows of the Texture class, but can't quite put my finger to it.

    (I've cut away most of the code)

    Code:
    #include "All the necessary includes DOT H"
    
    ITouchScreen *screen;
    OurApplication app;
    
    int main(int argc, char **argv) 
    {
    	// SETUP TOUCHLIB ///////////////////////
    
    	// snip-snip (No interesting code here)
    	
    	screen->registerListener((ITouchListener *)&app);	// Attach our application
    
    	screen->beginProcessing();
    	screen->beginTracking();
    	//////////////////////////////////////////
    
    	// SDL & OPENGL///////////////////////////
    	SDL_Init( SDL_INIT_VIDEO );
    	SDL_SetVideoMode( windowWidth, windowHeight, 0, SDL_OPENGL );
    	if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
    	{
    		std::cout << "SDL Error:" << std::endl;
    	}
    	if( SDL_SetVideoMode( windowWidth, windowHeight, 0, SDL_OPENGL ) == NULL )
    	{
    		std::cout << "OPENGL Error:" << std::endl;
    	}
    	initGL( windowWidth, windowHeight );
    	//////////////////////////////////////////
    
    	// APPLICATION LOOP //////////////////////
    	int done = 0;
    	while( !done )
    	{
    		SDL_Event event;
    		while( SDL_PollEvent( &event ) )
    		{
    			if( event.type == SDL_QUIT )
    				done = 1;
    		}
    
    		screen->getEvents();
    		app.runOrWhateverYouWantToCallIt();
    
    		displayFPS();
    	}
    	//////////////////////////////////////////
    
    	TouchScreenDevice::destroy();
    
    	SDL_Quit();
    
    	return 1;
    }
    Code:
    #include "OurApplication.h"
    
    OurApplication::OurApplication()
    {	
    	// This DOES NOT load.
    	texture = new Texture( "texture.tga" );
    }
    
    OurApplication::~OurApplication()
    {
    }
    OurApplication::aFunction()
    {
    	// When running this function, it DOES load.
    	texture = new Texture( "texture.tga" );
    }

    As I said, I can load textures just fine in the class past the contstructor, but not inside the constructor.

  2. #2
    Join Date
    Jun 2003
    Location
    Trier, Germany
    Posts
    1,350
    not sure about this, since i don't know your code, but this looks like an issue with the initialization. since app is a global, its constructor gets called at the very beginning of your program, before entering main(). at this point, neither opengl nor sdl have been initialized, so any glGenTextures() or whatever will fail.

    this is a classical example where exceptions would come in handy. if your texture class did some proper error checking and threw an exception in its constructor, you would have seen this right away

  3. #3
    Join Date
    Aug 2003
    Location
    Sweden
    Posts
    20
    Quote Originally Posted by ComicSansMS View Post
    not sure about this, since i don't know your code, but this looks like an issue with the initialization. since app is a global, its constructor gets called at the very beginning of your program, before entering main(). at this point, neither opengl nor sdl have been initialized, so any glGenTextures() or whatever will fail.

    this is a classical example where exceptions would come in handy. if your texture class did some proper error checking and threw an exception in its constructor, you would have seen this right away
    Thanks.

    That's what I was thinking aswell. I got it to load now, atleast it tells me it's loaded just fine. But now it won't render the texture. Probably some state error some where.


    Edit: Nevermind me, my fever is effecting my logic it seems. Was just doing things in the wrong order all the time.
    Last edited by SantiClaws; 02-12-2009 at 09:00 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •