Sign in to follow this  
carlito999

model appears black from distance

Recommended Posts

Hello everyone, I loaded some model whose real color can be seen only from short distance. But if i go far it becomes black. Can somebody tell me what's wrong?? Thanks in advance.

Share this post


Link to post
Share on other sites
I'm going to go out on a limb here with the absolutely tiny amount of information you have provided and say that it has to do with lighting.

Are you doing:

glEnable(GL_LIGHTING);

anyway in your code? If you so then lighting is enabled and your objects will be subject to getting lighter and darker subject to distance to light and the appropriate parameters for the Light.

Share this post


Link to post
Share on other sites
Thanks for ur reply.
A implemented nightmode when i enabled lighting. In other mode there is no use of lighting. These models act same in both cases. Dont know why?

Share this post


Link to post
Share on other sites
Quote:
Original post by carlito999
I loaded some model whose real color can be seen only from short distance. But if i go far it becomes black. Can somebody tell me what's wrong??


When you say "color", do you really mean color or is it textured? Though I'd have expected white or nothing at all, make sure you don't use mipmaps without actually specifying all the lower levels.

Share this post


Link to post
Share on other sites
Mine is a term project code.I tried to send the basic part.

int m,n,o,p;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor (0, 0, 0, 0.0);
glShadeModel (GL_SMOOTH);
glLoadIdentity();// Reset The matrix

if(nightflag==true)
{
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHT2);

}
else
glDisable(GL_LIGHTING);

///////here wrote all things


@trienco
the texture part is ok. Only the part where basic color was used while making the model appear dark black.

Share this post


Link to post
Share on other sites
Actually , i m using win32 api. i think there was no lighting at the very begining, so that i 've to didn't know how to create nightmode. Letter found out this way to do that. but models remains dark.

Share this post


Link to post
Share on other sites
That's not very much code you're giving us to work with. I'm sure there's plenty more relevant code. How'd you initialize the various lights? Do have fog enabled? Where's your texture code? Does it fade to no color or jump from full color to black? Screenshots, maybe? Without information all we can do is gaze into our crystal balls and speculate.

Share this post


Link to post
Share on other sites
here is my code:

void RenderScene()
{
int m,n,o,p;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glClearColor (0, 0, 0, 0.0);
glShadeModel (GL_SMOOTH);
glLoadIdentity();// Reset The matrix








////////////////////////////
if(gunvision==true)
{
//Draw_GUNVIEW();
// gluLookAt(0, 0, g_zoom, 0, 0, g_zoom + 1, 0, 1, 0);

// Rotate the world around the y axis, according to the degree stored in g_rotateY
// glRotatef(g_rotateY , 0, 1, 0);

gluLookAt(g_Camera.m_vPosition.x,g_Camera.m_vPosition.y,g_Camera.m_vPosition.z,
g_Camera.m_vView.x,g_Camera.m_vView.y,g_Camera.m_vView.z,
g_Camera.m_vUpVector.x, g_Camera.m_vUpVector.y, g_Camera.m_vUpVector.z);
//0,1,0);

}
else {

g_bNightVision=false;
g_Camera.Look();

}

//glEnable(GL_TEXTURE_2D);
//
if(nightflag==true)
{
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHT2);

}
else
{ glDisable(GL_LIGHTING);}




/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *


// Draw a grid so we can get a good idea of movement around the world
// Draw3DSGrid();



glTranslatef(1,-2,2);


// drawAxis();
//glScalef(5,5,5);

glPushMatrix();
if(nightflag==true) DrawSkyboxNight();
else Draw_Skybox();
//if(!GetAsyncKeyState('N')) Draw_Skybox();
//else DrawSkyboxNight();
anim();

/////////// //////////////Human figure

glPushMatrix();
// glScalef(10,10,10);
glColor3f(0.8,0.8,0.8);

glTranslatef(0,-10,0);
glRotatef(-90,1,0,0);


batsman->draw(0);

glPopMatrix();



glScalef(.4,.4,.4);
glColor3f(0.8,0.8,0.8);

glPushMatrix();
if(!reverseWalk){
glTranslatef(0,10,150);
glRotatef(-90,1,0,0);
bowler->draw(bowlerFrame);
}
glPopMatrix();

//glutSolidCube(5);


glPushMatrix();
if(reverseWalk){
glRotatef(180,0,1,0);
glTranslatef(-30,10,120);
glRotatef(-90,1,0,0);
bowler->draw(bowlerFrame);
}

