Jump to content
  • Advertisement


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


Terrains and bitmaps

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

I am writing a terrain loader which take a loaded grayscale bitmap and convertes it to a vertex buffer. I have written the bulk of my code BUT (and this is the reason i''m posting) how do i read pixel data from a bitmap? It is in a LPDIRECT3DTEXTURE8 object. I have tried locking the texture, but i am not sure what to do now. Help please, thanks in advance. Neil WHATCHA GONNA DO WHEN THE LARGEST ARMS IN THE WORLD RUN WILD ON YOU?!?!

Share this post

Link to post
Share on other sites

I have been looking into this in order to apply colors to my landscape (I''m writing the bitmap rather than reading it, but the concept is the same)

First you have to lock the surface (I didn''t have any luck locking just a portion, so I just locked it all by passing 0).

Then you have to update the pixels directly in the memory pointer returned to you. In order to do this you must know the surface format, but thankfully, you should know what it is since you created (or supplied) the bitmap.

To be even better, you can guarantee the format (force it to a specified format) (eg: 8 bits of red, 8 bits of green, 8 bits of blue, 8 bits of alpha, etc) at load-time using LoadTextureEx (can''t remember the exact name of the Dx8 function for loading textures, but it''s in the D3D8X library).

Here is some code I''ve just whipped together (untested) but it should work. Sorry I can''t get by tab key to work in here, so there''s no indenting. The code assumes as 32 bit image (RGBA). The x4 in the color assignment is due to the fact that each pixel requires 4 bytes of space in a 32 bit image (8 bits for each of R, G, B, A).

Good luck!

// lock the entire texture and update it
unsigned char *bits;
unsigned char r,g,b,a;

res= m_lightMap->LockRect(0, &lr, NULL, NULL);
buf= (unsigned char*)lr.pBits;

for (ty=0; ty<=256; ty++)
for (tx=0; tx<=256; tx++)
b= bits[256*4*ty + tx*4+0]= shade;
g= bits[256*4*ty + tx*4+1]= shade;
r= bits[256*4*ty + tx*4+2]= shade;
a= bits[256*4*ty + tx*4+3]= 255;


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.

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!