Make a heightmap from a loaded bitmap???
i am starting to work on adding terrain to my engine, and i want to be able to load a bitmap into memory, then read each pixel''s brightness, and convert that to a height in the terrain array. But i have no idea how to...
please help me if you can... thx
--------------------------------------------------------------If it sounds like a good idea, do it. It is much harder to get permission than it is to apologize.
That sounds just like my problem. Take a look at my post I explain alot in it the post is Terrain Engine Prolbem (Loading Heights). It''s reatvely easy to accomplish now that I have looked at it a bit more. All you have to do is create a mesh out of an array of numbers (not hard at all lesson 11 (the flag effect) shows you how)then take all of your x,y,or z components (whatever the height will be) and put in a Targa (TGA) image. Then useing glReadPixles you find the brightness of the colors in a diced up texture (the TGA) and use the chunks as verex heights. If or confused just ask i''ll try to be more clear.
A man walks into a bar.....ouch!?! Ya get it, do ya huh huh well....awww I give up.
yay some help!
i noticed your post, but i didnt see anything that really helped. I looked at the website some guy replied to your post about, but it seemed a bit too complicated for me.
All i really need cleared up (so far) is:
1. whats the difference between TGAs and bitmaps, wont they be the same when theyre loaded in as textures?
2. how do i read a pixel at a textures x,y location, and store its brightness.
btw, i have never used TGAs in my life, ive always liked bitmaps...
thanks :-)
i noticed your post, but i didnt see anything that really helped. I looked at the website some guy replied to your post about, but it seemed a bit too complicated for me.
All i really need cleared up (so far) is:
1. whats the difference between TGAs and bitmaps, wont they be the same when theyre loaded in as textures?
2. how do i read a pixel at a textures x,y location, and store its brightness.
btw, i have never used TGAs in my life, ive always liked bitmaps...
thanks :-)
--------------------------------------------------------------If it sounds like a good idea, do it. It is much harder to get permission than it is to apologize.
There are a copuple of differences between bitmaps ant targa images. First is size bitmaps are huge compared to acompressed Targa, there even big compared to a targa image. Thats the main reason I use them. They also have alot more formats makeing it easier to acomplish som things.
To read in a pixls format you use
glReadPixels(GLuint x, GLuin y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
Replace x, and y with the x and y positions of the lower left of the area you want to read. Replace width and height with the width and height of the area to scane. Replace the format with GL_RGB or GL_RGBA. Then type replace with the type of data the pixel is GL_UNSIGNED_BYTE, GL_BYTE, GL_BITMAP, GL_UNSIGNED_SHORT,
GL_SHORT, GL_UNSIGNED_INT, GL_INT, or GL_FLOAT. Then the last argument is a pointer to an array where the data will be stored so you have to increment the array location and the chunk of texture that will be stored.
I hope that helps.
To read in a pixls format you use
glReadPixels(GLuint x, GLuin y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels);
Replace x, and y with the x and y positions of the lower left of the area you want to read. Replace width and height with the width and height of the area to scane. Replace the format with GL_RGB or GL_RGBA. Then type replace with the type of data the pixel is GL_UNSIGNED_BYTE, GL_BYTE, GL_BITMAP, GL_UNSIGNED_SHORT,
GL_SHORT, GL_UNSIGNED_INT, GL_INT, or GL_FLOAT. Then the last argument is a pointer to an array where the data will be stored so you have to increment the array location and the chunk of texture that will be stored.
I hope that helps.
A man walks into a bar.....ouch!?! Ya get it, do ya huh huh well....awww I give up.
ok that helps, but there is still ONE more problem.
When i use glReadPixels, how do i make it read from the image?
if you dont understand, i will try to explain more :-)
thx
When i use glReadPixels, how do i make it read from the image?
if you dont understand, i will try to explain more :-)
thx
--------------------------------------------------------------If it sounds like a good idea, do it. It is much harder to get permission than it is to apologize.
The image is read from the frame buffer. Im not to clear on ths next part. You read the frame buffer and then you use glReadPixels. To read a buffer use glReadBuffer use the index in VC++ to look it up if you don''t have VC++ I will give you the snippet.
A man walks into a bar.....ouch!?! Ya get it, do ya huh huh well....awww I give up.
man im still having problems...
when you read from the frame buffer, that is just the screen, right? but i want to read from a texture...
i must be missing something...
thanks for putting up with me so far :-P
Edited by - RPGman on July 11, 2001 7:59:37 PM
when you read from the frame buffer, that is just the screen, right? but i want to read from a texture...
i must be missing something...
thanks for putting up with me so far :-P
Edited by - RPGman on July 11, 2001 7:59:37 PM
--------------------------------------------------------------If it sounds like a good idea, do it. It is much harder to get permission than it is to apologize.
Actualy the texture has to be storred in a buffer so find the buffer it''s eather the front or back and read the pixels. look at the site mentiond in my question it tells you ho if you read ways in.
A man walks into a bar.....ouch!?! Ya get it, do ya huh huh well....awww I give up.
I do this exact thing in my book with a BMP (OpenGL Game Programming).
Get some TGA loading code in a function and return the actual image data from the function. This image data is a stream of either BGRBGRBGRBGRBGR... or BGRABGRABGRABGRABGRA...you can do a little for loop to switch it to the standard RGB(A) format after you load the data.
Anyways, you have this block of image data in an array, and you want to use each pixel of this image data to build a heightmap. I'm not going to do it for you, but here's the InitializeTerrain() function from the example program I did for the book that created a heightmap from a greyscale BMP:
Well, have fun.
Kevin
Get some TGA loading code in a function and return the actual image data from the function. This image data is a stream of either BGRBGRBGRBGRBGR... or BGRABGRABGRABGRABGRA...you can do a little for loop to switch it to the standard RGB(A) format after you load the data.
Anyways, you have this block of image data in an array, and you want to use each pixel of this image data to build a heightmap. I'm not going to do it for you, but here's the InitializeTerrain() function from the example program I did for the book that created a heightmap from a greyscale BMP:
|
Well, have fun.
Kevin
Admin for GameDev.net.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement