-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);}
我看了很多教程,但我沒有」找到解決方案。每一個技巧真的很感激!提前致謝!
解釋「它不工作」的一部分...... – SigTerm