2012-05-05 35 views
-1

我正在处理高度贴图地形的渲染,除纹理外,一切正常。我必须在整个地形上使用一个jpg文件(使用GLM),但它不起作用!这是我的代码的一部分,仅仅是明确的(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);} 

我看了很多教程,但我没有”找到解决方案。每一个技巧真的很感激!提前致谢!

+3

解释“它不工作”的一部分...... – SigTerm

回答