Disabling Fog per model?

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
jinxtengu
Posts: 122
Joined: Wed Oct 14, 2009 2:05 pm
Contact:

Disabling Fog per model?

Post by jinxtengu »

Hello, I started working on a game that uses glFOG.
With the way that I'm using the fog code, it's getting called during the Appstates ONupdate,
so this applies the fog to all objects that are visible. The thing is, I wanted to have a background visible, without it being simply black, (which is what it's currently doing, due to being far from the camera, and having fog rendered)
however im not sure how to disable GlFog, per model.

I was wondering if anyone knows an easy way to do this?

I can post code if necessary :mrgreen: .
User avatar
Kjell
Posts: 1915
Joined: Sat Feb 23, 2008 11:15 pm

Re: Disabling Fog per model?

Post by Kjell »

Hi jinxtengu,
jinxtengu wrote: Tue Apr 18, 2023 1:12 pmI was wondering if anyone knows an easy way to do this?
Sure, you can simply use glEnable(GL_FOG) / glDisable(GL_FOG) :) Below is a simple example of a scene that contains a bunch of boxes ( that have fog enabled ) and a sky-box ( that has fog disabled ). The sky-box doesn't follow the camera on purpose just so you can look at it from a distance. Use the arrow keys to walk around.

Code: Select all

<?xml version="1.0" encoding="iso-8859-1" ?>
<ZApplication Name="App" Caption="ZGameEditor application" CameraPosition="0 0 0" LightPosition="0.25 0 1" FileVersion="2">
  <OnLoaded>
    <ZExternalLibrary ModuleName="opengl32">
      <Source>
<![CDATA[//

const int GL_FOG = 0x0B60,
          GL_FOG_DENSITY = 0x0B62;

//

void glDisable(int cap){}
void glEnable(int cap){}
void glFogf(int pname, float param){}]]>
      </Source>
    </ZExternalLibrary>
    <ZExpression>
      <Expression>
<![CDATA[//

glFogf(GL_FOG_DENSITY, 0.1); // Set fog density a bit lower than default
glEnable(GL_FOG); // Enable fog

//

createModel(Sky);

//

for(int i=0; i<32; i++)
{
  Box.Position.X = random(0, 16);
  Box.Position.Z = random(0, 16);

  createModel(Box);
}]]>
      </Expression>
    </ZExpression>
  </OnLoaded>
  <OnUpdate>
    <Repeat Name="AxisRepeat" Count="2">
      <OnIteration>
        <ZExpression>
          <Expression>
<![CDATA[//

int i = AxisRepeat.Iteration;

//

Axis[i] = 0;

//

AxisPositive.CharCode = i ? 38 : 39;
AxisNegative.CharCode = i ? 40 : 37;]]>
          </Expression>
        </ZExpression>
        <KeyPress Name="AxisPositive" CharCode="38">
          <OnPressed>
            <ZExpression>
              <Expression>
<![CDATA[//

Axis[AxisRepeat.Iteration]++;]]>
              </Expression>
            </ZExpression>
          </OnPressed>
        </KeyPress>
        <KeyPress Name="AxisNegative" CharCode="40">
          <OnPressed>
            <ZExpression>
              <Expression>
<![CDATA[//

Axis[AxisRepeat.Iteration]--;]]>
              </Expression>
            </ZExpression>
          </OnPressed>
        </KeyPress>
      </OnIteration>
    </Repeat>
    <ZExpression>
      <Expression>
<![CDATA[//

float dt = App.DeltaTime;

//

App.CameraRotation.Y += Axis[0]*0.25*dt;

//

if(Axis[1])
{
  float a = App.CameraRotation.Y*PI*2;

  App.CameraPosition.X += Axis[1]*4*sin(a)*dt;
  App.CameraPosition.Z -= Axis[1]*4*cos(a)*dt;
}]]>
      </Expression>
    </ZExpression>
  </OnUpdate>
  <Content>
    <Array Name="Axis" SizeDim1="2"/>
    <Model Name="Box">
      <OnRender>
        <UseMaterial Material="BoxMaterial"/>
        <RenderMesh Mesh="BoxMesh"/>
      </OnRender>
    </Model>
    <Mesh Name="BoxMesh">
      <Producers>
        <MeshBox/>
      </Producers>
    </Mesh>
    <Material Name="BoxMaterial" Shading="1"/>
    <Model Name="Sky">
      <OnRender>
        <ZExpression Comment="Disable fog">
          <Expression>
<![CDATA[//

glDisable(GL_FOG);]]>
          </Expression>
        </ZExpression>
        <UseMaterial Material="SkyMaterial"/>
        <RenderMesh Mesh="SkyMesh"/>
        <ZExpression Comment="Enable fog">
          <Expression>
<![CDATA[//

glEnable(GL_FOG);]]>
          </Expression>
        </ZExpression>
      </OnRender>
    </Model>
    <Mesh Name="SkyMesh">
      <Producers>
        <MeshBox Scale="-1 1 1"/>
      </Producers>
    </Mesh>
    <Material Name="SkyMaterial" Shading="1" Color="0 0.5 1 1" Light="0" ZBuffer="0"/>
  </Content>
</ZApplication>
K
jinxtengu
Posts: 122
Joined: Wed Oct 14, 2009 2:05 pm
Contact:

Re: Disabling Fog per model?

Post by jinxtengu »

Thanks Kjell!!
It works! :D :D
Post Reply