Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Strange behaviour with glTranslatef()

Started by julien1486 Feb 23, 2009 at 10:53 AM 0 replies 550+ views
Original Post
julien1486
julien1486
Hi there ! I'm new to openGL and I'm reading the red book. I want to draw a cube which move slowly on the z axis until a fixed value. So I declare this variables :

private float maxZTranslation = -6.0f;
private float currentZTranslation = 0.0f;

and here is my render() function :

private void render() {
        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);          // Clear The Screen And The Depth Buffer
        GL11.glColor3f(1.0f, 1.0f, 1.0f);
        GL11.glLoadIdentity();                          // Reset The Current Modelview Matrix
        
        GL11.glTranslatef(0.0f, 0.0f, currentZTranslation);
                
        GL11.glBegin(GL11.GL_QUADS);
                .....                //Drawing each faces
        GL11.glEnd();
        
        if(currentZTranslation>maxZTranslation){
        	currentZTranslation -= 0.05f;
        }
    }

and the results is weird... My screen is blank (that is because the cube is first draw at 0,0,0) and after one second or two my screen is black and that's all. If I directly put currentZTranslation = -6.0f it's ok, the cube is correctly displayed. What's wrong in my code ? :-( Thanks a lot for your help !
julien1486
julien1486
I've posted the same thing in "Beginner" which seems more appropriate. Please delete this topic.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.