3

(我已经更新了新的更好的代码)

http://www.flickr.com/photos/pkerkm/8251188947/in/photostream 好方向

http://www.flickr.com/photos/pkerkm/8252258464/in/photostream 不好的方向

我们正在使用 SOIL 库 C++ openGL

我们在显示的其中一张图像上绘制了 N、S、W、E 符号,因为我们认为图像被翻转或显示不正确。我们是对的,但不确定为什么以及如何解决它。我们的W在上,E在下,S在右,N在左。这意味着,符号 N 在左侧,至于它应该在上面的位置。

这是我们生成 3 维数组和图片的代码。

void genTex(){
texture[0]=SOIL_load_OGL_texture // load an image file directly as a new OpenGL      texture 
    (
        "C:\\Users\\Pkerkm\\Documents\\Visual Studio 2010\\Projects\\files\\gameprojecgraphics\\bloodwall2.png",
        SOIL_LOAD_AUTO,
        SOIL_CREATE_NEW_ID,
        SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
    );
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
}

void /*GraphicsEngine::*/generateMap(){
  int i, k, j;
  double coordinates[8][3];
  for(i=0; i<MAPWIDTH; i++){
    for(j=0; j<MAPHEIGHT; j++){
      for(k=0; k<MAPDEPTH; k++){
    if(stage[i][j][k]==0){
      //do nothing
    }
    else if (stage[i][j][k]==1){
      getWallCoordinates(coordinates, i, j, k);
  if(j==0 || stage[i][j-1][k]==0){
        drawWall(coordinates[0],coordinates[1],coordinates[2],coordinates[3],true);
  }
      if(j<MAPHEIGHT-1 && stage[i][j+1][k]==0){drawWall(coordinates[7],coordinates[6],coordinates[5],coordinates[4],false);
  }
  if(i==0 || stage[i-1][j][k]==0){drawWall(coordinates[7],coordinates[4],coordinates[0],coordinates[3],false);
  }
  if(k==MAPDEPTH-1 || stage[i][j][k+1]==0){drawWall(coordinates[7],coordinates[3],coordinates[2],coordinates[6],false);
  }
  if(i==MAPWIDTH-1 || stage[i+1][j][k]==0){drawWall(coordinates[6],coordinates[2],coordinates[1],coordinates[5],false);
  }
  if(k==0 || stage[i][j][k-1]==0){drawWall(coordinates[5],coordinates[1],coordinates[0],coordinates[4],false);
 }
    }
   }
  }
 }
} 
void /*GraphicsEngine::*/drawWall(double a[3],double b[3], double c[3], double d[3], bool floor){
//glColor3f(1.0,0.0,1.0);


if(floor){
    glBindTexture(GL_TEXTURE_2D, texture[1]);
}else{
    glBindTexture(GL_TEXTURE_2D, texture[0]);
}
//GLuint tex;
//glGenTextures(1, &tex);
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_MODULATE );
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

//tex = LoadTexture("wallsprite.png");
//glBindTexture(GL_TEXTURE_2D, tex);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
    //glNormal3f(0, 1, 0);
    glTexCoord2d(0.0,0.0);
    glVertex3dv(a);
    glTexCoord2d(-1.0,0.0);
    //glVertex3dv(b);
    glVertex3dv(d);
    glTexCoord2d(-1.0,-1.0);
    glVertex3dv(c);
    glTexCoord2d(0.0,-1.0);
    //glVertex3iv(d);
    glVertex3dv(b);
glEnd();
/*glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
    glTexCoord2f(0.0, 1.0); glVertex3f(-2.0, 1.0, 0.0);
    glTexCoord2f(1.0, 1.0); glVertex3f(0.0, 1.0, 0.0);
    glTexCoord2f(1.0, 0.0); glVertex3f(0.0, -1.0, 0.0);*/
glDisable( GL_TEXTURE_2D );
 }

}

我认为问题出在此处,但不确定如何解决

void /*GraphicsEngine::*/getWallCoordinates(double coordinates[8][3], double x, double y, double z){
int i;
for(i=0;i<8; i++){
    if((i/4)>=1){
        coordinates[i][1]=BLOCKHEIGHT*(y+1);
    }else{
        coordinates[i][1]=BLOCKHEIGHT*y;
    }
    if((i/2)%2==0){
        coordinates[i][2]=BLOCKDEPTH*z;
    }else{
        coordinates[i][2]=BLOCKDEPTH*(z+1);
    }
    if((i%4)%3==0){
        coordinates[i][0]=BLOCKWIDTH*x;
    }else{
        coordinates[i][0]=BLOCKWIDTH*(x+1);
    }
}

}

4

1 回答 1

2

只需切换 glTexCoord2f 指令即可将纹理旋转 90 度。

于 2012-12-07T00:16:28.593 回答