Go to bottom

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.
added on the 2011-11-04 23:38:11 by Marq Marq
whats wrong with clock() and CLOCKS_PER_SEC from ctime.h with a bit of typecasting and shifting?
added on the 2011-11-04 23:42:08 by vectory vectory
You live, you learn. Nuskool C89 addition! :)
added on the 2011-11-04 23:51:58 by Marq Marq
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/
added on the 2011-11-04 23:54:54 by zeroshift zeroshift
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.
added on the 2011-11-05 00:17:56 by joooo joooo
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.

added on the 2011-11-05 04:43:36 by xwize xwize
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).
added on the 2011-11-05 06:23:06 by provod provod
... or simply use the time of your audio lib
... as long as that audio lib isn't FMOD.
added on the 2011-11-05 11:31:43 by kb_ kb_
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. :)
added on the 2011-11-05 19:03:37 by kb_ kb_
I can't use BASS or FMOD in intros, right?
added on the 2011-11-05 20:19:20 by joooo joooo
I'd have to link it statically 'cause it's not part of usual setups, right?
added on the 2011-11-05 21:21:17 by joooo joooo
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?
added on the 2011-11-05 22:17:06 by joooo joooo
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.
added on the 2011-11-05 22:30:18 by jaw jaw
@joooo: 4klang can export ELFs, so you should be fine.
added on the 2011-11-05 23:01:25 by Subi Subi
Ah, that's nice! And I could get the 4klang linux example (that uses sdl+opengl) in 4k :D (down from 10)
added on the 2011-11-06 00:30:05 by joooo joooo
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.
added on the 2011-11-06 01:38:59 by Sesse Sesse
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.
added on the 2011-11-06 09:50:54 by Marq Marq


Go to top