Jump to content

  • Log In with Google      Sign In   
  • Create Account


Need help - loading textures


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Jossos   Members   -  Reputation: 206

Like
0Likes
Like

Posted 24 September 2013 - 03:08 AM

Hi, I use opengl with SDL. this function works in my other programs. I have the function load a file in the same directory as the other files and it works.

 

Now my problem is that I use this in another program, and for some reason, it returns some absurdly large number. I coped over working files to see if it was the actual image files, and no it still doesn't work. I watch the value of id in this code. In my older program, it holds the value 1 before it returns. In my new program, it returns something like 3465094356 something stupid like that.

// Load a Texture and return the ID
unsigned int GRAPHICS::LoadTexture(const char *filename)
{
	SDL_Surface* img = IMG_Load(filename);

	if (img == NULL) 
	{
		OutputDebugString("\"");
		OutputDebugString(filename);
		OutputDebugString("\" failed to load.\n");
		return -1;
	}

	SDL_PixelFormat form = {NULL, 32, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff, 0, 255};
	SDL_Surface *img2 = SDL_ConvertSurface(img, &form, SDL_SWSURFACE);

	if (img2 == NULL)
	{
		OutputDebugString("\"");
		OutputDebugString(filename);
		OutputDebugString("\" failed to load. img2 == -1\n");
		return -1;
	}

	unsigned int id;
	glGenTextures(1, &id);
	glBindTexture(GL_TEXTURE_2D, id);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img->w, img->h, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, img2->pixels);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

	SDL_FreeSurface(img);
	SDL_FreeSurface(img2);

	return id;
}

I don't understand at all why it would behave differently in each program.

 

Help is appreciated



Sponsor:

#2 BitMaster   Crossbones+   -  Reputation: 3895

Like
0Likes
Like

Posted 24 September 2013 - 04:51 AM

Is it possible you are calling this function before you have created a valid OpenGL context?

#3 mhagain   Crossbones+   -  Reputation: 7822

Like
0Likes
Like

Posted 24 September 2013 - 10:36 AM

Would the "absurdly large number" be 4294967295 by any chance?  Your function returns -1 on failure, but it's an unsigned int return, meaning that it will translate to 4294967295, so one of the two conditions that causes a -1 return is being triggered.  Which one?  Well, your OutputDebugString calls should tell you that when you run it in a debugger, so you'll be able to trace through possible causes from there.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#4 Jossos   Members   -  Reputation: 206

Like
0Likes
Like

Posted 27 September 2013 - 08:30 PM

id returns as 3435973836. God I wish I could fix this. Also, the function isn't returning -1, meaning that it is actually loading the file.



#5 3TATUK2   Members   -  Reputation: 730

Like
0Likes
Like

Posted 27 September 2013 - 08:46 PM

Like BitMaster said.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS