PDA

View Full Version : lighting_(plz its urgent)



chign
06-13-2010, 05:18 PM
well i have to draw several objects and what i get is olny the one.. alla the others appear black..

any idea??

the first objects is a textured image and the others are models i have loaded..

here is parts of my code..

my display:


if (x[i][j]=='*') {
glColor3f(1.0,1.0,1.0);
drawcube_wall(cnt1,cnt2,temp1,temp2);
}
else if (x[i][j]=='2'){
glColor3f(0,1,0);
drawfood(cnt1,cnt2,temp1,temp2);
fruits=fruits+1;

}


my drawnig functions...
the first one that works:


glPushMatrix();
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_RE PLACE);
glBindTexture(GL_TEXTURE_2D,textureID[0]);
//drawing//
glDisable(GL_TEXTURE_2D);
glPopMatrix();
}

and after that the problematic one:

GLfloat ambientcoefficients[]={0.0,0.0,0.0};
glPushMatrix();
glEnable(GL_TEXTURE_2D);
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFF USE,ambientcoefficients);
glTranslatef( (GLfloat) b1+a1/2, (GLfloat) b2+a2/2, 0);
glRotatef(45,1,0,0);
if (a1<a2) glScalef(1.0,GLfloat (a2/a1),1.0);
else glScalef(1.0,GLfloat (a1/a2),1.0);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_RE PLACE);
glBindTexture(GL_TEXTURE_2D, g_models[0].tex);
glCallList(g_models[0].dlist);
glDisable(GL_TEXTURE_2D);
glPopMatrix();
}

i dont know what i am doing wrong.. what i want for the second item is to be drawn with the colour of the object.. the object is loaded correctly (its texture with its colour)

if its necessary this is my lighting function:

GLfloat light_specular[] = {1.0,1.0,1.0,1.0};
GLfloat light_diffuse[] = {1.0,1.0,1.0,1.0};
GLfloat light_ambient[] = {0.0,0.0,0.0,1.0};
GLfloat light_position[] = { -2.0, 2.0, 2.0, 1.0 };
GLfloat light_model[] = { 0.7, 0.7, 0.7, 1.0 };

glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular);
glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);
glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient);
glLightfv(GL_LIGHT0, GL_POSITION,light_position);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, light_model);


glClearColor (0.1, 0.1, 0.1, 1.0);
glShadeModel (GL_SMOOTH);

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

//blending - antialiasing
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_POLYGON_SMOOTH);
glEnable(GL_POINT_SMOOTH);
//glEnable(GL_BLEND);
glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);
glHint(GL_POLYGON_SMOOTH_HINT,GL_NICEST);
glLineWidth(2.0);


//fog
glEnable(GL_FOG);
GLfloat fogColor[4] = {0.0,0.0,0.0,1.0};
GLint fogMode = GL_LINEAR;
glFogi(GL_FOG_MODE,fogMode);
glFogfv(GL_FOG_COLOR,fogColor);
glFogf(GL_FOG_DENSITY,0.50);
glHint(GL_FOG_HINT,GL_NICEST);
glFogf(GL_FOG_START,50.0);
glFogf(GL_FOG_END,100.0);

Dark Photon
06-13-2010, 07:44 PM
Post a short GLUT test program (start with this (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&amp;Number=278315#Post2783 15)) that illustrates your problem.

And this is not an Advanced question. Please post subsequent posts to Beginners.