glPopMatrix();

glPopMatrix();
glColor3f(1,1,1);




/////////////////////end of human figure

////////////////////Draw_sun
glPushMatrix();
glTranslatef(0,5,0);
Draw_Sun();
glPopMatrix();


//check point
if(e==10) {
//MessageBox(NULL, "U got Em!", "Click", MB_OK);

char str[20],st1[20];
sprintf(str,"U got all %d of them",e);

MessageBox(NULL,str,NULL,MB_OK);
e++;
sprintf(st1,"Number of miss shot %d",mshot);
MessageBox(NULL,st1,NULL,MB_OK);

}



/////////////////////////////////////////////////Draw Chair///////////////////////////

///////////////stage front
glPushMatrix();
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textPlane[0]);

glTranslatef(15,-.5,-8);
//glRotatef(150,0,1,0);
for(p=1;p<=9;p++){
Draw_Chair();
glTranslatef(0,0,2);
}
////stage front 2nd row for late commer

glTranslatef(-3,0,-2);
for(p=1;p<=9;p++){
Draw_Chair();
glTranslatef(0,0,-2);
}
// glDisable(GL_TEXTURE_2D);
glPopMatrix();
/////// stage left
glPushMatrix();
//glEnable(GL_TEXTURE_2D);
glTranslatef(20,-.5,-15);
// glRotatef(-90,0,1,0);
for(p=1;p<=9;p++){
//glRotatef(-90,0,1,0);
stageLeft=true;
Draw_Chair();

glTranslatef(2,0,0);
}
stageLeft=false;
//glDisable(GL_TEXTURE_2D);
glPopMatrix();
///////stage right
glPushMatrix();
//glEnable(GL_TEXTURE_2D);
glTranslatef(20,-.5,15);
// glRotatef(-90,0,1,0);
for(p=1;p<=9;p++){
//glRotatef(-90,0,1,0);
stageRight=true;
Draw_Chair();

glTranslatef(2,0,0);
}
stageRight=false;
glDisable(GL_TEXTURE_2D);
glPopMatrix();





/////////////////////////////////////////////////Draw Shop AND STAGE///////////////////////////


Draw_Stage();

glPushMatrix();
//glRotatef(150,0,1,0);
Draw_Stage1();

glPopMatrix();


glPushMatrix();
//
glTranslatef(0,0,10);
//flower.Draw();
glPopMatrix();


/////////////////////////////////////////////////Draw Shop///////////////////////////
DrawShop();
// glBindTexture(GL_TEXTURE_2D, textPlane[8]);

/////////////draw ballon

glPushMatrix();
glTranslatef(-43,0,0);
glColor3f(1,1,1);
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, roof[3]);

//glEnable(GL_TEXTURE_GEN_S);
// glEnable(GL_TEXTURE_GEN_T);
// glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
// glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);

//glutSolidSphere(1,50,50);

// glColor3f(1,1,0);
ballon(15,1,1);

glBindTexture( GL_TEXTURE_2D, roof[2]);
glTranslatef(0,0,-1);
ballon(10,1,1);

glColor3f(0,0,1);
glTranslatef(0,0,2);
glBindTexture( GL_TEXTURE_2D, roof[1]);
ballon(12,1,1);

glColor3f(0,1,1.5);
glTranslatef(0,0,-3);
glBindTexture( GL_TEXTURE_2D, roof[1]);
ballon(13,1,1);


glDisable(GL_TEXTURE_2D);
glPopMatrix();





////////////////////////////////////Draw Road/////////////////////////////

glPushMatrix();
glEnable(GL_TEXTURE_2D);
// glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

// glEnable(GL_LIGHTING);
glBindTexture(GL_TEXTURE_2D, textPlane[1]);


glTranslatef(-35,.1,0);
glScalef(5,1,5);
n=0;

for(o=1;o<3;o++)
{
for(m=1;m<=17;m++){ glTranslatef(n,0,0); Draw_road();n=1;}
glRotatef(-90,0,1,0);
glTranslatef(-8,.1,8);
}
glPopMatrix();

/////////////////////////////////////////watch tower/////////////////////////////
glPushMatrix();
glScalef(.1,.05,.1);
// glTranslatef(-30,.1,0);
//T_plane[20].Use();
glBindTexture(GL_TEXTURE_2D, textPlane[4]);
drawWatchtower(500,0,-500,1,0);
glPopMatrix();

////////////////////////////////////Draw Fench/////////////////////////////
glPushMatrix();

