[SOLVED] Issue with face culling

How can i make sure in OpenGL the correct sides of the face are culling

My code to enable culling :


GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glCullFace(GL11.GL_FRONT);

My issue is, is that this works fine for the top, left, right, front and back faces, but the bottom face it culls the wrong side, so the face can be seen when inside the cube not outside.

Quick note : I’m using VBOs so manually using something like this :


GL11.glFrontFace(GL11.GL_CW);

(I think that’s the correct function)

I don’t think would be possible

Then your probably rendering the bottom the wrong way.
Just render it backwards?

How do you mean render it backwards, here is my code :


	public static void addCubeBottomFace(BufferObject v, float x, float y, float z) {
		v.addVertex(x, y + 1, z + 1, 0, 1);
		v.addVertex(x + 1, y + 1, z + 1, 1, 1);
		v.addVertex(x + 1, y + 1, z, 1, 0);
		v.addVertex(x, y + 1, z, 0, 0);
	}

Just flip the order:


	public static void addCubeBottomFace(BufferObject v, float x, float y, float z) {
		v.addVertex(x, y + 1, z, 0, 0);
		v.addVertex(x + 1, y + 1, z, 1, 0);
		v.addVertex(x + 1, y + 1, z + 1, 1, 1);
		v.addVertex(x, y + 1, z + 1, 0, 1);
	}

It’s easy!

  • Longor1996

Didn’t work :S

How about: Try to swap the first and last vertex instructions.


	public static void addCubeBottomFace(BufferObject v, float x, float y, float z) {
		v.addVertex(x, y + 1, z, 0, 0);
		v.addVertex(x + 1, y + 1, z + 1, 1, 1);
		v.addVertex(x + 1, y + 1, z, 1, 0);
		v.addVertex(x, y + 1, z + 1, 0, 1);
	}

  • Longor1996

Didn’t work either ???

Could this be an issue with my graphics card? I highly doubt it myself.

The wierd thing is, i render the top face like this :


		v.addVertex(x, y, z, 0, 0);
		v.addVertex(x + 1, y, z, 1, 0);
		v.addVertex(x + 1, y, z + 1, 1, 1);
		v.addVertex(x, y, z + 1, 0, 1);

and the bottom face like this :


		v.addVertex(x, y + 1, z, 0, 0);
		v.addVertex(x + 1, y + 1, z, 1, 0);
		v.addVertex(x + 1, y + 1, z + 1, 1, 1);
		v.addVertex(x, y + 1, z + 1, 0, 1);

The only thing different between these two faces, is the y coordinate (bearing in mind the culling of the top face works perfectly)

hmm… another update :

I’ve just found that all the other faces aren’t working either

Only 3 of the 6 faces work, and the ones that don’t seem to be the ones with constant

y+1
y+1
y+1
y+1

x+1
x+1
x+1
x+1

z+1
z+1
z+1
z+1

https://sphotos-a.xx.fbcdn.net/hphotos-ash4/295670_571331559578554_143944326_n.jpg

It sounds to me like the problem is that you are using the same points except for your y. If you look at the winding of your top face it is fine but if you simply translate the same points downwards you are keeping the same winding. Your bottom face should have an opposite winding because you need to have all the “out” sides of your polygons facing out of the cube. You should only be able to see the “out” side of either your top face or your bottom face never bot simultaneously. (the pic shows the wrong way to do it) :slight_smile:

Wow, well I’m stupid.

I guess all i really needed to do was change the order of vertexes around :-\

Sorry for wasting everyone’s time on this :frowning:

Thank you for all the help though ;D

I hope that helped. I’m new and still getting my mind wrapped around it ;D