Doubt regarding SDL programming

Started by
4 comments, last by maxfire 12 years, 1 month ago
Hi All,

I have a doubt regarding SDL programming.
Can some one please help me how can i subdivide a Image lets say into 4 parts and then store them in SDL_Surface array.
I intend to animate later using these subdivided images by using SDL_BlitSurface function.

I am new to SDL,so it would be great if someone could provide some codes for reference.

Please note that i am using Microsoft visual c++ 2010 compiler..

Thanks
Jatin
Advertisement
hey dude why would you do this? Its a wast of memory

your best bet is to load one surface and then clip it

You can do this by specifying a clipping rect ( SDL_RECT ) when blitting the surface to the screen.

int SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect); // the second parameter

if you really want to do it like that you could create an array/vector/list then use SDL_CreateRGBSurface to create a new surface, blit from your original onto the new one then store it into the array/vector/list but you will still need to use the clipping to get the segment you want. smile.png

hope this helps
Hi Guys,

I am stuck again and need you help on two issues,if some one know any thing about these two things please reply

1)I want to create a negative of an image if say the user enter key 'N'.Now i know the logic of creating an negative ie find RGB value of each pixel on the screen,then subtract the indiviual RGB value from 255 to get the new value.However i do not know how can we take RGB value from each pixel and then write them back on screen.Have anyone tried something like this or do someone have a better idea.Please some reference code if some one has tried anything like this.

2)I am trying to create a camera in SDL by using SDL_rect and then positioning it in the screen by giving some offsets,but what i really want to achieve is that i have created an animation and i would like my camera to move along with it.I mean if my animation is moving to the right ,it should feel like camera is following him.But i am unable to achieve this result.Have anyone tried to emulate a camera in SDL before and if yes assist me.
You really need to look at some SDL and game tutorials dude. I recommend http://lazyfoo.net/SDL_tutorials/. He has tutorials up there for pixel manipulation and camera moving. My suggestion is go through all of these tutorials before starting anything.
Hi MaxFire,
Thanks for the Information but i have already have a look at them and these things are not there.,but i gained all of knowledge from there.
Can you please suggest some other good SDL programming sites esp related having motion and collision examples.

Thanks
Jatin
Lazyfoo does indeed has them all

Camera - http://lazyfoo.net/SDL_tutorials/lesson21/index.php
pixel manipulation - http://lazyfoo.net/SDL_tutorials/lesson31/index.php ( to achieve the effect your looking for you will need to use SDL_GetPixel to get the colours to achive your negative effect )
motion - http://lazyfoo.net/SDL_tutorials/lesson16/index.php
collision detection - http://lazyfoo.net/SDL_tutorials/lesson17/index.php

This topic is closed to new replies.

Advertisement