• 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

    • "lets you pause updates by choosing an end date, for up to 35 days" Wasn't it "indefinitely"?
    • Those extra reboots are related to the UEFI Secure Boot certificate update thing.
    • Hands on with the ProtoArc EM25: Affordable ergonomic mouse that focuses on the right things by Taras Buria ProtoArc is known for making all sorts of office products with a big focus on ergonomics and comfort. Its latest product, the EM25, promises a comfortable-to-use, affordable, and customizable mouse. We took one for a spin; here are our impressions. The ProtoArc EM25 is a $49.99 mouse, but right now, during Prime Day 2026, you can get it for just $37.99. Right off the bat, you can see that the EM25 is inspired by Logitech's MX Master lineup and the legendary MX Master 3/3S. Its shape and proportions are very similar, so for a person with large hands (right-handed person, mind you), the EM25 is very comfortable to use. The mouse fills the palm, and the thumb rests on a small extension, giving your wrist a small tilt to reduce strain. The mouse is made of black plastic without any coating, eliminating long-term wear concerns. However, I can see the main buttons and other areas you touch the most getting polished over time. Despite its size and bulk, the mouse is not too heavy. It weighs about 100 grams, which is significantly less than the MX Master 3S and its successor. It is no lightweight gaming mouse by any means, but it is not excessively heavy like the MX Master 4. The EM25 has a built-in storage for its USB dongle. It is a cleverly made magnetic flap that you open by simply pressing on it. Next to the flap, you will find the on/off switch, the 1,000 Hz sensor, and a DPI button (up to 8,000 DPI). I find the DPI button location a bit odd, and I would prefer it somewhere below the main scroll wheel. Still, given that I never change DPI on my mice, I will let it pass. What is more important is that, unlike MX Master 3/3S/4, the device switch button is located below the left-click button, which allows you to switch devices without lifting and flipping the mouse. For a multi-device setup, this is a perfect solution: the button does not require too much effort to use, it does not get in your way, but it is also easily reachable with your thumb. The main scroll wheel has two modes: ratcheted and free-flow. You can only change between them with a bright orange button (I like this little touch of color), which is sprung and requires some effort to press. The wheel is dead-silent in free-flow mode, but ratched is quite loud and stiff, perhaps even too much to my liking. I can hardly call it deal-breaking, but it will certainly take some time to get used to. The side scroll wheel, it is notched, silent, and pleasant to use. Next to it, you can find a piece of glossed plastic with connection indicators: Dongle, Bluetooth 1, Bluetooth 2, and the low battery indicator. By the way, the built-in battery is rechargeable via a USB Type-C cable, which is included. It is sleeved and has an orange velcro strap to keep it tidy. After using the EM25 for a few weeks, I can say that its main buttons are my absolute favorite. They have very pronounced clicks, which feel great with just the right amount of force required to register a press. I would say they feel like something in between regular mouse clicks and silent ones. You can hear and feel the springy switch, but it is not sharp or loud to the point of annoying you. As for back/forward and device switch buttons, they are very clicky and quite noisy. Unfortunately, there are no extra buttons that you can map to specific things like in the MX Master lineup. Besides great primary clicks, another thing I like about the EM25 is its 1,000 Hz sensor. In the world, where Logitech still uses 125 Hz sensors in $100+ mice, seeing a much faster sensor in a mouse that costs three times less is very refreshing. Also, all the settings and customization you make are stored on-device, and you do not need to install any software. Just open the web-based app and change all that you need. Speaking of customization, you can remap what buttons do, adjust the DPI, and the sensor speed. Sadly, gestures are not supported, but you can still map pretty much anything to each button, including shortcuts, media buttons, and more. I also recommend using software like XMouseControl, as it will let you remap the side scroll wheel. At the end of the day, the ProtoArc EM25 is a great mouse. Clearly inspired by the MX Master lineup, it takes the best of it and complements it with a much more wallet-friendly price tag, significantly better sensor, on-device memory, a built-in storage for the dongle, and more (it fixes everything that I complained about the MX Master 4 recently). And for only $37.99 during Prime Day, the EM25 is an easy recommendation. Buy ProtoArc EM25 mouse - $37.99 | 24% off with Prime As an Amazon Associate, we earn from qualifying purchases.
    • Pretty nice tool, thanks
  • Recent Achievements

    • Rookie
      DaviKar went up a rank
      Rookie
    • Dedicated
      HidekoYamamoto94 earned a badge
      Dedicated
    • One Month Later
      timbobit earned a badge
      One Month Later
    • One Month Later
      nates earned a badge
      One Month Later
    • Week One Done
      Almohandis earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      464
    2. 2
      +Edouard
      161
    3. 3
      PsYcHoKiLLa
      110
    4. 4
      Michael Scrip
      83
    5. 5
      Steven P.
      70
  • Tell a friend

    Love Neowin? Tell a friend!