Pregunta

Here is my problem;

Image a box, or a cube, all sides right.

If we were to put the box on a flat surface, the face touching the bottom, would be the floor or base. if the base had an inside, which most boxes do, from the outside you would not be able to see it right.

Unfortunately, in my code you can. instead of a box, you have a room, in which i go outside the room and see the floor, but i should not.

ill post an image of the problem and a video, as well as some code and any code that you might ask for.

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/

//here is how i manage the textures

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();
}

//here is the reshape function

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();
}

//here is the display function

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();
}

//here is what tells where to draw the floor and the walls

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);
    }
}
}

// the walls

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);
}
}

//and here is how i load up the textures

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]);
}
¿Fue útil?

Solución

It looks like depth testing is disabled. Enable it:

glEnable(GL_DEPTH_TEST);

If that doesn't work, make sure you have a depth buffer and try again.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top