Only objects with textures are visible

So, I changed my initGL() function to include lighting in my game. Works great for textured objects, but If I make a colored cube with no texture, I don’t see it. Here’s my initGL() function:

protected void initGL() {
		int width = display_parent.getWidth();
		int height = display_parent.getHeight();
		GL11.glEnable(GL11.GL_TEXTURE_2D); // Enable Texture Mapping
        GL11.glShadeModel(GL11.GL_SMOOTH); // Enable Smooth Shading
        GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
        GL11.glClearDepth(1.0f); // Depth Buffer Setup
        GL11.glEnable(GL11.GL_DEPTH_TEST); // Enables Depth Testing
        GL11.glDepthFunc(GL11.GL_LEQUAL); // The Type Of Depth Testing To Do

        // Calculate The Aspect Ratio Of The Window
        GLU.gluPerspective(45.0f, (float) width / (float) height, height, -height);
        GL11.glMatrixMode(GL11.GL_MODELVIEW); // Select The Modelview Matrix

        // Really Nice Perspective Calculations
        GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
        ByteBuffer temp = ByteBuffer.allocateDirect(16);
        temp.order(ByteOrder.nativeOrder());
        GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, (FloatBuffer)temp.asFloatBuffer().put(lightAmbient).flip());              // Setup The Ambient Light
        GL11.glLight(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, (FloatBuffer)temp.asFloatBuffer().put(lightDiffuse).flip());              // Setup The Diffuse Light
        GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION,(FloatBuffer)temp.asFloatBuffer().put(lightPosition).flip());         // Position The Light
        GL11.glEnable(GL11.GL_LIGHT1);
        
        GL11.glEnable(GL11.GL_LIGHTING);
	}

Anyone see anything wrong with it?

I’d guess you keep a texture bound and just don’t send texture coordinates, right? glTexCoord works just like glColor, meaning that if you don’t specify texture coordinates for the next glVertex calls then they are all going to use the last value. That means that the texture is going to sample at a single location and put that color on the whole triangle/quad/line/whatever, which in your case might be black. Try to either unbind the texture (glBindTexture(GL_TEXTURE_2D, 0):wink: or disable texturing (glDisable(GL_TEXTURE_2D);).

I changed this:

GLU.gluPerspective(45.0f, (float) width / (float) height, height, -height);

to this:

GL11.glOrtho( -width/2, width/2, -height/2, height/2, -height, height );

And problem solved! Still not sure why, though. Can someone explain?

the zNear, zFar values are a bit off.

GLU.gluPerspective(45.0f, (float) width / (float) height, nearZero, over9000);

So, this should work?

GLU.gluPerspective(45.0f, (float) width / (float) height, .1f, height);

Cause it made my objects invisible again. :frowning:

Then you aim your camera in the wrong direction (the objects are behind the camera)