//glColor3f(0,0,.8);
glTranslatef(-40,0,-40);

glPushMatrix();
glEnable(GL_TEXTURE_2D);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, textPlane[0]);
glScalef(5,5,5);
//glEnable(GL_LIGHTING);
for(int j=1;j<5;j++){
int s=1;
for(int i=1;i<17;i++){glTranslatef(s,0,0);Draw_fench();}
//if(s==1) s==-1;
glRotatef(-90,0,1,0);

}
glDisable(GL_TEXTURE_2D);


glPopMatrix();
glPopMatrix();


//////////////////////////////////////////base grass
glPushMatrix();

glTranslatef(0,-1,0);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, g_Texture[0]);
glTranslatef(-120,0,-120);

for(p=1;p<10;p++){
glPushMatrix();


for(o=1;o<10;o++){
glTranslatef(30,0,0);
glPushMatrix();

glScalef(15,1,15);
c.drawCube(1,0,1,false);

glPopMatrix();

}
glPopMatrix();
glTranslatef(0,0,30);
}

// glScalef(15,1,15);
// c.drawCube(1,0,1,false);
//

//glScalef(5,1,5);
//c.drawCube(1,0,1,false);



// Display a quad texture to the screen
/* glBegin(GL_QUADS);

glColor3f(1,1,1);

//glTranslatef(0,0,0);
//glScalef(10,10,10);

glTexCoord2f(0,1); glVertex3f(-10, 0 ,10);
glTexCoord2f(1,1); glVertex3f(-10, 0,-10);
glTexCoord2f(1,0); glVertex3f(10,0,-10);
glTexCoord2f(0,0); glVertex3f(10,0,10);

glEnd();
*/

glDisable(GL_TEXTURE_2D);
glPopMatrix();



///////////////////////////////////////////////////////Draw wheel
/*
GLfloat lightpos1[] = {20,30,20, 1};
glLightfv(GL_LIGHT1, GL_POSITION, lightpos1);


glLightf(GL_LIGHT1, GL_SPOT_CUTOFF,45);
GLfloat spot_direction1[]={0,-1,0};
glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spot_direction1);


*/




glPushMatrix();

glTranslatef(20,0,20);
glRotatef(45, 0,1,0);
glScalef(.03,.03,.03);

//if(nightflag==true)

//glEnable(GL_LIGHTING);
//glEnable(GL_LIGHT0);
// GLfloat lightpos[] = {0, -1, 0, 0};
//glLightfv(GL_LIGHT0, GL_POSITION, lightpos);

// GLfloat color[] = {1,0,0, 1};
//glMaterialfv(GL_FRONT, GL_AMBIENT, color);
//glLightf(GL_LIGHT0, GL_SPOT_CUTOFF,45);

//GLfloat spot_direction[]={0,-1,0};
//glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spot_direction);


drawWheel();
glPopMatrix();





///////////////////////////Base part
//glColor3f(1,1,1);


//////////////////////////Base part







//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////shops///////////////////////////////////////////////
glPushMatrix();

glTranslatef(0,10,10);
glScalef(10,10,10);
shopping.drawShop();
glPopMatrix();

//if(nightflag==true) glEnable(GL_LIGHTING);
//else glDisable(GL_LIGHTING);

glPushMatrix();
glTranslatef(5,0,0);
glScalef(3,3,3);

// a.InitFountain();
// a.CreateList();
//
// a.DrawFountain();
glPopMatrix();


//glEnable(GL_TEXTURE_2D);

//////////////////////////draw modelsss///////////////////////

glPushMatrix();
// glEnable(GL_TEXTURE_2D);

glTranslatef(0,0,40);
// glColor3f(0.2,1.0,0.2);

tree.scale = .05;
tree.Draw();


glPopMatrix();

glPushMatrix();

tree1.scale = .009;
glTranslatef(-40,0,-40);
tree1.Draw();

glPopMatrix();

glPushMatrix();

tree1.scale = .009;
glTranslatef(40,0,40);
tree1.Draw();

glPopMatrix();


glPushMatrix();
// glColor3f(0,1.0,0);
dust.scale = 5;
glTranslatef(-40,0,40);
dust.Draw();
glPopMatrix();

glPushMatrix();
glColor3f(1,1,1);
dust.scale = 5;
glTranslatef(-40,0,15);
dust.Draw();
glPopMatrix();

