2012-05-05 14 views
-1

私は高さマップの地形のレンダリングに取り組んでいます。私は全体の地形上で(GLMを使用して)jpgファイルを伸ばす必要がありますが、動作しません!これは私のコードの一部であり、単に(Terreain.cpp)明確にする:OpenGLテクスチャの高さマップ

GLfloat height, width; 

int CreateTerrain::getTextureID(){ 
GLuint textID = glmLoadTexture("bergen-new-terrain.png",GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE,&width, &height); 
return textID; 
} 

float* CreateTerrain::getTexture(){ 
int j = 0; 
float iF = (width/mapCols)/width; 
float jF = (height/mapRows)/height; 
for (int row = 0; row < mapRows; row++) { 
    for (int col = 0; col < mapCols; col++) { 
     terrainTexture[j++] = (float)(float) row/(float)mapRows; 
     terrainTexture[j++] = (float)(float) col/(float)mapCols; 
    } 
} 
return terrainTexture; 
} 

、これはファイルmain.cppにある:

GLuint _textureId; //The id of the texture 
GLuint textID = terrain.getTextureID(); 
float* texture = terrain.getTexture(); 

    void RenderTerrain(){ 
    glEnable(GL_TEXTURE_2D); 
    glBindTexture(GL_TEXTURE_2D,_textureId); 
    glEnable(GL_COLOR_MATERIAL); 
    glTranslatef(-(MAP_COLS*CELL_SIZE)/2, 0, -(MAP_ROWS*CELL_SIZE)/2); 
    glEnableClientState(GL_VERTEX_ARRAY); 
    glEnableClientState(GL_NORMAL_ARRAY); 
    glEnableClientState(GL_TEXTURE_COORD_ARRAY); 
     glVertexPointer(3, GL_FLOAT, 0, vertices ); 
     glNormalPointer(GL_FLOAT, 0, normals); 
     glTexCoordPointer(2,GL_FLOAT,0,texture); 
     for (int row = 0; row < MAP_ROWS - 1; row++) { 
      int i = 0; 
      for (int col = 0; col < MAP_COLS; col++) { 
       indices[i++] = col + (row * MAP_COLS); 
       indices[i++] = col + (row * MAP_COLS) + MAP_COLS; 
      } 
      glPushMatrix(); 
       glDrawElements(GL_TRIANGLE_STRIP, i, GL_UNSIGNED_INT, indices); 
      glPopMatrix(); 
     } 
    glDisableClientState(GL_VERTEX_ARRAY); 
    glDisableClientState(GL_NORMAL_ARRAY); 
    glDisableClientState (GL_TEXTURE_COORD_ARRAY);} 

「私は、チュートリアルをたくさん読んで、私はdidnの解決策を見つける。すべてのヒントは本当に感謝しています!前もって感謝します!

+3

説明が一部「それは動作しません」... – SigTerm

答えて

関連する問題