glBlend calls only work from within display?

hi there all,

I’m a little confused as to the following bug:

I have a global: boolean g_bFog = true;
I set the default state in the init block to enable the fog (glEnable(GL_FOG)), but I try to map a kep press to change the boolean status of the fog but nothing changes.

The app detects the keypress and outputs to the cmd line what state it should be but the state does not visibly change.

The only way around this is to add code to my display section which detects what the current state of g_bFog is and enables or disables the effect:

if (g_bFog)
gl.glEnable(GL_FOG)
else
gl.glDisable(GL_FOG)

Do I have to put this code in the display section for the code to be disabled / enabled, or should the keypress code suffice?

Thanks

ribot.

try this

if( FOG_ENABLE )
{
	glEnable( GL_FOG );
	glFogi( GL_FOG_MODE, GL_LINEAR );
	glFogfv( GL_FOG_COLOR, fog_color );
	glFogi(GL_FOG_START, 100);
	glFogi(GL_FOG_END, 300);
}

else {glDisable( GL_FOG );}

Thanks for replying mancha.

But, I already have this in my init:

gl.glFogi(GL_FOG_MODE, GL_EXP2);
gl.glFogfv(GL_FOG_COLOR, fogColour);
gl.glFogf(GL_FOG_DENSITY, g_fogDensity);
gl.glHint(GL_FOG_HINT, GL_DONT_CARE);
gl.glFogf(GL_FOG_START, 0.0f);
gl.glFogf(GL_FOG_END, 10.0f);
gl.glEnable(GL_FOG);

It’s just that I want to know if I have to put code like you’ve given me, into the main display block to actually change the state of the effect.

I would really like to just keep the state changing code to the keyPress command:

  case KeyEvent.VK_F: {
// =======================
    g_bFog = !g_bFog;
if (g_bFog) {
  gl.glEnable(GL_FOG);
} else {
  gl.glDisable(GL_FOG);
}
System.out.println("fog change: " + g_bFog);
break;
// =====================
  }

Hope you understand what I’m trying to say!

Thanks

ribot