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 ?
A way to set GL fog color?
Moderator: Moderators
Re: A way to set GL fog color?
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:
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);
Re: A way to set GL fog color?
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 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?
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 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?
Re: A way to set GL fog color?
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:
Most of the information related to fog in OpenGL can be found here.
K
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>
K
Re: A way to set GL fog color?
Many thanks Kjell.