Basic standard graphics

Adam D. Ruppe destructionator at gmail.com
Fri Nov 12 14:54:19 PST 2010


bearophile:
> That's not a fault of Rosettacode, it's more a "meh" of D
> language itself ;-)

I'd say the opposite: it means all your existing knowledge can be used straight up.

This is also why I don't take people's complaints about D's library situation
seriously either. It is a superset of C, and you can use all that stuff with a
minimal amount of fuss.

And even using it in C style is still better than C itself, thanks to the little
enhancements like strings that don't suck, nested functions, and scope statements.


> If you take a look at the RosettaCode site you may find tens of D
> implementations that I have translated from Python (or Haskell)
> instead, and they are sometimes quite different from the C ones.

Yes, I've seen many of your posts about it.

(btw just because you get no responses doesn't mean your posts
were ignored! Many of us read them but have very little to add
or too little time to post, so we don't say anything.)


> If you take a look at my post you may also see I have given a link to the
PureBasic implementation (instead to the C version)

Yea, but it's not significantly different. Hell, if you write the C/D
in the same fashion of the Basic (no functions, just a linear main),
the C has an almost equal line count! (37 lines for C without functions, vs 36
lines for PureBasic Proof: http://arsdnet.net/noise.d ).

So, what's the big benefit there?

Let's walk through it. They work /exactly/ the same way.

Open the window (OpenWindow vs SDL_SetVideoMode)
Do the drawing (StartDrawing vs SDL_LockSurface)
Flip buffers when done (FlipBuffer vs SDL_Flip)
Check the time
Output the FPS


Identical, right down to the individual functions! Every C call has a one-to-one
mapping to PureBasic.


So, really, there's no difference here at all aside from C and D using {} and
Basic using If/EndIf.


> I think D has to aim to something higher level than that C code
> (or your C-like D code).


My D game engine (built on top of SDL and OpenGL) works
by having a frame callback.

Here's an old post I made on another forum a couple years
ago showing a trivial Pong game in D1:

http://sveit.com/forum/viewtopic.php?f=32&t=2051

It gives joystick and transparent network support for a graphical
game in just a little over 100 lines.

With some of my new techniques developed in the years past that, I could cut its
length almost in half, using main mixins and combining variables on one line.


I haven't ported my engine to D2 yet since I've been working almost non-stop in my
code time (which results in web app based stuff coming out of me), but I want to
eventually. When I do, we'll kick the ass of these kind of tasks.


> And I was talking about a standard basic graphics interface for
> Phobos.

Meh, it might be nice, but C gets by without one, and we can do everything C can do.


More information about the Digitalmars-d mailing list