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 .
Disabling Fog per model?
Moderator: Moderators
Re: Disabling Fog per model?
Hi jinxtengu,
K
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>
Re: Disabling Fog per model?
Thanks Kjell!!
It works!
It works!