Hello,
I am trying to load a height map image file (in PPM format ) into a QPixmap (would this be the correct type to store and access grayscale values for terrain rendering in OpenGL, rather than a QByteArray?) but, do not exactly understand what goes into the QPixmap.load(??) parameters and if QPixmap.index(x,y) will yield the color/integer values properly. These are the relevant parts of my code to what I am trying to achieve:
==========================================
//-----Heightfield.h-----//
class Heightfield {
public:
void Create(char *hFilename);
void Render(void);
QPixmap hHeightField;
private:
int hmHeight;
int hmWidth;
};
//-----Heightfield.cpp-----//
void Heightfield::Create(char *hFilename) {
hHeightField.load(hFilename, ???); <----- const char*format =0?
hmHeight = hHeightField.height();
hmWidth = hHeightField.width();
}
void Heightfield::Render() {
// x & z because we're mapping terrain on that plane
glBegin(GL_POINTS);
for (int hmX = 0; hmX < hmWidth; hmX++) {
for (int hmZ = 0; hmZ < hmHeight; hmZ++)
glVertex3f(hmX, hHeightField.index(hmX,hmZ), hmZ); // plot heights for the corresponding pt in x/z-plane
}
glEnd();
}
//-----glwidget.cpp-----//
**beforehand created Heightfield hField;
In InitializeGL():
hField.Create("map.ppm");
In paintGL():
// call terrain rendering function
glPushMatrix();
hField.Render();
glPopMatrix();
==========================================
This is what I got from Qt's refrence library:
bool load ( const QString & fileName, const char * format = 0, ColorMode mode = Auto )
bool load ( const QString & fileName, const char * format, int conversion_flags )
Any help will be greatly appreciated; thank you for regarding my question!
- Alessandra

Reply With Quote

