[sdl] Having A Screen Area Larger Than The Screen


Alex.

Retired
Joined
Aug 24, 2005
Messages
4,616
I recently started playing with SDL, and came upon a problem: I want to allocate a screen larger than the GP2X's physical screen, say 340*260 (a 10px border around real screen). Then, I'd like to copy it starting from 10,10 to 329,249. I thought that would be useful for quickly clipping sprites not 100% on screen.

Unfortunately I have no idea how to implement it. I'm used to doing this with a void* buffer then memcpy, but SDL is like a new world :)

Thank you for any help and advice!

- Alex
 
I recently started playing with SDL, and came upon a problem: I want to allocate a screen larger than the GP2X's physical screen, say 340*260 (a 10px border around real screen). Then, I'd like to copy it starting from 10,10 to 329,249. I thought that would be useful for quickly clipping sprites not 100% on screen.

Unfortunately I have no idea how to implement it. I'm used to doing this with a void* buffer then memcpy, but SDL is like a new world :)

Thank you for any help and advice!

- Alex
Try this
http://lazyfooproductions.com/SDL_tutorial...son18/index.php
 
Last edited by a moderator:
Create the screen as normal (320 by 240) . Then create another surface using CreateRGB (or similar) that is of your set size (340 by 260). Blit to this new surface (Sprites, tiles etc), then blit the large surface to the screen's surface.
 
SDL_CreateRGBSurface is just what I was looking for :) I thank you both very much!

- Alex
 
Ah, God! I've been looking for this ever since my GP2X was finally released by the NSA! I couldn't remember "LazyFoo"

http://lazyfooproductions.com/SDL_tutorials/index.php

Also there are even more tutorials directly from the SDL homepage www.libsdl.org
But im glad I could help you.
THe LazyFoo tutorials are great, im moving through them fairly quickly and I think i might be able to create a simlpe jump'run type game fairly easily. We'll see.
 
Last edited by a moderator:
I'm sorry to ask such beginner questions, but rather than making a whole new thread I'll ask here:

How do you get a random integer in a given range? In the C library I used before I'd seed the random number generator with randomize() and then call myint = random(4), which would give me an integer 0, 1, 2, or 3. This no longer works in DevKitGP2X. I was under the impression that SDL has random number functions, but I couldn't find anything.

- Alex

Edit: for now www.randomizer.org is my friend, yay for pre-calculated tables! :D
 
I use the C library functions:

srand(time(NULL)) to seed it
((rand() / 16) % n) to give a number 0 to n-1

The /16 is necessary to give a more random result, the bottom bits are a bit predictable
 
Parkydr, thank you so so much! I turned it into a macro and it works perfectly!

- Alex
 
Back
Top