• 0

Parallax Starfield (SDL)


Question

Hi,

I was reading an issue of Linux Format today, and saw a parallax starfield in SDL. I hadn't tried SDL before, so I gave it a shot, and added some extra functionality like bliting images of planets, etc. I was surprised how easy it was.

Anyone else played around with SDL before? How do you rate it vs other graphic libraries?

I've included the code I threw together as an attachment if anyone wants to play with it. Just chmod +x build, then ./build to compile it, and ./cosmos to run it. It's hardcoded for my resolution (1080p), but it's easy enough to change the defines at the top of main.c.

cosmos.zip

Link to comment
https://www.neowin.net/forum/topic/1108349-parallax-starfield-sdl/
Share on other sites

10 answers to this question

Recommended Posts

  • 0

Strange. I'm still getting some tearing even after locking the fps at 60 frames and double buffering the surface. Perhaps it's SDL or my graphics driver.

I just realised as well that passing an expression containing rand () as a parameter to a MAX macro isn't a good idea due to duplicate evaluation :/

cosmos.zip

  • 0

I tried to compile your code on my Mint VM but I didn't have SDL installed, and I'm not sure how to properly install it on Linux.

That said SDL is obviously a quality and widely used library especially in the *.nix world, but for my own needs I prefer to use higher-level, object-oriented APIs which allow me to focus on the application logic. For C++ I like SFML, for C# I like XNA/MonoGame.

  • 0

I much prefer Allegro 5 over SDL, but both are good at what they do. A game I'm developing uses Allegro 5 to abstract most platform-specific stuff, while the rest is done in C# and OpenGL 3.3. I went with Allegro over the experience and (in my opinion), the nicer API. But I guess that doesn't matter much when it's all P/Invoke.

  • 0

I tried to compile your code on my Mint VM but I didn't have SDL installed, and I'm not sure how to properly install it on Linux.

sudo apt-get install libsdl-dev libsdl-image1.2-dev

Ubuntu / Mint's default version of GCC doesn't like it when -lSDL_image isn't right at the end of the line. So you'll need to move it to the end of the line in build:

gcc -o cosmos -O2 -march=native -s -pedantic -Wall `pkg-config --cflags --libs sdl` [b']-lSDL_image main.c[/b]

to

gcc main.c -o cosmos -O2 -march=native -s -pedantic -Wall `pkg-config --cflags --libs sdl` -lSDL_image

should do it.

You'll probably have to change the video resolution in main.c if your host doesn't support 1080p. If it does support it, then just full screen the guest mint and it should work, albeit, not as smooth as a native machine.

That said SDL is obviously a quality and widely used library especially in the *.nix world

Yeah, I'm quite impressed with how easy it is to use. I might try writing a game in it, or perhaps a Stargate-esque wormhole simulator.

, but for my own needs I prefer to use higher-level, object-oriented APIs which allow me to focus on the application logic. For C++ I like SFML, for C# I like XNA/MonoGame.

I haven't tried MonoGame before, but I'll take a look at it, thanks.

  • 0

I much prefer Allegro 5 over SDL, but both are good at what they do. A game I'm developing uses Allegro 5 to abstract most platform-specific stuff, while the rest is done in C# and OpenGL 3.3. I went with Allegro over the experience and (in my opinion), the nicer API. But I guess that doesn't matter much when it's all P/Invoke.

That looks interesting. It looks like it does more of the grunt work than SDL. Perhaps it would be easier to get a game up and running using that than SDL alone.

  • 0

If you're on Ubuntu or Mint you need to add the badgerports repositories to get the latest Monodevelop/MonoGame packages. On other distributions I don't know.

There are two packages for Arch (my distro).

$  yaourt -Ss monogame
aur/monogame 2.5.1.0-1 (3)
	XNA Implementation for Mono based platforms
aur/monogame-git 20120512-1 (1)
	XNA Implementation for Mono based platforms (git)

The GIT one will no doubt be more up to date. It's good that it has cli tools. I'm too attached to Vim to use anything else ;)

Edit: Not sure I like the licence:

$  yaourt -Si monogame | grep Licenses
Licenses	   : Microsoft Public License

  • 0

What's the problem with it? Having "Microsoft" in the name? It's approved by the OSI.

Microsoft licences tend to be precarious. I prefer the GPL. Mono has a GPL licence, so I don't see why monogame can't follow suit. But anyway, I'll take a look at it.

This topic is now closed to further replies.
  • Posts

    • Windows 8 and Vista were far worse. Both of those got marginally better at the very end. Just look at their adoption rates and support life-span. If those versions had as much social media in their time they would have ripped apart unmercifully.
    • I must admit, this is probably the only game at the moment where I can see that $80 price point being ok. The issue will be when other developers think they can get away with it with half of the work.
    • Google Wallet expands TSA PreCheck Touchless ID access to more travellers by Fiza Ali Google has announced that Google Wallet is becoming the first digital wallet to integrate with TSA PreCheck Touchless ID. It is a programme that lets eligible travellers move through participating airport security checkpoints using facial recognition instead of showing a physical ID or boarding pass. While the TSA PreCheck Touchless ID programme has been available for some time, using it hasn't always been straightforward. The programme currently operates at 65 airports across the US, but participation has largely depended on flying with a limited number of airlines. Travellers also had to upload passport information separately through participating carriers. Now, the tech giant's new integration is designed to remove some of those extra steps. With the update rolling out in the coming weeks, travellers with TSA PreCheck membership will be able to enrol in Touchless ID through Google Wallet and use the service with any of the 100 airlines participating in the programme. Rather than repeatedly submitting identification details, users can store a digital ID in Google Wallet and use it to streamline future trips. Setting up the feature is relatively straightforward as well. The process starts with users creating a digital ID in Google Wallet using their passport information. After checking in for a flight and saving a boarding pass to the app, eligible travellers will see a "Get started" option that directs them to the TSA enrolment process. Once users choose to share their ID pass and boarding pass information with the TSA for a specific trip, the agency will verify the enrolment. If approved, a TSA PreCheck Touchless ID indicator will appear on the boarding pass stored in Google Wallet, signalling that the traveller can use designated express Touchless ID lanes at participating airports. As privacy and security are likely to be key considerations for many travellers, Google says users must explicitly opt in before any information is shared with the TSA, and authentication is required through a device PIN, pattern, or biometric verification. The company also notes that digital IDs stored in Google Wallet remain encrypted and are kept on the user's device. For frequent flyers who already use TSA PreCheck, the new integration could remove a few more steps from the airport security process, making travel slightly faster and a little less cumbersome.
    • Even though MS had to sunset the Windows Subsystem for Android, you can apparently use BlueStacks to run Android in Windows now. I haven't tested this yet, so if anyone has any feedback, I'd love to hear it.
  • Recent Achievements

    • Dedicated
      Scoobystu earned a badge
      Dedicated
    • First Post
      Tom Schmidt earned a badge
      First Post
    • One Month Later
      D0nn13 earned a badge
      One Month Later
    • Rookie
      +ChiefOfNeo went up a rank
      Rookie
    • One Year In
      Tom Schmidt earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      456
    2. 2
      +Edouard
      177
    3. 3
      PsYcHoKiLLa
      123
    4. 4
      Michael Scrip
      82
    5. 5
      Xenon
      76
  • Tell a friend

    Love Neowin? Tell a friend!