Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Doubt regarding SDL programming


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

#1 meetjatin88   Members   -  Reputation: 104

Like
0Likes
Like

Posted 21 February 2012 - 03:53 PM

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

Sponsor:

#2 MaxFire   Members   -  Reputation: 180

Like
0Likes
Like

Posted 21 February 2012 - 04:40 PM

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. Posted Image

hope this helps

#3 meetjatin88   Members   -  Reputation: 104

Like
0Likes
Like

Posted 22 February 2012 - 11:18 AM

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.

#4 MaxFire   Members   -  Reputation: 180

Like
0Likes
Like

Posted 22 February 2012 - 01:28 PM

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.

#5 meetjatin88   Members   -  Reputation: 104

Like
0Likes
Like

Posted 22 February 2012 - 03:35 PM

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

#6 MaxFire   Members   -  Reputation: 180

Like
0Likes
Like

Posted 22 February 2012 - 03:49 PM

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




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