height map and loading bmp

Started by
1 comment, last by sefiroths 17 years, 6 months ago
hi, i have readed this article: www.gamedev.net/reference/articles/article1966.asp i think i have not understood one thing: i have a bmp greyscale image 64x64 pixel, i want to display it in opengl using a quad for each pixel for denugging reason, so i write this code: for(iz=0;iz<m_iSize;iz++){ glTranslatef(-2*m_iSize,2.0f,0.0f); for(ix=0;ix<m_iSize;ix++){ glTranslatef(2.0f,0.0f,0.0f); ucColor=getTrueHeightAtPoint(ix,iz); glColor3f(ucColor,ucColor,ucColor); glBegin(GL_QUADS); // Draw A Quad glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left glVertex3f( 1.0f, 1.0f, 0.0f); // Top Right glVertex3f( 1.0f,-1.0f, 0.0f); // Bottom Right glVertex3f(-1.0f,-1.0f, 0.0f); // Bottom Left glEnd(); } } class CTerrain{ public: Bitmap mappa; .... inline unsigned char getTrueHeightAtPoint( int ix, int iz){ return mappa.data[iz*m_iSize*3+ix*3]; } the image displyed is like expected except a line of different color that is orizontal and at 3/4 of height from the bottom of the image what do you think it could be? thanks [Edited by - sefiroths on October 22, 2006 6:37:06 AM]
Advertisement
The image is like expected except.. ?
Are you sure. I only glanced over the code but from what I see the glTranslate calls are independent of ix and iz, hence you should only see one pixel, since you are drawing them all on top of eachother. You have to change those Translate calls.
On a side note, dont draw one quad per pixel. Just use the bitmap as texture and render that on one quad.

Hope I was of help.

-CProgrammer
i wanted to do a height map, so i needed to know the color of each pixel to attrib to each pixel an altitude, the image displayed was as i wanted but only one row was not colored,
today i have reopened the project and everything seem work well, the translation don't depends on ix,iz because the display function modify the world matrix time after time without a glLoadIdentity or glPushMatrix:
translate(2,0,0)
glbegin(glquads)
ecc..
glend
translate(2,0,0)
glbegin(glquads)
ecc..
glend

produce 2 quads one near the other, i know it's horrible solution but was only for debug, fast to write :)

This topic is closed to new replies.

Advertisement