Why is nothing rendering? - LWJGL

Hey, this is not a question of performance. I’ve for long been using immidiate openGL, when transfering to VBO for performance purposes, I’ve headed into a issue. Nothing is render!? I can’t see anything.

here’s some code…

Window.java


private void render() {
		GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
		
		game.render();
	}

Game.java


public void render() {
		ready3D();
		render3D();
		
		ready2D();
		render2D();
	}
	
	//3D
	private void ready3D() {
		glViewport(0, 0, Display.getWidth(), Display.getHeight());
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		
		gluPerspective(75f, Display.getWidth() / Display.getHeight(), 0.001f, 1000f);
		glMatrixMode(GL_MODELVIEW);
		
		glEnable(GL_DEPTH_TEST);
	}
	private void render3D() {
		world.render(camera);
	}
	
	//2D
	private void ready2D() {
		glClear(1);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		
		glViewport(0, 0, Display.getWidth(), Display.getHeight());
		glOrtho(0, 1, 0, 1, -1, 1);
		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
	}
	private void render2D() {
		
	}

World.java


public void render(Camera camera) {
		chunk.render();
		camera.lookThrough();
	}

Chunk.java


private void rebuildVBO() {
		FloatBuffer vCoords = BufferUtils.createFloatBuffer(size * size * size * (3 * 4 * 6));
		FloatBuffer cCoords = BufferUtils.createFloatBuffer(size * size * size * (4 * 4 * 6));
		
		for(int x = 0; x < size; x++) {
			for(int y = 0; y < size; y++) {
				for(int z = 0; z < size; z++) {
					
					vCoords.put(Shape.createCubeVerticies(x, y, z, 0.5f));
					cCoords.put(Shape.getCubeColors());
					
				}
			}
		}
		
		vCoords.flip();
		cCoords.flip();
		
		glBindBuffer(GL_ARRAY_BUFFER, vId);
		glBufferData(GL_ARRAY_BUFFER, vCoords, GL_STATIC_DRAW);
		glBindBuffer(GL_ARRAY_BUFFER, 0);
		
		glBindBuffer(GL_ARRAY_BUFFER, cId);
		glBufferData(GL_ARRAY_BUFFER, cCoords, GL_STATIC_DRAW);
		glBindBuffer(GL_ARRAY_BUFFER, 0);
	}
	
	public void render() {
		glBindBuffer(GL_ARRAY_BUFFER, vId);
		glVertexPointer(3, GL_FLOAT, 0, 0);
		
		glBindBuffer(GL_ARRAY_BUFFER, cId);
		glColorPointer(4, GL_FLOAT, 0, 0L);
		
		glEnableClientState(GL_VERTEX_ARRAY);
		glEnableClientState(GL_COLOR_ARRAY);
		
		glDrawArrays(GL_QUADS, 0, size * size * size * (3 * 4 * 6));
		
		glDisableClientState(GL_VERTEX_ARRAY);
		glDisableClientState(GL_COLOR_ARRAY);
	}


public static float[] createCubeVerticies(float x, float y, float z, float size) {
		return new float[] {
			//Bottom face
			x, y, z + size,
			x + size, y, z + size,
			x + size, y, z,
			x, y, z,
			
			//Top face
			x, y + size, z,
			x + size, y + size, z,
			x + size, y + size, z + size,
			x, y + size, z + size,
			
			//Front face
			x, y, z,
			x + size, y, z,
			x + size, y + size, z,
			x, y + size, z,
			
			//Back face
			x, y + size, z + size,
			x + size, y + size, z + size,
			x + size, y, z + size,
			x, y + size, z,
			
			//Left face
			x + size, y, z,
			x + size, y, z + size,
			x + size, y + size, z + size,
			x + size, y + size, z,
			
			//Right face
			x, y, z + size,
			x, y, z,
			x, y + size, z,
			x, y + size, z + size,
			
		};
	}
	
	public static float[] getCubeColors() {
		
		return new float[] {
			1, 1, 1, 1,
			1, 1, 1, 1,
			1, 1, 1, 1,
			1, 1, 1, 1,
			
			1, 1, 1, 1,
			1, 1, 1, 1,
			1, 1, 1, 1,
			1, 1, 1, 1,
			
			1, 1, 1, 1,
			1, 1, 1, 1,
			1, 1, 1, 1,
			1, 1, 1, 1,
			
			1, 1, 1, 1,
			1, 1, 1, 1,
			1, 1, 1, 1,
			1, 1, 1, 1,
			
			1, 1, 1, 1,
			1, 1, 1, 1,
			1, 1, 1, 1,
			1, 1, 1, 1,
			
			1, 1, 1, 1,
			1, 1, 1, 1,
			1, 1, 1, 1,
			1, 1, 1, 1,
		};
	}

Camera.java


public void lookThrough() {
		GL11.glLoadIdentity();
        GL11.glRotatef(pitch, 1.0f, 0.0f, 0.0f);
        GL11.glRotatef(yaw, 0.0f, 1.0f, 0.0f);
        GL11.glTranslatef(x, y, z);
        
        System.out.println(x + ", " + y + ", " + z);
        System.out.println(pitch + ", " + yaw);
	}

Any help is appritated

Do you clear the depth buffer?

If you’re talking about

GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);

then, yes. I updated the post.

Wrong order?

