Need A Little Help With A Piece Of Code Here.


Quiest

I like turtles!
Joined
Sep 2, 2004
Messages
3,411
Age
40
Location
Dteuschland ;)
I`m learning a little SDL atm (working on my first sdl game for the gp2x :D) and I`d really like to know what is wrong with this piece of code: (please ignore that it will be slow on the gp2x)

Code:
//function to return an altered surface
SDL_Surface *water_effect(SDL_Surface *back)
{
	SDL_Surface *water = NULL;
	SDL_Rect pixel;
	SDL_Rect pixel_mod;

	pixel.w=1;
	pixel.h=1;
	pixel_mod.w=1;
	pixel_mod.h=1;

	for(int y=1; y<y_res-1; y++)
	{
		for(int x=1; x<x_res-1; x++)
		{
			pixel.x=x;
			pixel.y=y;


			//some code here which has nothing to do with the problem


			pixel_mod.x=pixel.x;
			pixel_mod.y=pixel.y;


			SDL_BlitSurface(back,&pixel_mod,water,&pixel);
		}
	}
	return water;
}


What it should do (in this posted state) is take the surface passed to it by parameter and put it pixel per pixel onto another surface (from "back" to "water") and then return the new surface.

But it doesn't work (and the code worked fine when not put in a function), it just returns the empty surface.
:( Can someone help me?
 
Quiest posted on Feb 1 2007 at 10:35 PM said:
I`m learning a little SDL atm (working on my first sdl game for the gp2x :D) and I`d really like to know what is wrong with this piece of code: (please ignore that it will be slow on the gp2x)
(snippity snip)
What it should do (in this posted state) is take the surface passed to it by parameter and put it pixel per pixel onto another surface (from "back" to "water") and then return the new surface.

But it doesn't work (and the code worked fine when not put in a function), it just returns the empty surface.
:( Can someone help me?
Well, as it stands you're not creating a new surface to blit to, you initialize water to be a null pointer and that's it. You need to set it to a valid surface. If SDL_BlitSurface() is passed a null pointer for a surface it just returns without doing anything.
 
Last edited by a moderator:
the guru has spoken!

*reminds me I have to put the fixed version of my first game online*
 
Back
Top