int width = 800, height = 600;
voidKhoiTaoChieuSang(void)
{
GLfloatlight_position[] = { 1.0, 1.0, 1.0, 0.0 };
GLfloatwhite_light[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloatlmodel_ambient[] = { 0.1, 0.1, 0.1, 1.0 };
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
floatmauMatNgoai[] = { 0.8, 0, 0.8, 1 };
floatmauMatTrong[] = { 0, 0, 0.8, 1 };
glMaterialfv(GL_FRONT, GL_EMISSION, mauMatNgoai);
glMaterialfv(GL_BACK, GL_EMISSION, mauMatTrong);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
glShadeModel(GL_SMOOTH);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
//glEnable(GL_LIGHTING) ;
//glEnable(GL_LIGHT0) ;
}
voidInit(void)
{
// Thiet lap maunen
glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
// Thiet lap phepchieu
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-width / 2, width / 2, -height / 2, height / 2, 100, 1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0, 0, -400);
glEnable(GL_DEPTH_TEST);
return;
}
voidPhapVector(floatv1[3], floatv2[3], floatv3[3], floatv[3])
{
float x1, y1, z1;
float x2, y2, z2;
float x3, y3, z3;
float x, y, z;
x1 = v1[0];
y1 = v1[1];
z1 = v1[2];
x2 = v2[0];
y2 = v2[1];
z2 = v2[2];
x3 = v3[0];
y3 = v3[1];
z3 = v3[2];
x = y1*(z2 - z3) + y2*(z3 - z1) + y3*(z1 - z2);
y = z1*(x2 - x3) + z2*(x3 - x1) + z3*(x1 - x2);
z = x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 - y2);
v[0] = x;
v[1] = y;
v[2] = z;
return;
}
voidChuanHoaVector(floatv[3])
{
float x, y, z, L;
x = v[0];
y = v[1];
z = v[2];
L = sqrt(x*x + y*y + z*z);
x = x / L;
y = y / L;
z = z / L;
v[0] = x;
v[1] = y;
v[2] = z;
return;
}
voidComputersGraphics(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSwapBuffers();
return;
}
int main(intargc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGB);
glutInitWindowPosition(10, 10);
glutInitWindowSize(width, height);
glutCreateWindow("Computers Graphics With OpenGL");
Init();
glutDisplayFunc(ComputersGraphics);
glutMainLoop();
return 0;
}