Well, previously when I’ve rendered in immidiate mode I’ve always rendered and then translated(Looked through) to the current location. Anyway changing the order doesn’t seem to show any effect.

Adding this before looking through…



		GL11.glTranslatef(-1.5f, 0.0f, -6.0f); // Move Left And Into The Screen

		GL11.glBegin(GL11.GL_TRIANGLES); // Start Drawing The Pyramid
		GL11.glColor3f(1.0f, 0.0f, 0.0f); // Red
		GL11.glVertex3f(0.0f, 1.0f, 0.0f); // Top Of Triangle (Front)
		GL11.glColor3f(0.0f, 1.0f, 0.0f); // Green
		GL11.glVertex3f(-1.0f, -1.0f, 1.0f); // Left Of Triangle (Front)
		GL11.glColor3f(0.0f, 0.0f, 1.0f); // Blue
		GL11.glVertex3f(1.0f, -1.0f, 1.0f); // Right Of Triangle (Front)

		GL11.glColor3f(1.0f, 0.0f, 0.0f); // Red
		GL11.glVertex3f(0.0f, 1.0f, 0.0f); // Top Of Triangle (Right)
		GL11.glColor3f(0.0f, 0.0f, 1.0f); // Blue
		GL11.glVertex3f(1.0f, -1.0f, 1.0f); // Left Of Triangle (Right)
		GL11.glColor3f(0.0f, 1.0f, 0.0f); // Green
		GL11.glVertex3f(1.0f, -1.0f, -1.0f); // Right Of Triangle (Right)

		GL11.glColor3f(1.0f, 0.0f, 0.0f); // Red
		GL11.glVertex3f(0.0f, 1.0f, 0.0f); // Top Of Triangle (Back)
		GL11.glColor3f(0.0f, 1.0f, 0.0f); // Green
		GL11.glVertex3f(1.0f, -1.0f, -1.0f); // Left Of Triangle (Back)
		GL11.glColor3f(0.0f, 0.0f, 1.0f); // Blue
		GL11.glVertex3f(-1.0f, -1.0f, -1.0f); // Right Of Triangle (Back)

		GL11.glColor3f(1.0f, 0.0f, 0.0f); // Red
		GL11.glVertex3f(0.0f, 1.0f, 0.0f); // Top Of Triangle (Left)
		GL11.glColor3f(0.0f, 0.0f, 1.0f); // Blue
		GL11.glVertex3f(-1.0f, -1.0f, -1.0f); // Left Of Triangle (Left)
		GL11.glColor3f(0.0f, 1.0f, 0.0f); // Green
		GL11.glVertex3f(-1.0f, -1.0f, 1.0f); // Right Of Triangle (Left)
		GL11.glEnd();

Will render a triangle, however as I move the triangle stays stationary to the screen, not what is suppose to happen.

Kind of off topic, are you by any chance following a tutorial to do this? On Youtube perhaps?

Not specifally, But I have been trying to understand how to use VBO’s from many tutorials, one of them being from youtube yes. PancakeSimone’s series
https://www.youtube.com/user/pancakesimone/videos

That’s hilarious. That’s my Youtube channel, I made those videos!

Anyway, your issue is that your camera is probably set up wrong or the angle isn’t correct so you cannot see the geometry you are trying to render. Make sure that you are rendering the vertices in front of the camera (usually in front is negative on the z axis).

Well why does it matter?, I can turn around and I still see nothing. I move around and still nothing.

Maybe your camera isn’t working correctly? Do you have face culling on? Try turning it off if you do:


glDisable(GL_CULL_FACE);

If you see your vertices that means your faces are wound the opposite way of what you are culling.

I don’t see anything, it’s all black! :s

Do you color your vertices? Make sure the color isn’t set to black before rendering.

You mentioned before that your vertices weren’t being translated when the camera moves. That leads me to believe that your glTranslate calls are in the wrong order. You want to translate and then draw the vertices in their new positions.

I wouldn’t recommend following my tutorials anymore, the code I wrote wasn’t all that good.

It should be rendering in white now, check the updated code in the first post. Still nothing tho.

Sorry but… bump? Anyone?

Have you tried to call [icode]glGetError();[/icode]?

Sysout that and I get 1281. I’m not sure what that means and google doesn’t seem to give me any great results but I’ll look into it unless someone has the answer already?

You can located which line is outputting this error by putting a check before and after a section of code. If the first check returns 0, and the second check returns something else, then you know that the error is in between those two checks.

Also, why are you calling [icode]glClear(1);[/icode]?

I googled it, I also debuged it with your method, and both showed the same result. The error 1281 is caused by the following line.



		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

From this article as mentioned before, http://blog.nobel-joergensen.com/2013/01/29/debugging-opengl-using-glgeterror/
They describe it, and say it’s suppose to be “glClear(GL_COLOR_BUFFER_BIT);” Which I have so what is wrong?

I don’t know why I call glClear(1); as mentioned before, I’m half-following a tutorial. Sorry if I seem stupid or naive.
However, removing this line, it’s still pitch black!

So you called glGetError like this?


System.out.println("Before: " + glGetError());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
System.out.println("After: " + glGetError());

And they both showed the same error? 1281?


System.out.println("VERY FIRST! " + glGetError());
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		System.out.println("2nd! " + glGetError());

results…


VERY FIRST! 1281
2nd! 0

However, when removing “glClear(1);” the error is no longer printed. The new result is…


VERY FIRST! 0
2nd! 0