• 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

    • Exactly, this is just the beginning. I hope that by that time, our inept politicians devise something like a Universal Basic Income, because unemployment and poverty rates will skyrocket otherwise. And believe me, robots that perform physical work aren't a matter of IF, but WHEN. No career is truly safe from AI/androids, it's just a matter of time.
    • Subtitle Edit 5.0.0 by Razvan Serea Subtitle Edit is a powerful, free, and user-friendly subtitle editing tool designed for creating, editing, and converting subtitles for videos. It supports a wide range of subtitle formats, including SRT, ****, and SUB, allowing users to easily modify and adjust subtitles for accurate timing and formatting. With its intuitive interface, Subtitle Edit provides a variety of features such as waveform audio display, spell-check, subtitle synchronization, and real-time video preview, making it an ideal choice for both beginners and professionals. The software also includes powerful tools for batch processing, translating subtitles, and converting between different subtitle formats. Subtitle Edit features: Create/adjust/sync/translate subtitle lines Convert between SubRib, MicroDVD, Advanced Sub Station Alpha, Sub Station Alpha, D-Cinema, SAMI, youtube sbv, and many more (300+ different formats!) Cool audio visualizer control - can display wave form and/or spectrogram Video player uses mpv, DirectShow, or VLC media player Visually sync/adjust a subtitle (start/end position and speed) Audio to text (speech recognition) via Whisper or Vosk/Kaldi Auto Translation via Google translate Rip subtitles from a (decrypted) dvd Import and OCR VobSub sub/idx binary subtitles Import and OCR Blu-ray .sup files - bd sup reading is based on Java code from BDSup2Sub Can open subtitles embedded inside Matroska files Can open subtitles (text, closed captions, VobSub) embedded inside mp4/mv4 files Can open/OCR XSub subtitles embedded inside divx/avi files Can open/OCR DVB and teletext subtitles embedded inside .ts/.m2ts (Transport Stream) files Can open/OCR Blu-ray subtitles embedded inside .m2ts (Transport Stream) files Merge/split subtitles Adjust display time Fix common errors wizard....and more. Subtitle Edit 5.0.0 changelog: Subtitle Edit 5 is a major new release and a big step for the project. For the first time, Subtitle Edit runs natively on Windows, macOS, and Linux from a single, modern, cross-platform codebase. The builds are self-contained, so no separate .NET installation is required, and on macOS and Linux the needed media components (mpv/ffmpeg) are bundled in. Please read before upgrading: Subtitle Edit 5 is a new application, not just an update of Subtitle Edit 4. It has been rebuilt from the ground up to be cross-platform, so: It is not 100% the same app. The look, layout, and some workflows have changed. Some things are in different places, and a few behave differently than in SE4. Not every SE4 feature exists in SE5 yet. SE5 covers all the core editing, conversion, sync, video playback, OCR, and online services, but some of the more specialized SE4 tools are not available yet. Features will continue to be added. If you rely on a specific SE4 feature that is missing, please keep SE4 installed alongside SE5. The easiest way to run both side by side is to use the Portable versions of SE4 and SE5, which keep their settings separate and do not interfere with each other. Which version should I use? Subtitle Edit 5: recommended for most users on Windows 10 (22H2) or newer, macOS 12+, and Linux. Subtitle Edit 4: please continue to use SE4 if you are on an older Windows version (Windows 7/8), or on older / slower computers where SE5 may not run well. SE4 remains available and is the right choice in those cases. To run SE4 and SE5 at the same time, use the Portable versions - you can try SE5 while keeping SE4 as a fallback. Download: Subtitle Edit 5.0.0 | ARM64 | ~60.0 MB (Open Source) Download: Subtitle Edit Portable | 103.0 MB View: Subtitle Edit Homepage | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Google Pixel 11 series: Here's what to expect by Hamid Ganji Google Pixel 10 series In recent years, Google has successfully turned its Pixel devices into worthy contenders in the smartphone market. The search giant is now preparing to launch the Pixel 11 series in just a few months, and many Pixel fans are likely wondering what Google has in store for them this year. The next lineup of Google smartphones includes four devices: the Pixel 11, Pixel 11 Pro, Pixel 11 Pro XL, and Pixel 11 Pro Fold. This year, we don’t expect Google to bring revolutionary upgrades to its handsets, and the Pixel 11 series is likely to receive modest hardware improvements alongside a slew of AI-powered features. Here are the rumored specifications of the Google Pixel 11 series ahead of its official debut: When will the new Pixel phones be unveiled? The last two generations of Google Pixel phones (Pixel 9 series and Pixel 10 series) were launched in August, unlike the previous three generations that debuted in October. With that in mind, we expect Google to unveil the Pixel 11 series sometime in August 2026. The exact launch date has yet to be confirmed. Google Pixel 11 CAD renders - Image via AndroidHeadlines How much will the Pixel 11 series cost? Predicting the final price of upcoming smartphones has become increasingly difficult. As you may know, RAM and memory prices are rising sharply, leading to significant increases in the cost of consumer electronics. Recently, Apple CEO Tim Cook said that price increases for some future Apple products are unavoidable, suggesting that the iPhone 18 series could become more expensive. Google has remained tight-lipped about any potential price increases for the Pixel 11 series. If the company manages to maintain last year’s pricing structure, here’s what the lineup could cost: Pixel 11: $799 Pixel 11 Pro: $999 Pixel 11 Pro XL: $1,199 Pixel 11 Pro Fold: $1,799 Given current market conditions, it may be difficult for Google to avoid raising prices unless it adopts cost-saving measures, such as equipping the base model with 8GB of RAM. Google Pixel 11 series anticipated specs: We expect the Google Pixel 11 series to debut with a new Tensor G6 processor as well as an upgraded camera system. The overall design, however, is expected to remain largely unchanged across the lineup. Specifications Pixel 11 Pixel 11 Pro Pixel 11 Pro XL Pixel 11 Pro Fold Display 6.3-inch LTPO AMOLED / 120Hz refresh rate / up to 3100 nits of brightness 6.3-inch Super Actua LTPO OLED, 120Hz refresh rate, up to 3600 nits of brightness 6.8-inch Super Actua LTPO OLED, 120Hz refresh rate, up to 3600 nits of brightness 8-inch inner screen and 6.4-inch outer display, 120Hz refresh rate, up to 3600 nits of brightness RAM & Processor Tensor G6 / 8-12GB of RAM Tensor G6 / 12-16GB of RAM Tensor G6 / 12-16GB of RAM Tensor G6 / 16GB of RAM Storage options 128GB or 256GB 256GB, 512GB, 1TB 256GB, 512GB, 1TB 256GB, 512GB, 1TB Camera 50MP main sensor, 13MP ultra-wide, 10.8MP 5x telephoto, 10.5MP front camera 50MP main camera, 48MP ultra-wide, 48MP telephoto with 5x optical zoom, 42MP selfie camera 50MP main camera, 48MP ultra-wide, 48MP telephoto with 5x optical zoom, 42MP selfie camera 50MP main camera, 10.5MP ultra-wide camera, 10.8MP telephoto camera, 10MP front camera, 10MP inner camera Battery 4,840 mAh 4,707 mAh 5,000 mAh 4,658 mAh Software Android 17 Android 17 Android 17 Android 17 The Pixel 11 series won’t be a major departure from its predecessor, with Google instead focusing on subtle improvements and AI additions such as Gemini Intelligence. However, a patent filed by Google suggests the company is working on a removable battery for its smartphones, and we could see this feature make its way to the Pixel 11 Pro Fold. Given that nearly all smartphones today lack removable batteries, such a feature would be a welcome addition to future Pixel devices. That said, it may not arrive with this year’s lineup after all, and the final decision is yet to be made by Google. The Pixel 11 series could also face an uphill battle in the market. In the Android segment, Samsung is performing well with the Galaxy S26 series, while the Galaxy Z Fold 8 lineup is also expected to launch next month. On the other hand, Apple is preparing to unveil the iPhone 18 Pro and iPhone 18 Pro Max in September alongside its first foldable iPhone.
    • At least AMD is still taking Windows 10 seriously (after the oops) before it consumer extended support ends. @WaltC - Memories, 2x Voodoo in SLI with a Riva TNT with an Aureal A3D soundcard.
  • Recent Achievements

    • 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
    • Rookie
      dorf went up a rank
      Rookie
    • First Post
      mike_rumble earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      475
    2. 2
      +Edouard
      172
    3. 3
      PsYcHoKiLLa
      105
    4. 4
      Michael Scrip
      88
    5. 5
      Steven P.
      70
  • Tell a friend

    Love Neowin? Tell a friend!