glPushMatrix();
// glColor3f(0,1,0);
skateman.scale =.07;
glTranslatef(3,0,-10);
skateman.Draw();
glPopMatrix();

glPushMatrix();
// glColor3f(0,1,0);
guitar.scale =.04;
glTranslatef(40,2.5,0);
glRotatef(90,0,0,1);
// glRotatef(45,1,0,0);


guitar.Draw();
glPopMatrix();


/////chair table
int i;
for(i=1;i<3;i++)
{

glPushMatrix();

if(i==1)glTranslatef(-30,0,10);
if(i==2)glTranslatef(-10,0,30);
glPushMatrix();
//glColor3f(0,1.0,0);
chair.scale = 3;

glTranslatef(0,0,0);
glRotatef(90,0,1,0);
chair.Draw();

glTranslatef(2,0,5);
glRotatef(-180,0,1,0);
chair.Draw();

glTranslatef(3,0,2);
glRotatef(-90,0,1,0);
chair.Draw();

glTranslatef(2,0,4);
glRotatef(-180,0,1,0);
chair.Draw();

glPopMatrix();

/////////table
glPushMatrix();
glColor3f(1,1,1);
// glEnable(GL_TEXTURE_2D);
//glEnable(GL_BLEND);
// glBindTexture(GL_TEXTURE_2D, textPlane[8]);
table.scale = .05;
glTranslatef(0,0,0);
table.Draw();
//cup5.Draw();
glPopMatrix();
//glDisable(GL_BLEND);
// glDisable(GL_TEXTURE_2D);

glPopMatrix();

}
//////////////////end of chair table

glPushMatrix();
//glColor3f(0,1.0,0);
dinnerset.scale = 3;
glTranslatef(0,0,0);
//dinnerset.Draw();
glPopMatrix();

glPushMatrix();
//glColor3f(0,1.0,0);
// dinner_table.scale = 3;
glTranslatef(0,0,10);
// dinner_table.Draw();
glPopMatrix();
/////// slider


glPushMatrix();
glColor3f(1,1,0);
slider.scale =.005;
glTranslatef(-20,0,-15);
glRotatef(90,0,1,0);
slider.Draw();
glPopMatrix();
/////////////////rock dolna

glPushMatrix();
glColor3f(1,1,1);
rock.scale =4;
glTranslatef(-5,0,30);
//glRotatef(90,0,1,0);
rock.Draw();
glPopMatrix();

////////////snack cart
glPushMatrix();
glColor3f(1,1,1);
snack_cart.scale =.04;
glTranslatef(-30,0,-5);
glRotatef(90,0,1,0);
snack_cart.Draw();
glPopMatrix();


////////////mandrum
glPushMatrix();
glColor3f(1,1,1);
mandrum.scale =.1;
glTranslatef(30,2,3);
glRotatef(90,0,1,0);
mandrum.Draw();
glPopMatrix();


////////////drum
glPushMatrix();
glColor3f(1,1,1);
drum.scale =2;
glTranslatef(30,10,3);
glRotatef(90,0,1,0);
drum.Draw();
glPopMatrix();

////////////man
glPushMatrix();
glColor3f(1,1,1);
man.scale =.05;
glTranslatef(30,10,3);
glRotatef(90,0,1,0);
man.Draw();
glPopMatrix();

if(gunvision==true){

Draw_GUNVIEW();


}
if(!gunvision && altrnightflag && !nightflag) {nightflag=true;altrnightflag=false; }


//if(!gunvision && g_bNightVision && !nightflag){ nightflag=true;}

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

// Draw the pyramids that spiral in to the center
// DrawSpiralTowers();

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *


// Swap the backbuffers to the foreground
SwapBuffers(g_hDC);

// gluDeleteQuadric(pObj); // Free the Quadric

// Below we increase the rotations for each sphere.

SunRotation += 0.2f; // Rotate the sun slowly
EarthRotation += 0.5f; // Increase the rotation for the each
PlutoRotation += 0.6f;
A_up +=.04f;
B_up +=.03f;
C_up +=.05f;
sun_up +=.07;
e_up +=.08;
p_up += .1;
D_up +=.02f;
ea_up +=.05f;
F_up +=.07f;
G_up +=.06f;
}

Share this post


Link to post
Share on other sites
Seeing as how you have no calls to glFrustum or gluProjection, your projection matrix is out of whack. The maximum depth that will be rendered is probably whatever the default value is, which, if my memory serves me, is 1. So any objects further than 1 unit away from the camera wouldn't show up.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this