More DX 16bit queries ... ;)

Started by
17 comments, last by GameDev.net 24 years, 4 months ago
Hey,

Thanks for all your replies guys, most useful

Have just been looking on directxfaq.com, and found this article; http://www.directxfaq.com/kbase/ddraw/16bitspixels.htm

The code in it looks pretty similar to CJs
Infact, I'd say identical heh.

Anyway, thanks a lot,

James

Advertisement
I think you missed my point, Coder++. Using a global array is, in this case, much the same as using a pointer to memory allocated at startup and deallocated at shutdown. As CJ says, everyone has their style, and that is the style I find most simple to use for such things.

Also, using a char in this code would not be such a good idea. Even an unsigned char would still overflow when incremented at 255, and thus the for loop would not catch it.

My advice is to not bother to be frugal about counter variables and such. You're far more likely to cause more trouble than you save.

Regards

Starfall

jAMES,
hat's right, it's the place where I got it from a long time ago, I lost the url though. I've been using it for quite a while, but i changed to 24 bit these days. I got a good understanding about 16 bit, and will probably soon write a better thing.

I'm just wondering, what would be faster? To shift? or to use a LUT.....what's more important? speed or memory? I would say a LUT is still faster........

------------------
Dance with me......

http://members.xoom.com/CJdeVos/index.htm

James -
An easy way is similar to using Starfalls-
just create an array that converts from 555 to the screen format and one that converts back:

unsigned short clr_555_to_fmt[32768];
unsigned short clr_fmt_to_555[65536];

All colors would pass through the first array before displaying them, and if you need to read information back, pass them through the 2nd.

The reason they are different sizes is the first only takes a 555 amount, and the second possibly uses 565.

If this doesn't make much sense, let me know and I'll type something better -- I'm at work right now.


Now, about using malloc and static arrays:
it doesn't really matter. It's just coding style. It some cases though, using a static array will bloat the .exe file.

As for using int and such, you have to remember that int is not a fixed size - it will vary from machine to machine and depending on the compiler.

Use short for 16 bit, and long for 32 bit
(on a x86 machine at least).

Jim

Hi Jim,

Thanks for your reply, I *think* I get you, but could you kindly exemplify the creation of the LUT a little?

I'd appreciate it

Thanks,
James

btw, Lightbefallen is looking amazing!

James-

Here's what I do: All my tiles are stored in a 555 format, just because I definately know that's what it is. All color calculations performed are 555 no matter what.

When it comes time, say to load a tile into the cache, it will pass through a conversion function to convert to the screen format.

So, let's say we have a 32x32 tile stored at 555 format and this is my loading function:

for(i=0;i<32;i++) {
fread(&buf, 1, 32*2, fp);
for(j=0;j<32;j++)
buf[j] = clr_555_to_fmt[buf[j]];
buf += page.lpitch;
}

I never have to worry what the screen format is. Let's assume I'm reading a pixel from a screen buffer or tile buffer or whatever to work on:

color = page.ptr[12];
color555 = clr_fmt_to_555;<BR> <BR>Then I do color conversions based on 555 format to color555 variable, then I can write it back:<P> page.ptr[12] = clr_555_to_fmt[color555];<P><BR>Now, to setup the conversion tables, just do this:<P>unsigned short clr_555_to_fmt[32768];<BR>unsigned short clr_fmt_to_555[65536];<P>for(i=0;i<65536;i++) {<BR> // convert 555 to format<BR> if(i < 32768) {<BR> red = (i >> 10) & 31;<BR> green = (i >> 5) & 31;<BR> blue = i & 31;<BR> clr_555_to_fmt = (red << 11) | (green << 5) | blue;<BR> }<P> // convert format to 555 - assume 565<BR> red = (i >> 11) & 31;<BR> green = (i >> 5) & 31;<BR> blue = i & 31;<BR> clr_fmt_to_555 = (red << 10) | (green << 5) | blue;<BR>}<P>Please excuse me if this is a little off - I'm trying to do this from memory, but it looks right. You should get the idea.<P>Just create a better one that shifts and arranges the colors based on the info you get from GetSurfDesc.<P><BR>Thanks about TLB. It's being totally revamped - we have a new graphics and sound engine, plus some awesome stuff going in - we hope to have a new demo in the next couple of months.<P><BR>Jim Adams<P>

As already mentioned there is no reason to use an _int64 for creating portable apps, 'cause it's MS specific. And I don't think it's reasonable to talk about portability when writing apps for DirectX. I'd really like to see a port of DirectX to a system that does not use the same size for an int.

CU,
Alex

------------------
Alexander Stockinger
Programmer

Alexander Stockinger
Programmer
Hi =)

After reading through a few articles on the problems of 16bit RGB formats on vid cards, I've finally (almost) got it licked.

What I'm not sure on is how to actually implement the different variations in my code. I can detect the format etc., that isn't the problem... Hmm, this is hard to explain.

What I mean is, say I have a 5-5-5 graphics card. Pure white will therefore me (31,31,31). But say I then use the code on a 5-6-5 format graphics card... It'll be a pinky colour. Basically what I'm asking is, do I pick say 5-6-5 as my primary format (65k colours) and then reduce (ie. divide by 2 the green componet) for a 5-5-5 card etc.?

Also, is it better to (at each point in my code where I want to draw a pixel say) have an if() or switch() kinda thing or should I use a macro which encompasses everything (but has a lot of shifts...)?

I'm sorry if I haven't made sense... basically I know how to detect the format, the shifts needed etc, just not how to implement them (in an optimized way).

Any help would be appreciated

Thanks,
James

Regarding ints and DX - do you know what size an int is on the dreamcast? Is it use 32 or 64 bit registers?

As far as porting, you can alway generalize function calls and use DX in those. When you port, simply change a couple routines and it's done.


Jim

This topic is closed to new replies.

Advertisement