gonna try again...

Started by
2 comments, last by Nibbles 23 years ago
hi, was wonder how to read the pixels of a bitmap for a heightfield.. can i just use the same technique to load the bitmap as i would to load textures for texturemapping and whatnot? and if so.. how do i tell glReadPixels to read the pixels for the bitmap? i''m browsing through the red book, but i must be missing something. thanks, Scott "If you try and don''t succeed, destroy all evidence that you tried."
Advertisement
you dont get opengl to read the pixels - you need to do that yourself...

load your bitmap, and then do something like this*:

char *bitmap; // with all the data loaded
GLfloat *heightfield; // should be a block of memory 3x
// the number of pixels in the bitmap

for(int i=0; i for(int j=0; j
heightfield[(i*3)*bitmap_width+j] = (GLfloat)i;
heightfield[(i*3)*bitmap_width+j+1] = (GLfloat)bitmap[i*bitmap_width+j];
heightfield[(i*3)*bitmap_width+j+2] = (GLfloat)j;
}
}

or something like that... you have all your vertex data in an array now, and you can throw it straight to the card (with some indices for triangle strips - glDrawElements or somesuch.. Red Book page 72 (second edition))

sorry that code''s sloppy.. I was going for clarity, and I know it''s horribly inoptimal, but I hope you get the idea.

Hope this helps - mail me if it doesn''t.





I used to be indecisive. Now I''m not so sure...
_________________________________I used to be indecisive. Now I'm not so sure...
well, gonna try this:

  GLfloat *heightfield;for (int x=0;x<TextureImage[0]->sizeX;x++) {  for (int y=0;y<TextureImage[0]->sizeY;y++) {    heightfield[(x*3)*TextureImage[0]->sizeX+y] = (GLfloat)x;    heightfield[(x*3)*TextureImage[0]->sizeX+y+1] = (GLfloat)TextureImage[0]->data;    heightfield[(x*3)*TextureImage[0]->sizeX+y+2] = (GLfloat)y;  }}  


but on the line:
  heightfield[(x*3)*TextureImage[0]->sizeX+y+1] = (GLfloat)TextureImage[0]->data;  


i''m not sure what to put instead of bitmap[i*bitmap_width+j]; as you put in your example.

"If you try and don''t succeed, destroy all evidence that you tried."
Basically, what you want to put there is a height value based on the value of the TextureImage at that point.

if your palette is set up right, the data you store in the image masically means - if I''m a light pixel I''m up high, if I''m dark, I''m down low.

If you have a 256 colour pcx (what I use) you should be able to get plenty of variation.

I dont quite see why you''re bothering to make the base image a texture - greyscale terrain can be pretty boring

I''d just load it into a temporary malloc, then get rid of it when you''ve filled the vertex array.

please mail me if this isnt any help



I used to be indecisive. Now I''m not so sure...
_________________________________I used to be indecisive. Now I'm not so sure...

This topic is closed to new replies.

Advertisement