Ok, here is my initialisation (I use the nehe base code, which calls this)
void GLApplication::init()
{
srand(time(NULL));
l_TimeStarted = timeGetTime();
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glFrontFace(GL_CCW);
glShadeModel(GL_SMOOTH);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,1.4,0.1,5000.0);
gluLookAt(0,300,1000,0,000,0,0,1,0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
CTerraGenerator *gen = new CTerraGenerator();
terr = new GLTerrain(gen->generateTerrain(200,50,50,5,15),50,50);
terr->generateObject(2000,2000,250);
fl_Angle = 0;
float fl_FogColour[4] = {0.5f, 0.8f, 0.9f, 1.0f};
glClearColor(fl_FogColour[0], fl_FogColour[1], fl_FogColour[2], fl_FogColour[3]);
glEnable(GL_FOG);
glFogfv(GL_FOG_COLOR, fl_FogColour);
glFogi(GL_FOG_MODE, GL_LINEAR);
glFogf(GL_FOG_DENSITY, 0.1f);
glFogf(GL_FOG_START, 2000.0f);
glFogf(GL_FOG_END, -200.0f);
}
TerraGenerator and GLTerrain are the objects to create and hold the terrain, then my draw code looks like:
void GLApplication::draw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(fl_Angle, 0,1,0);
glTranslatef(-1000,0,-1000);
terr->draw();
glFlush();
}
Thanks,
-wolfman
Help with fog ...
Hmm.
Setting GL_FOG_DENSITY shouldn't have any effect if you are using GL_LINEAR. GL_FOG_DENSITY only affects GL_EXP and GL_EXP2. (I think!) But, I digress...
I'm not sure if setting GL_FOG_START to 2000 and GL_FOG_END to -200 would cause it, but you were setting it to different values in your above posts and still getting the same effect.
Other than that, I don't see anything suspiciously out of place.
[edited by - Waverider on May 16, 2002 4:55:29 PM]
Setting GL_FOG_DENSITY shouldn't have any effect if you are using GL_LINEAR. GL_FOG_DENSITY only affects GL_EXP and GL_EXP2. (I think!) But, I digress...
I'm not sure if setting GL_FOG_START to 2000 and GL_FOG_END to -200 would cause it, but you were setting it to different values in your above posts and still getting the same effect.
Other than that, I don't see anything suspiciously out of place.
[edited by - Waverider on May 16, 2002 4:55:29 PM]
It's not what you're taught, it's what you learn.
May 16, 2002 04:03 PM
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,1.4,0.1,5000.0);
gluLookAt(0,300,1000,0,000,0,0,1,0);
I''m not quite sure you want that gluLookAt there. Once you set up the projection matrix for your frustum, you shouldn''t touch it -- all transformations should go through the ModelView matrix. OpenGL acutally uses the projection matrix for other things (fog calculation being one of them), so this could be why your fog''s acting weird.
-- John
glLoadIdentity();
gluPerspective(45.0,1.4,0.1,5000.0);
gluLookAt(0,300,1000,0,000,0,0,1,0);
I''m not quite sure you want that gluLookAt there. Once you set up the projection matrix for your frustum, you shouldn''t touch it -- all transformations should go through the ModelView matrix. OpenGL acutally uses the projection matrix for other things (fog calculation being one of them), so this could be why your fog''s acting weird.
-- John
I though all things to do with the view were done in the projection matrix? Then all your world stuff is done in modelview.
Or at least thats what I think.
-wolfman
Or at least thats what I think.
-wolfman
-wolfmanThe End is only the Beginning of the End
You're saying that gluLookAt should only be called after GL_MODELVIEW is made active?
That would make sense. Wolfman called it while GL_PROJECTION was active.
GL_PROJECTION is used to set up the shape of the "rendering frustum", which affects x-y axis ratios, edge-edge viewing angle, etc. Anything that moves the camera or viewing direction should be done with GL_MODELVIEW
In short, try scooting your gluLookAt to after the GL_MODELVIEW/glLoadIdentity() and see if that helps.
[edited by - Waverider on May 16, 2002 5:11:54 PM]
That would make sense. Wolfman called it while GL_PROJECTION was active.
GL_PROJECTION is used to set up the shape of the "rendering frustum", which affects x-y axis ratios, edge-edge viewing angle, etc. Anything that moves the camera or viewing direction should be done with GL_MODELVIEW
In short, try scooting your gluLookAt to after the GL_MODELVIEW/glLoadIdentity() and see if that helps.
[edited by - Waverider on May 16, 2002 5:11:54 PM]
It's not what you're taught, it's what you learn.
the above AP is correct....
your matrix initialization should be....
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,1.4,0.1,5000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,300,1000,0,000,0,0,1,0);
i personally find gluPerspective and gluLookAt atrocious functions, but none the less....
i believe [bgluLookAt calls some form of glRotate and glTranslate .
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
your matrix initialization should be....
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0,1.4,0.1,5000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0,300,1000,0,000,0,0,1,0);
i personally find gluPerspective and gluLookAt atrocious functions, but none the less....
i believe [bgluLookAt calls some form of glRotate and glTranslate .
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
see the faq (www.opengl.org)
also this http://www.sjbaker.org/steve/omniv/projection_abuse.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html
also this http://www.sjbaker.org/steve/omniv/projection_abuse.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html
Since the draw() method resets the modelview matrix too, you should call gluLookAt in the draw() function.
There''s no need to set the mdelviewmatrix in the init() method :
Also, you may not call gluLookAt since the following glRotatef(fl_Angle, 0,1,0); and glTranslatef(-1000,0,-1000); are here to set your camera !?
There''s no need to set the mdelviewmatrix in the init() method :
void GLApplication::init(){...glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(45.0,1.4,0.1,5000.0);// gluLookAt(0,300,1000,0,000,0,0,1,0);// glMatrixMode(GL_MODELVIEW);// glLoadIdentity();CTerraGenerator *gen = new CTerraGenerator();terr = new GLTerrain(gen->generateTerrain(200,50,50,5,15),50,50);...}void GLApplication::draw(){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glMatrixMode(GL_MODELVIEW);glLoadIdentity();gluLookAt(0,300,1000,0,000,0,0,1,0); /* new */glRotatef(fl_Angle, 0,1,0);glTranslatef(-1000,0,-1000);terr->draw();glFlush();}
Also, you may not call gluLookAt since the following glRotatef(fl_Angle, 0,1,0); and glTranslatef(-1000,0,-1000); are here to set your camera !?
glFogf(GL_FOG_START, 2000.0f);
glFogf(GL_FOG_END, -200.0f);
You are starting the fog in front of the camera, and ending it behind. It should be more like (just an example):
glFogf(GL_FOG_START, 200.0f);
glFogf(GL_FOG_END, 300.0f);
And you should activate the modelview matrix immediately after setting up the projection one.
glFogf(GL_FOG_END, -200.0f);
You are starting the fog in front of the camera, and ending it behind. It should be more like (just an example):
glFogf(GL_FOG_START, 200.0f);
glFogf(GL_FOG_END, 300.0f);
And you should activate the modelview matrix immediately after setting up the projection one.
_______________________________________Pixelante Game Studios - Fowl Language
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement