\$25

Image of the Day Submit

IOTD | Top Screenshots

Fussy Fog. :-(

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

6 replies to this topic

#1Vlion  Members

Posted 11 September 2001 - 11:46 AM

I am not getting the fog to work. Whats happening is all my objects are colored the color of the intended fog. The fog is not showing. :-| This code is taken from a simplistic solar system model, btw.
#include
#include
#include
#include
#include
#include
#include
#include
#include

#pragma comment( linker, "/entry:\"mainCRTStartup\"" )  // set the entry point to be main()

#define SCRNX 600
#define SCRNY 600

bool fscrn;
float eyex, eyey, eyez;
float px, py, pz;
float tx,ty,tz;
float ex,ey;
float time;

//Slow, unoptimized...oh well.
void DrawEllipse()
{
glColor3ub(255,255,255);
float x,y,z,t;
for(t = 0.0; t <= 360; t += 1)
{
x = 5*sin(t);
y = 4*cos(t);
z = 0;
glBegin(GL_POINTS);
{
glVertex3f(x,y,z);
}
glEnd();
}
}
void DrawSphere(float x,float y, float z, float r)
{
glPushMatrix();
{
glTranslatef(x,y,z);
glutSolidSphere(r,16,16);
}
glPopMatrix();
}
//Location in space of the orbit point, and radius of orbit.
void DrawMoon(float x, float y, float z, float r)
{

glPushMatrix();
{

glTranslatef(x,y,z);	//Translate to the Earth posiiton

x = r*sin(time*10);		//Rotate co-ords
y = r*cos(time*10);
z = sin(time);

glTranslatef(x,y,z);	//Translate to the rotate position

glutSolidSphere(.5,16,16);

}
glPopMatrix();
}

void Render()
{
float pos[] = {0,0,0,1};
float color[] = {1,1,0,1};
float amb[] = {1,1,1,1};

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);

glPushMatrix();
{
glTranslatef(tx,ty,tz);
gluLookAt(eyex,eyey,eyez,px,py,pz,0,1,0);
glPushMatrix();
{
glDisable(GL_LIGHTING);
glColor4ub(255,255,0,255);
DrawSphere(0,0,0,1);

glEnable(GL_LIGHTING);

glLightfv(GL_LIGHT0, GL_AMBIENT, amb);

glLightfv(GL_LIGHT0, GL_DIFFUSE, color);
glLightfv(GL_LIGHT0, GL_POSITION, pos);

glColor3f(0,1,0);

DrawSphere(ex,ey,0,1);
DrawMoon(ex,ey,0,2);

}
glPopMatrix();

//The axes
glPushMatrix();
{
glBegin(GL_LINES);
{

//X axis
glColor3ub(255,0,0);
glVertex3f(100,0,0);
glVertex3f(-100,0,0);

//Y axis
glColor3ub(0,255,0);
glVertex3f(0,100,0);
glVertex3f(0,-100,0);

//Z axis
glColor3ub(0,0,255);
glVertex3f(0,0,100);
glVertex3f(0,0,-100);

DrawEllipse();

}
glEnd();

}
glPopMatrix();

}
glPopMatrix();

glFlush();
glutSwapBuffers();

}

int Init(int argc,char **argv)
{
eyex = eyey = 0;
eyez = 10;

px = py = pz = 0;

tx = ty = tz = 0;
ex = ey = time = 0;
float fogcolor[] = {1,1,0,1};

glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(SCRNX,SCRNX);
glutInitWindowPosition(0,0);
glutInit(&argc,argv);

glutCreateWindow("Star model");

glClearColor(0,0,0,0);
glViewport(0,0,SCRNX,SCRNX);
glMatrixMode(GL_PROJECTION);

gluPerspective(60.0f, SCRNX/SCRNX, 1.0, 1000.0f);

glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);

glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

glFrontFace(GL_CW);
glCullFace(GL_FRONT);

GLuint	fogMode[]= { GL_EXP, GL_EXP2, GL_LINEAR };	// Storage For Three Types Of Fog
GLuint	fogfilter = 0;								// Which Fog Mode To Use
GLfloat	fogColor[4] = {0.5f,0.5f,0.5f,1.0f};		// Fog Color

glFogi(GL_FOG_MODE, fogMode[fogfilter]);			// Fog Mode
glFogfv(GL_FOG_COLOR, fogColor);					// Set Fog Color
glFogf(GL_FOG_DENSITY, 0.35f);						// How Dense Will The Fog Be
glHint(GL_FOG_HINT, GL_DONT_CARE);					// Fog Hint Value
glFogf(GL_FOG_START, 1.0f);							// Fog Start Depth
glFogf(GL_FOG_END, 5.0f);							// Fog End Depth
glEnable(GL_FOG);

return 0;
}
void Main()
{
ex = 5*sin(time);
ey = 4*cos(time);
time += 0.01;

Render();
};

void Mouse(int,int,int,int);
void Special(int,int,int);
void Key(unsigned char,int,int);

int main(int argc,char **argv)
{
Init(argc,argv);
glutDisplayFunc(Render);

glutIdleFunc(Main);

glutMouseFunc(Mouse);
glutKeyboardFunc(Key);
glutSpecialFunc(Special);

glutMainLoop();
return 0;
}


I came, I saw, I got programmers block. ~V''''lion

#2Xunil_RJ  Members

Posted 11 September 2001 - 02:43 PM

You are not seeing the fog, problably because you are clearing the screen with a color tha is diference of the fog color. So you have to do the clear colo like the fog color...

So...if you put your fog this...

GLfloat fogColor[4] = {0.5f,0.5f,0.5f,1.0f};

you have to do this...

glClearColor(0.5f,0.5f,0.5f,1.0f);

I hope that is waht you want

#3Vlion  Members

Posted 11 September 2001 - 04:41 PM

I dont get it....
My models not emerging from fog...its just totally colored the color the fog color is.
v''lion

I came, I saw, I got programmers block.
~V''''lion

#4Lord Karnus  Members

Posted 15 September 2001 - 08:14 PM

The way that I understand OpenGL fogging to work is that the fog color is applied to pixels as they are rendered based on their distance from the viewer. You mention your objects as being completely fog colored. This is likely because they are pretty far from the camera. Does this fog color fade away as the camera nears the object? The reason the rest of space is not fogged is because that you aren''t rendering anything there, so there are no pixels to fog. I can''t think of an easy way to do fog in a space environment, unless you set the fog color to black. I hope that this has helped.

Feel free to email me.

#5DeathWish  Members

Posted 15 September 2001 - 11:13 PM

Try making the fog start further back - remeber GL is right-handed, so you could try setting the start to -3.0f and the end to sommat like -8.0f.

DeathWish

#6Anonymous Poster_Anonymous Poster_*  Guests

Posted 17 September 2001 - 12:27 PM

Yeah. I figured out what was happening.
Its like Lord Karnus said- only the pixels on the objects are getting fogged- its up to me to deal wityh the other stuff.
Which is really interesting.
In Homeworld and HW:Cataclysm, they evidently have a fog that bypasses certain objects. Ships/and other ingame models are fogged t the background color, and the background shows perfectly. I`m pretty sure the background is a textures sphere.
Hm.
Anyways, thanx.
~V''lion

#7AIRmichael  Members

Posted 20 September 2001 - 09:48 PM

Hey, i think the fog density is 1.0f as default. So make the fog depth function, and change it to a lower number.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.