DirectDraw screws up colors, Direct3D doesn't

Started by Khris, Wed 07/11/2007 14:20:10

Previous topic - Next topic

Khris

I've coded a small ray caster.
It was set to use DirectDraw by default and the result looked like this:


Since I've used a rather arbitrary method for calculating the color, I didn't mind it too much.

When I switched to Direct3D, suddenly I got this:


So my code does work as it should.
I'm just a bit surprised by the results.

Here's a snippet:
Code: ags
        else lightness=Maths.ArcCos(v[hr].dot(rr))/(Maths.Pi);
        lightness=1.0-lightness;
        lightness=lightness*light.lightness;
        int are, g, b;
        are=FloatToInt(IntToFloat(s[fnd].cr)*Maths.RaiseToPower(lightness, red), eRoundNearest);
        g=FloatToInt(IntToFloat(s[fnd].cg)*lightness*red, eRoundNearest);
        b=FloatToInt(IntToFloat(s[fnd].cb)*lightness*red, eRoundNearest);        
        RawSetColorRGB(are, g, b);
        RawDrawRectangle(x, y, x+renderstep-1, y+renderstep-1);


(You can ignore the red variable since it's set to 1 by default.)
lightness is somewhere between 0.0 and 1.0, s[X].cr/g/b define the color of the sphere.

Any explanation? :)

Edit: Actually, after posting this, I came up with a possible explanation. Could it be that the r,g,b values are rounded somehow? To bigger steps than 1? That would explain the huge uni-colored areas and the hue jumps.

DoorKnobHandle

Sorry to not be of any help, but I just gotta ask: what kind of frame-rates are you getting from your renderer? Are they interactive? Awesome work anyways! :)

Khris

Currently, the frame rate is 0,076923076923076923076923076923077 ;)
Looking at the windows clock, it takes 13 seconds to render 320x200=64'000 pixels.

It's not interactive; the spheres are predefined in the code.
I'm planning to add translucency and reflections, and rectangles/boxes.
It's not a serious project, rather something to pass the time while I'm curing my cold :)

Here's a new shot with corrected lighting:

Pumaman

What colour depth is the game set to, and what colour depth was the image imported for the room background?

Direct3D always converts all sprites to the game colour depth, whereas DirectDraw uses them at the depth they were imported at.

Khris

The game is set to 16bit but the room doesn't have a background image. I don't use any sprites.

Could that be the reason?

Current progress: added multiple lights, reflections, shadows


Pumaman

Hmm, try importing a blank 16-bit image as the room background -- it might be that you're using the default room 1 8-bit background which is causing it to map down to 256-colours.

SMF spam blocked by CleanTalk