| Operator?

Started by Nark, February 23, 2005, 22:05:24

Previous topic - Next topic

Nark

GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);          // Clear The Screen And The Depth Buffer


I understand that GL11.glClear first passes GL11.GL_COLOR and when that was successful GL11.GL_DEPTH_BUFFER_BIT?

But that seems to be wrong because my experiment
private static void test(String testtext)
{
 	System.out.println(testtext);
}

public static void main(String args[])
{
 	...
 	test("test 1" | "test 2");
 	...
}

didn't work.

princec

No! That is a binary OR operatator; those two GL constants just refer to different bits in an int. GL checks each bit and clears the appropriate buffers.

Cas :)

funsheep

if you assume that GL_COLOR_BUFFER_BIT is equal to 2 and GL_DEPTH_BUFFER_BIT equal to 8:

than the int in binary of GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT is ...01010

where the left 1 stands for the 8 and the right one for 2. when you now go there with

(merged_int & GL_COLOR_BUFFER_BIT > 0)  it will return true. so opengl knows that you want to clear the GL_COLOR_BUFFER.