gpt4 book ai didi

c++ - 纹理显示不正确 C++ opengl SOIL

转载 作者:太空宇宙 更新时间:2023-11-04 11:57:08 26 4
gpt4 key购买 nike

这是我的问题;

想象一个盒子或立方体,所有边都正确。

如果我们将盒子放在平面上,接触底部的面就是地板或底座。如果底座有一个内部,大多数盒子都有,从外面你将无法正确看到它。

不幸的是,在我的代码中你可以。你有一个房间,而不是一个盒子,我走到房间外面看地板,但我不应该。

我会张贴问题图片和视频,以及一些代码和您可能需要的任何代码。

http://www.youtube.com/watch?v=ml3-OBGNXXA&feature=youtu.be

http://www.flickr.com/photos/pkerkm/8607171993/

http://www.flickr.com/photos/pkerkm/8608276014/

//这是我管理纹理的方式

void /*GraphicsEngine::*/drawWall(double a[3],double b[3], double c[3], double d[3], bool floor){
if(floor){
glBindTexture(GL_TEXTURE_2D, texture[1]);
}else{
glBindTexture(GL_TEXTURE_2D, texture[0]);
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
//gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); // build our texture mipmaps
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_DECAL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_DECAL);
//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glEnable(GL_TEXTURE_2D);
glBegin(GL_QUADS);
glTexCoord2d(0.0,0.0);
glVertex3dv(a);
glTexCoord2d(-1.0,0.0);
glVertex3dv(d);
glTexCoord2d(-1.0,-1.0);
glVertex3dv(c);
glTexCoord2d(0.0,-1.0);
glVertex3dv(b);
glEnd();
}

//这里是reshape函数

void reshape(int w, int h){
//glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
//glLoadIdentity();
gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 200.0);
glMatrixMode(GL_MODELVIEW);
//glTranslatef(0.0, 0.0, -3.6);
//glLoadIdentity();
}

//这里是显示函数

void /*GraphicsEngine::*/display(){
//glClearColor (0.0, 0.0, 0.0, 1.0);
//glLoadIdentity ();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//glShadeModel(GL_FLAT);
//glClearDepth(1.0);
//glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
setPos();
gluLookAt(currentXPos,currentYPos,currentZPos,currentXFace,currentYFace,currentZFace,0,1,0);
generateMap();
graphicsFloor();
int i = 0;
if(projectiles.size()>0){
for(i= 0; i< projectiles.size(); i++){
arrow(projectiles.operator[](i).getXPos(),projectiles.operator[](i).getYPos(),projectiles.operator[](i).getZPos(),0.5,BLOCKWIDTH);
}
projectileMotion();
player.advance();
//glutPostRedisplay();
/*}else if(player.advance()){
glutPostRedisplay();
}*/
}
//glFlush();
glutSwapBuffers();
}

//这是告诉在哪里绘制地板和墙壁的内容

void graphicsFloor(){
int x,z;
//up

for(x=0;x<7;x+=7){
for(z=0;z<105;z+=7){
double a[3] = {x,0,z};
double b[3] = {x+7,0,z};
double c[3] = {x+7,0,z+7};
double d[3] = {x,0,z+7};
drawWall(d,a,b,c,true);
}
}
}

//墙壁

void generateMap(){
int z;
int x;
for(z =0;z<105;z+=7){
double a[3] = {0,0,z};
double b[3] = {0,0,z+7};
double c[3] = {0,MAPHEIGHT,z+7};
double d[3] = {0,MAPHEIGHT,z};
drawWall(d,a,b,c,false);
}
for(z =0;z<42;z+=7){
double a[3] = {7,0,z};
double b[3] = {7,0,z+7};
double c[3] = {7,MAPHEIGHT,z+7};
double d[3] = {7,MAPHEIGHT,z};
drawWall(d,a,b,c,false);
}
}

//这是我加载纹理的方式

void genTex(){

texture[0]=SOIL_load_OGL_texture // load an image file directly as a new OpenGL texture
(
//"C:\\Users\\Eddy\\Desktop\\Senior Project\\Senior Project\\bloodwall2.png",
"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
//SOIL_FLAG_POWER_OF_TWO| SOIL_FLAG_MIPMAPS| SOIL_FLAG_MULTIPLY_ALPHA| SOIL_FLAG_COMPRESS_TO_DXT| SOIL_FLAG_DDS_LOAD_DIRECT| SOIL_FLAG_INVERT_Y

);
glBindTexture(GL_TEXTURE_2D, texture[0]);
}

最佳答案

看起来深度测试被禁用了。启用它:

glEnable(GL_DEPTH_TEST);

如果这不起作用,请确保您有深度缓冲区并重试。

关于c++ - 纹理显示不正确 C++ opengl SOIL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15735837/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com