• 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

    • The memory and nvme can be swapped and upgraded with standard parts. But the GPU cannot, which is the weakest part of the box. It's a dead product at these prices.
    • Sounds like the debloated build you are running is missing some components that the Photos app and Snipping Tool rely on.
    • Apparently, Microsoft doesn't use water in their taps, washrooms or clean their facility. /sarc
    • Wow, throwback.  VERY VERY briefly - but realised that it wasn't the language I needed for the tasks I was taking on.
    • Apple and Tesla trade secrets reportedly exposed following a Tata Electronics cyberattack by Hamid Ganji Image via Depositphotos.com Tata Electronics has confirmed that it detected a cybersecurity incident in some of its systems. The Indian company is a manufacturing partner of both Apple and Tesla, and the incident may have exposed some trade secrets belonging to the two American companies. The World Leaks ransomware group is said to be behind the attack, and it has reportedly posted up to 200,000 files on the dark web, including component designs and specification documents related to Apple and Tesla products. Tata Electronics told Reuters that its response protocols were deployed immediately and that the “incident has had no impact on our operations across businesses, which remain unaffected.” The ransomware group reportedly sent a ransom demand to Tata Electronics, while Apple has launched an investigation into the incident. World Leaks claims it stole more than 200,000 files totaling over 630GB from Tata Electronics. Some database files on the ransomware group’s website are titled "com.apple.factorydata," which could refer to Apple’s iPhone production operations in India. Moreover, some documents reportedly contain material specifications and quality inspection standards for iPhone circuit board components. However, Apple is not the only affected company. A folder found in the World Leaks database is titled "NV36 Chargeport Controller - North America," which may refer to Tesla Model Y components. Additionally, other files in the database reportedly contain drawings related to Tesla’s Project Highland, the internal codename for the EV maker’s updated Model 3 sedan. To support the authenticity of the stolen files, World Leaks has published documents containing footers that read: "This document contains proprietary and confidential information of Apple Inc." and "information contained herein is deemed confidential, proprietary, and a trade secret of Tesla Inc." Cybersecurity researcher Rajshekhar Rajaharia told Reuters that the database also contains emails, event logs spanning several years, and passport copies of employees, including foreign nationals. Both Tesla and Apple have declined to comment on the scale of the incident.
  • Recent Achievements

    • 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
    • Dedicated
      tuben earned a badge
      Dedicated
  • Popular Contributors

    1. 1
      +primortal
      479
    2. 2
      +Edouard
      198
    3. 3
      PsYcHoKiLLa
      96
    4. 4
      Michael Scrip
      91
    5. 5
      neufuse
      71
  • Tell a friend

    Love Neowin? Tell a friend!