lwjgl texture culling incorrect

So I've been working on a voxel game engine for the last few days, and have ran into some issues with my cube model.

Here is a screenshot of what is happening: (removed so I could post photo links further down)

All my culling seems to be inverted. I went through stack overflow looking for answers, but all I could find had to do with the render order of the objects.

I tried changing the render order of my faces, but that didn't seem to make a difference to the culling.

Here is my code:

package com.musicalcreeper01.renderer.objects;

import static org.lwjgl.opengl.GL11.*;

public class ModelCube extends Object{

float BLOCK_SIZE = 1;

boolean RenderTop = true;
boolean RenderBottom = true;
boolean RenderBack = true;
boolean RenderFront = true;
boolean RenderLeft = false;
boolean RenderRight = true;

@Override
public void render (){
    glPushMatrix(); 

    // set the color of the quad (R,G,B,A)
    glColor3f(0.5f,0.5f,1.0f);

    glTranslatef(x, y, z);

    // draw quad
    glBegin(GL_QUADS);
    if(texture != null){
        texture.bind();
    }
    if(RenderBack){
        //Back
        glTexCoord3f(BLOCK_SIZE, 0, 0);
        glVertex3f(BLOCK_SIZE, 0, 0);

        glTexCoord3f(0, 0, 0);
        glVertex3f(0, 0, 0);

        glTexCoord3f(0, BLOCK_SIZE, 0);
        glVertex3f(0, BLOCK_SIZE, 0);

        glTexCoord3f(BLOCK_SIZE, BLOCK_SIZE, 0);
        glVertex3f(BLOCK_SIZE, BLOCK_SIZE, 0);

    }
    if(RenderFront){
        //Front
        glTexCoord3f(0, 0, BLOCK_SIZE);
        glVertex3f(0, 0, BLOCK_SIZE);

        glTexCoord3f(0, BLOCK_SIZE, BLOCK_SIZE);
        glVertex3f(0, BLOCK_SIZE, BLOCK_SIZE);

        glTexCoord3f(BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE);
        glVertex3f(BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE);

        glTexCoord3f(BLOCK_SIZE, 0, BLOCK_SIZE);
        glVertex3f(BLOCK_SIZE, 0, BLOCK_SIZE);
    }
    if(RenderRight){
        //Right
        glTexCoord2f(0,BLOCK_SIZE);
        glVertex3f(BLOCK_SIZE,0,BLOCK_SIZE);

        glTexCoord2f(BLOCK_SIZE,BLOCK_SIZE);
        glVertex3f(BLOCK_SIZE,BLOCK_SIZE,BLOCK_SIZE);

        glTexCoord2f(0,BLOCK_SIZE);
        glVertex3f(BLOCK_SIZE,BLOCK_SIZE,0);

        glTexCoord2f(0,0);
        glVertex3f(BLOCK_SIZE,0,0);
    }
    if(RenderBottom){
        //Bottom
        glTexCoord2f(0,BLOCK_SIZE);
        glVertex3f(BLOCK_SIZE,BLOCK_SIZE,0);

        glTexCoord2f(0,0);
        glVertex3f(0,BLOCK_SIZE,0);

        glTexCoord2f(0,BLOCK_SIZE);
        glVertex3f(0,BLOCK_SIZE,BLOCK_SIZE);

        glTexCoord2f(BLOCK_SIZE,BLOCK_SIZE);
        glVertex3f(BLOCK_SIZE,BLOCK_SIZE,BLOCK_SIZE);


    }
    if(RenderLeft){
        //Left
        glTexCoord2f(0,BLOCK_SIZE);
        glVertex3f(0,0,BLOCK_SIZE);

        glTexCoord2f(0,0);
        glVertex3f(0,0,0);

        glTexCoord2f(0,BLOCK_SIZE);
        glVertex3f(0,BLOCK_SIZE,0);

        glTexCoord2f(BLOCK_SIZE,BLOCK_SIZE);
        glVertex3f(0,BLOCK_SIZE,BLOCK_SIZE);

    }
    if(RenderTop){
        //Top
        glTexCoord2f(0,BLOCK_SIZE);
        glVertex3f(BLOCK_SIZE,0,0);

        glTexCoord2f(0,0);
        glVertex3f(0,0,0);

        glTexCoord2f(0,BLOCK_SIZE);
        glVertex3f(0,0,BLOCK_SIZE);

        glTexCoord2f(BLOCK_SIZE,BLOCK_SIZE);
        glVertex3f(BLOCK_SIZE,0,BLOCK_SIZE);

    }
    glEnd();

    glPopMatrix();
}
}

Only thing I could think it might be, it that I'm using quads instead of triangles. I though since a quad has four corners, it would be easier and more efficient then drawing 2 triangles for each side.

Also if anyone cares to give me some tips on optimizing my model, I would really appreciate it :)

I'm fairly new to openGL, I did some work with it a year or two back, and at the time I used triangles, and it worked perfectly. So I'm guessing quads are why it isn't working, but that didn't seem logical to me.

EDIT: I'm assuming it has to do with the normals, but I'm having trouble finding answers for how to use the normal functions.

EDIT 2: I just changed to using gl lists to render my objects, as suggested by Iggy (thanks ;)), and it seems to have fixed some render issues I was getting. Now my row of cubes look like this from the outside: http://i.stack.imgur.com/MYLiO.png and this from the inside: http://i.stack.imgur.com/Ckb9i.png

EDIT 3: Updated to to most recent version.


It looks to me as if your winding order is wrong. Basically you have to specify your vertices in counter-clockwise order to mark them as front facing. Read more here.

As for optimizations you should look into using modern OpenGL with vertex buffer objects. This allows you to compact all your vertices , colors , texture coordinates into one array, and then push it to the GPU with a single call. Again you can read more here. (Excellent tutorials on modern OpenGL)

在这里输入图像描述

链接地址: http://www.djcxy.com/p/34032.html

上一篇: LWJGL GLTranslation添加到previos翻译

下一篇: lwjgl纹理剔除不正确