Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Dynamic Lighting in a 2D game!

This topic is 6947 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay so this idea isn''t exactly new, but for me, it was groundbreaking (in that i sort of know how to do it!) Its a way of having rockets etc glow using a predefined .pcx file to show where the glow is (so you could have a glow in any shape you wanted). Okay, Here''s my method. - Draw everything (sprites, backgrounds) to a backbuffer - Now extract required pixels from the composite frame (the backbuffer) - Modify them according to a LightMap© - And draw them back on! Okay so this may be slow in practise, but its a start. What I was wondering is if anyone knows how to convert an RGB 16bit integer BACK into it''s three seperate colour values? so go from: int colour; to: int red, int green, int blue; all with a maximum value of 31 (16 bit colour mode). Any help would be appreciated!

Share this post

Link to post
Share on other sites
[Woo, a fellow Aussie ]

If you have a 16-bit colour, nColour, in RGB565 format you can convert back to R,G,B values:

nR = nColour & 0x001F;
nG = (nColour & 0x07E0) >> 5;
nB = (nColour & 0xF800) >> 11;

Except, nG will have a maximum value of 63 (''cause it''s using 6-bits not 5). If you double nR and nB then they''ll all have a maximum value of 63.

If you really want them all to have a maximum of 31, then you''ll have to divide nG by two - note that you are losing information here (i.e. the value of the low-order bit of nG). By doubling nB and nR, you don''t lose any information (you insert redundant information).

A final point is that if you''re using DirectDraw to do this, you should use it''s DirectDrawPixelFormat (is that the right one?) structure to get the values to be used in the calculations above (in case the 16-bit format is actually BGR565 or something else odd).

I''m sure someone can correct any of my errors.


Share this post

Link to post
Share on other sites
Yeah, what you''re talking about is a two-pass sprite rendering system. I also came to the conclusion that to do dynamic lighting, its probably the best way of doing it. A single-pass method of trying to compute how the lightmap effects your pixels while you''re blitting, even with a software blit, is very difficult.

And yes, it''s probably slow. Not sure how doable it is with DirectDraw blits, you can do it (slowly) in software render, or you can hook up with a 3d rasterizer to do all this heavy-duty pixel manip for you.

- Remnant
- (Steve Schmitt)

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!