problem with zBuffer

Started by johnnyh, September 03, 2011, 20:13:51

Previous topic - Next topic

johnnyh

wow, i am just trying to use the zBuffer thechnic by typing "GL11.glEnable(GL_DEPTH_TEST);" but netBeans doesnt recognize "GL_DEPTH_TEST" and tells me that he cannot find the symbol...

I dont know what to do, because everything all works and LWJGl is correctly installed?... :(

Please find my entire code here, its just about drawing a cube :
package testlwjgl4;

import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;


public class TestLWJGL4 {
    private float vitesseDeplacement = 0.1f;
    private float vitesseRotation = 0.5f;
    private float dernierTemps;
    private float temps;
    FPCameraController camera = new FPCameraController(0,0,0);
    private int dx;
    private int dy;
    private float dernierTempsFPS;
    private int FPS;
    private float F=10000;//distance Fog
    
    
    public void start(){
        try {
	    Display.setDisplayMode(new DisplayMode(800,600));
	    Display.create();
	} catch (LWJGLException e) {
	    e.printStackTrace();
	    System.exit(0);
	}
        
        init();
        
        while(!Display.isCloseRequested() && !Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)){
            refresh();
            Display.update();
            Display.sync(60);
        }
        
        Display.destroy();
        }
    ////////////////////////////////////////////////////////////////////////////
    
    
    
    
    
    
    public void init(){
        GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glLoadIdentity();
            GLU.gluPerspective(70, (float)800/600, 1, F);
            //GL11.glOrtho(0, 800, 600, 0,1,1000 );
        GL11.glMatrixMode(GL11.GL_MODELVIEW);
        GL11.glEnable(GL_DEPTH_TEST);
        Mouse.setGrabbed(true);
        dernierTemps=System.nanoTime()/1000000;
        dernierTempsFPS=dernierTemps;
        
    }
    
    public void refresh(){
        temps=System.nanoTime()/1000000;
        float delta = temps-dernierTemps;
        if (temps-dernierTempsFPS > 1000){
            dernierTempsFPS=temps;
            Display.setTitle("FPS : "+FPS);
            FPS=0;
        }FPS++;
        
        float distance = delta*vitesseDeplacement;
        dernierTemps=temps;
        
        dx=Mouse.getDX();
        dy=Mouse.getDY();

        camera.yaw(dx*vitesseRotation);
        camera.pitch(dy*vitesseRotation);

        if (Keyboard.isKeyDown(Keyboard.KEY_Z)){
            camera.avancer(vitesseDeplacement*delta);
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_S)){
            camera.reculer(vitesseDeplacement*delta);
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_Q)){
            camera.pasGauche(vitesseDeplacement*delta);
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_D)){
            camera.pasDroite(vitesseDeplacement*delta);
        }
        
        GL11.glPushMatrix();
        camera.lookThrough();
        
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); 
        
        dessinCube(0,0,-30,20);
        
        
        GL11.glPopMatrix();
        

    }
    
    public void dessinCube(float xc, float yc, float zc, float h){
        GL11.glBegin(GL11.GL_QUADS);

            //face 1
            GL11.glColor3f(1f,0f,0f);
            GL11.glVertex3f(xc-h/2,yc+h/2,zc+h/2);
            GL11.glVertex3f(xc+h/2,yc+h/2,zc+h/2);
            GL11.glVertex3f(xc+h/2,yc-h/2,zc+h/2);
            GL11.glVertex3f(xc-h/2,yc-h/2,zc+h/2);
            
            //face 2
            GL11.glColor3f(0f,1f,0f);
            GL11.glVertex3f(xc+h/2,yc+h/2,zc+h/2);
            GL11.glVertex3f(xc+h/2,yc+h/2,zc-h/2);
            GL11.glVertex3f(xc+h/2,yc-h/2,zc-h/2);
            GL11.glVertex3f(xc+h/2,yc-h/2,zc+h/2);
            
            //face 3
            GL11.glColor3f(0f,0f,1.0f);
            GL11.glVertex3f(xc+h/2,yc+h/2,zc-h/2);
            GL11.glVertex3f(xc-h/2,yc+h/2,zc-h/2);
            GL11.glVertex3f(xc-h/2,yc-h/2,zc-h/2);
            GL11.glVertex3f(xc+h/2,yc-h/2,zc-h/2);
            
            //face 4
            GL11.glColor3f(1f,1f,0f);
            GL11.glVertex3f(xc-h/2,yc+h/2,zc+h/2);
            GL11.glVertex3f(xc-h/2,yc+h/2,zc-h/2);
            GL11.glVertex3f(xc-h/2,yc-h/2,zc-h/2);
            GL11.glVertex3f(xc-h/2,yc-h/2,zc+h/2);
            
            //face 5
            GL11.glColor3f(1f,1f,1.0f);
            GL11.glVertex3f(xc-h/2,yc+h/2,zc+h/2);
            GL11.glVertex3f(xc+h/2,yc+h/2,zc+h/2);
            GL11.glVertex3f(xc+h/2,yc+h/2,zc-h/2);
            GL11.glVertex3f(xc-h/2,yc+h/2,zc-h/2);
            
            //face 6
            GL11.glColor3f(0f,0f,1.0f);
            GL11.glVertex3f(xc-h/2,yc-h/2,zc+h/2);
            GL11.glVertex3f(xc+h/2,yc-h/2,zc+h/2);
            GL11.glVertex3f(xc+h/2,yc-h/2,zc-h/2);
            GL11.glVertex3f(xc-h/2,yc-h/2,zc-h/2);
            
        GL11.glEnd();
    }
    

    public static void main(String[] args) {
        TestLWJGL4 test = new TestLWJGL4();
        test.start();
    }
}

spasi

You forgot GL11. in front of GL_DEPTH_TEST.

It's much better to simply statically import GL classes and use method/tokens immediately.

Without static import:

import org.lwjgl.opengl.GL11;
...
GL11.glEnable(GL11.GL_DEPTH_TEST);


With static import:

import static org.lwjgl.opengl.GL11.*;
...
glEnable(GL_DEPTH_TEST);

johnnyh

for god sake, ty man, I was searching for hours !! :D