/*
* OpenGL implementation of Warns illumination model(spotlight)
* for better understanding read Computer Graphics by Hill
* page 426
*/
#include <GL/glut.h>
void init(void)
{
GLfloat mat_specular[] = { 1.0, 1.0, 0.0, 1.0 };
GLfloat mat_shininess[] = { 50.0 };
//set spotlight’s position
GLfloat dir_light[]={2.0, 1.0, -4.0};
GLfloat light_position[] = { 2.0, 1.0, 5.0, 1.0 };
glClearColor (1.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
/*
* a cutoff angle of 45 degrees
* default value is 180 degrees
*/
glLightf(GL_LIGHT0,GL_SPOT_CUTOFF, 45.0);
/*
* The desired falloff of light with angle(E) is 1
* As E increases the spotlight disappears
* default value is 0
*/
glLightf(GL_LIGHT0,GL_SPOT_EXPONENT, 1.0);
glLightfv(GL_LIGHT0,GL_SPOT_DIRECTION,dir_light);
//enables light
glEnable(GL_LIGHTING);
//enables this particular source.
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidSphere (1.0, 20, 16);
glutSwapBuffers();
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho (-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w, 1.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0);
else
glOrtho (-1.5*(GLfloat)w/(GLfloat)h, 1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (”Single-Point Light Source”);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
/*
* This is Phong illumination model, an illumination model for
* non-perfect reflectors.This is the most popular illumination model
* although does not actually explain the real light source.
*/
#include <GL/glut.h>
void init(void)
{
GLfloat mat_shininess[] = { 10.0 };
//set light position
GLfloat light_position[] = { 1.0, 1.0, 2.0, 1.0 };
//define colors for ambient, diffuse, and specular light
GLfloat light_Ka[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat light_Kd[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_Ks[] = { 1.0, 1.0, 1.0, 1.0 };
glClearColor (1.0, 0.0, 0.0, 0.0);
glShadeModel (GL_SMOOTH);
/*GL_LIGHT0 means there is only one light source
* we can actually have maximum of 8 light sources
* denoted as GL_LIGHT0, GL_LIGHT1,…,GL_LIGHT7
*/
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
//attach defined lights to light source
glLightfv(GL_LIGHT0, GL_AMBIENT, light_Ka);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_Kd);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_Ks);
glMaterialfv(GL_FRONT, GL_SPECULAR, light_Ks);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
//enables light
glEnable(GL_LIGHTING);
//enables this particular source.
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutSolidSphere (1.0, 20, 16);
glutSwapBuffers();
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
if (w <= h)
glOrtho (-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w, 1.5*(GLfloat)h/(GLfloat)w, -10.0, 10.0);
else
glOrtho (-1.5*(GLfloat)w/(GLfloat)h, 1.5*(GLfloat)w/(GLfloat)h, -1.5, 1.5, -10.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow (”Single-Point Light Source”);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
;———————–get system time—————————
mov ah, 02ch
int 21h
;————————get hour (00-24)————————
xor ax, ax
xor dx, dx
mov al, ch
call display
mov dl,’:’
int 21h
;————————–get minute—————————
xor ax, ax
xor dx,dx
mov al, cl
call display
;—generate 10 3-digit “random” numbers——
mov ch, 10
num:
xor ax, ax
xor bx, bx
mov dh, dl
;————————3 digit numbers————————-
mov cl,3
digits:
mov al, dl ; get millisec
mov bl, 10
div bl
add ah, 30h
mov dl, ah
mov ah, 02
int 21h
shr dl,1 ; digits seem to random
dec cl
jnz digits
mov ah,02 ; go to nxt line
mov dl,0ah
int 21h
mov dl,0dh
int 21h
mov dl, dh ; generate more 3-digit numbers
add dl, 17
dec ch
jnz num
int 20h
;————–display hour/minute———————
display:
mov bl, 10
div bl
add al, 30h
add ah, 30h
mov dh, ah
mov ah, 02
mov dl, al
int 21h
mov dl,dh
int 21h
ret