Message Board


Message Board > C/C++ > Whats wrong with this piece of code?!? (SDL)

February 1, 2007, 20:18
Quiest
now with more happynes
142 posts

Code:

//function that returns a 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 does not matter

            //please ignore that it does not make sense:
            pixel_mod.x=pixel.x;
            pixel_mod.y=pixel.y;
            //stop ignoring

            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 it.

Does not work. :( Can someone tell me why?
____________
Roundhousekick to the face, baby!
#
February 2, 2007, 14:42
PEader
お前はもう死んでいる
1486 posts

where are you getting the y_res and x_res? Shouldn't you use the surface to get the x and y values?

Why are you doing it pixel by pixel? Why not one large rect?

My SDL is a bit rusty but don't you need to create the water surface before you blit onto it?

One problem I see is you are not copying a 1x1 pixel rect every time. In each loop you set the width of the rectangle to the x value and the height of the rectangle to the y value.

So when x=5 and y = 5 you are copying a 5x5 pixel rectangle which has it's top left corner at (5,5).

Both these values should be 1 if you want to copy 1 pixel.

I suggest you write your own put_pixel and get_pixel as per the docs and use this to set the corresponding pixels rather then your method of copying a rectangle of 1x1.

[Edited on February 2, 2007 by PEader]
____________
I see 57,005 people.
#
February 2, 2007, 22:10
Quiest
now with more happynes
142 posts

First of all, I figured it out (well,I got help in the gp2x dev board ^^), its just that I forgot to create an actual surface (water was only set to NULL, ).

It works fine now.

And I`m doing it pixel by pixel cause I`m modifying the background image. (the code that didnt matter)

I`m using x_res and y_res (constants) cause it will always be the background size.

And I`m not changing the width and height with .x and .y, thats what you do with .w and .h
I`m changing the coords of the rect.

[Edited on February 2, 2007 by Quiest]
____________
Roundhousekick to the face, baby!
#

Message Board > C/C++ > Whats wrong with this piece of code?!? (SDL)

Quick reply


You must log in or register to post.
Copyright © 2005 Booleansoup.com
Questions? Comments? Bug reports? Contact us!