A way to set GL fog color?

All topics about ZGameEditor goes here.

Moderator: Moderators

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

A way to set GL fog color?

Post by jinxtengu »

Hello,
I was wondering if anyone knows a way to set the GL fog color?
I'd like to make a game where the fogcolor is blue or maybe white.

I have tried a number of different ways but, all came up with various error messages,



Defining the function glfogfv(Gl_fog_color,fogcolor); I get an unknown function error,
any thoughts ? :D
User avatar
VilleK
Site Admin
Posts: 2277
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Re: A way to set GL fog color?

Post by VilleK »

Hi,

How did you define the function?

Did you try this:
1. Right-click in project tree on a folder
2. Select "Add from library...", "External libraries", "Open GL 4.0 graphics"

Now you should be able to use OpenGL functions like this:

Code: Select all

float[4] fogcolor = {1.0, 0.0, 0,0, 1.0};
glFogfv(GL_FOG_COLOR, fogcolor);
jinxtengu
Posts: 122
Joined: Wed Oct 14, 2009 2:05 pm
Contact:

Re: A way to set GL fog color?

Post by jinxtengu »

Hi,

To answer your question, I was defining glFogfv(GL_FOG_COLOR, fogcolor);
inside the Opengl32 library. It was giving me an Invalid primary error message,
however when I imported the built in Opengl library as you suggested, and then defined the function it worked.
Turns out I was using a depreciated version of Opengl, whoops :oops: :mrgreen: anyway problem solved.

Thanks heaps for the speedy response, I will be sure to post games here when I finish them :)

-----------------------------------------------------------------------------------------
Edit
Actually I have a follow up, basic question to ask; how exactly does the function GL_FOG_COLOR get called in order to change the color?
I perhaps hastily posted my reply, assuming I would figure it out quickly, but after trying (what I would imagine) all the most obvious
ways of calling this, I thought I would ask.

I assume it must have a structure like: fogcolor(1,0,1,1);
placed in on, on update or on render or is this only called once, such as at the beginning of an appstate?
User avatar
Kjell
Posts: 1883
Joined: Sat Feb 23, 2008 11:15 pm

Re: A way to set GL fog color?

Post by Kjell »

Hi jinxtengu,

Below is a simple example ( containing 8 white boxes and a animated camera ) that enables blue exponential fog with a density of 0.05:

Code: Select all

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

const int GL_FOG = 0x0B60;
const int GL_FOG_DENSITY = 0x0B62;
const int GL_FOG_COLOR = 0x0B66;

//

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

glEnable(GL_FOG); // Enable fog
// Default fog mode is GL_EXP
glFogf(GL_FOG_DENSITY, 0.05); // Set fog density ( default is 1 )
glFogfv(GL_FOG_COLOR, vector4(0, 0, 1, 1)); // Set fog color to blue

// Spawn a couple of boxes for demonstration purposes

for(int i=0; i<8; i++)
{
  Box.Position.X = random(0, 8);
  Box.Position.Y = random(0, 4);
  Box.Position.Z = random(0, 8);

  createModel(Box);
}]]>
      </Expression>
    </ZExpression>
  </OnLoaded>
  <OnUpdate>
    <ZExpression>
      <Expression>
<![CDATA[// Animate the camera

App.CameraPosition.Z = 8+sin(App.Time)*8;]]>
      </Expression>
    </ZExpression>
  </OnUpdate>
  <Content>
    <Model Name="Box">
      <OnRender>
        <RenderMesh Mesh="BoxMesh"/>
      </OnRender>
    </Model>
    <Mesh Name="BoxMesh">
      <Producers>
        <MeshBox/>
      </Producers>
    </Mesh>
  </Content>
</ZApplication>
Most of the information related to fog in OpenGL can be found here.

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

Re: A way to set GL fog color?

Post by jinxtengu »

Many thanks Kjell.
Post Reply