Linux C++ Democoding
category: code [glöplog]
There's no pure C function to get a millisecond timer, but practically all Unix flavors do support gettimeofday(). SDL_GetTicks() is probably less hassle, if you're gonna have SDL there anyway.
whats wrong with clock() and CLOCKS_PER_SEC from ctime.h with a bit of typecasting and shifting?
You live, you learn. Nuskool C89 addition! :)
It may help someone, i have been porting my humble demoscene toolkit to the linux, checkout, build-it and run :) https://code.google.com/p/nctoolkit/
vectory: That's clock returns the number of cpu cycles of my application. That's not what I want. Took me some time to figure that.
The most painless setup I've managed to find with opengl is glfw + glee. They're both static libraries, cross platform and do what they say on the tin. One handles all system stuff and window setup (even msaa which is a total pain in the arse) gives you threads, timers and even a tga loader. The other handles all the opengl extension stuff. You can avoid a hell of a lot of boilerplate code this way and get stuff up and running very quickly. I'd choose glfw over SDL or GLUT any day. Throw in CG maybe for shaders and BASS/FMOD/ArbitaryAudioLibrary for audio and you've got yourself a decent core set of libraries to build your demo on - painlessly too I might add. All thats left is to code up are the interesting bits.
The best and most correct and efficient way to get high resolution time in linux is the clock_gettime(CLOCK_MONOTONIC_RAW, ...). Don't ever think of using gettimeofday() for anything with high resolution deltas.
SDL_GetTicks() is fine too, as it internally calls clock_gettime(CLOCK_MONOTONIC).
SDL_GetTicks() is fine too, as it internally calls clock_gettime(CLOCK_MONOTONIC).
... or simply use the time of your audio lib
... as long as that audio lib isn't FMOD.
what's wrong with FMOD? (or what's wrong with Linux version of FMOD?)
the 43hz timer thingy (although with some luck this problem doesn't exist on the linux version). Really, use BASS, on both Windows and Linux and you'll be happy.
FMOD's time functions are only precise to 1024 samples which is about 43Hz at a sampling rate of 44KHz. Sucks if you want the demo to run smoothly at 60. :)
I can't use BASS or FMOD in intros, right?
I'd have to link it statically 'cause it's not part of usual setups, right?
Well, you could also set LD_LIBRARY_PATH to use a dynamic library, but of course that wouldn't work for size restricted intros.
So, I necessarily have to write my own softsynth for a linux intro?
a bit off topic.. but might interrest someone...
I'm testing compiling windows programs under linux using mingw32 (there's also a 64-bit compiler). So far it seems quite promising - every thing works a lot better than under windows mingw when compiling libs like glfw, glew, zlib, png etc.. There's even NSIS on debian/ubuntu and cmake can generate such installers. So if this works out I'll have a very nice automated build environment which can build both windows and linux binaries.
I'm testing compiling windows programs under linux using mingw32 (there's also a 64-bit compiler). So far it seems quite promising - every thing works a lot better than under windows mingw when compiling libs like glfw, glew, zlib, png etc.. There's even NSIS on debian/ubuntu and cmake can generate such installers. So if this works out I'll have a very nice automated build environment which can build both windows and linux binaries.
@joooo: 4klang can export ELFs, so you should be fine.
Ah, that's nice! And I could get the 4klang linux example (that uses sdl+opengl) in 4k :D (down from 10)
jaw: Almost all of the Windows demos I've been part of releasing have been cross-compiled from Linux using MinGW, so I can attest that it works.
For Linux 4k coding there's a dedicated page here: http://in4k.northerndragons.ca/index.php?title=Linux. Some of the material is a bit outdated, though.