Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


SDL 2.0 and SDL_image problem


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
2 replies to this topic

#1 Spirrwell   Members   -  Reputation: 277

Like
0Likes
Like

Posted 04 July 2012 - 11:11 AM

I tried out SDL 2.0 to see how much better it is than SDL 1.2. I came into a small little bump in road when I'm trying to load an image. These images that I'm using I've had no problem using with SDL 1.2. Basically what's happening is that the BytesPerPixel is getting set to 8 and the BitsPerPixel is getting set to 0. I don't know how this really affects the surface I'm working with, but I wanted to load an OpenGL texture by converting the surface into it. Here's my function:

int LoadTexture2D(const char* filename)
	{
		SDL_Surface* surface = IMG_Load(filename);
		if (!surface)
		{
			errorlevel = 2;
			return -1;
		}
		if ((surface->w & (surface->w - 1)) != 0)
			++warnings;
		if ((surface->h & (surface->h - 1)) != 0)
			++warnings;
		printf("%d\n", surface->format->BitsPerPixel);
		numOfColors = surface->format->BytesPerPixel;
		printf("%d\n", numOfColors);
		switch (numOfColors)
		{
		case 3:
			if (surface->format->Rmask == 0x000000ff)
				textureFormat = GL_RGB;
			else
				textureFormat = GL_BGR;
			break;
		case 4:
			if (surface->format->Rmask == 0x000000ff)
				textureFormat = GL_RGBA;
			else
				textureFormat = GL_BGRA;
			break;
		default:;
			++warnings;
			errorlevel = 2;
			return -1;
			break;
		}
		Width = surface->w;
		Height = surface->h;
		glGenTextures(1, &texture);
		glBindTexture(GL_TEXTURE_2D, texture);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexImage2D(GL_TEXTURE_2D, 0, numOfColors, surface->w, surface->h, 0, textureFormat, GL_UNSIGNED_BYTE, surface->pixels);
		SDL_FreeSurface(surface);
		return 0;
	}

In case you're wondering, this function is inside a class and so are the variables that it's using. So what's the problem, is it just that this function is outdated for SDL 2.0? Should I load an OpenGL texture some other way?

Edited by Spirrwell, 04 July 2012 - 11:12 AM.


Sponsor:

#2 Sik_the_hedgehog   Crossbones+   -  Reputation: 1814

Like
0Likes
Like

Posted 04 July 2012 - 12:50 PM

Never used SDL_image so no idea, but make sure you're using the SDL2 version of SDL_image and not the original one. SDL 2.0 looks similar to 1.2 but it isn't compatible, and as such all the satellite libraries (including SDL_image) had to be adapted.

I doubt that in itself will solve your problem, but make sure you update SDL_image and everything else or you're going to have some serious issues with SDL 2.0 (in some cases the libraries won't even link).
Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

#3 Spirrwell   Members   -  Reputation: 277

Like
0Likes
Like

Posted 04 July 2012 - 02:02 PM

Great, I've got a new problem now. It won't even load the image. It tries to load and it's just null. I completely rebuilt the project and I linked SDL2_image and removed the link to SDL_image. Now I have the modern functions such as IMG_LoadTexture, but I can't even load an image.




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