Jump to content
  • Advertisement
Sign in to follow this  
shotgunnutter

OpenGL Getting 2d worms terrain into memory

This topic is 4003 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

Hi there, This is for a worms clone,in c++ and OpenGL, which I am in the middle of writing. Right now the poor chaps have to put up with fighting on a single line. The terrain is larger because this clone focuses more on rifles and submachine guns than bazookas or grenades, so the distances can be further apart. Maps are loaded from a .tga file. Supposing my terrain is made of 16 x 8 sections each 256x256 pixels. There is an alpha map which doubles as collision detection data. How do I get 256 x 256 x 16 x 8 into the minimum amount of memory, assuming each section is self contained, and there is only a requirement for 4 bits? I've tried using c++ bools but they take 8 bytes each. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Bools are only supposed to hold 'true' or 'false', putting numbers into a bool may *seem to work on your compiler*, but it's not valid code, and might not work on other compilers.

You probably want to create a big array of bytes (chars), or an array of structures like this:

struct PixelWithAlpha
{
unsigned char r,g,b,a;//unsigned char's hold values from 0 to 255 (on most systems, anyway...)
};
struct BitmapChunk256
{
PixelWithAlpha[256][256];
};
struct Map
{
BitmapChunk256[16][8];
};

Map myMap;//here you go

[EDIT] Also keep in mind that the compiler is going to pad things out to the word boundary of the CPU (32 bits usually), so if your not careful, a 2-bit number can still end up using 32 bits!
struct PixelWithAlpha
{
unsigned char r,g,b; //24 bit colour
unsigned char a:1;//only 1 bit alpha
};//this structure still takes up 32 bits (not 25) due to padding!



[Edited by - Hodgman on December 4, 2007 8:16:58 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!