"Don't tell me how hard you work. Tell me how you get done."
- James J. Ling

Warn illumination model

September 15, 2006

 /*
* 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;
}

Posted by phengpheng at 9:53 pm | permalink | Add comment

Phong illumination model

/*
* 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;

Posted by phengpheng at 1:31 am | permalink | Add comment

Pseudo-Random Numbers in ASM

September 1, 2006

;———————–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 

 

 

 

Posted by phengpheng at 10:24 pm | permalink | comments[1]

     

September 2006
M T W T F S S
« Aug   Oct »
 123
45678910
11121314151617
18192021222324
252627282930  

Sponsored Links

About Me

A Computer Science graduate who is a fanatic in assembly, java, and j2me programming. Developed BlueVoice system (Direct Voice Communication in Mobile Phones), this system allows mobile users to experience FREE VOICE CALLS

Subscribe

Technorati
Bloglines

Tagboard

tinnitus treatment:

thanks You sure do know what your’e talking about. Man, this blog is just great! I cant wait to read more of what youv’e got to say. Im really happy that I came across this when I did because I was really starting

phengpheng:

Haven’t managed my blog for a long time already because I’m so busy now… Sorry to cause you guyz trouble…

Jun Mark:

hoW tO creaTE a PrOGram thAT woULD oUTpuT ascii table???

Jun Mark:

pLZ anSwer mY qUEstions

cutieGurl:

how to convert binary to hexadecimal, decimal and octal?????????please. answer me??????????

mary ann:

kuya, ung binary to decimal converter nyo. mali man? ung sa mga compare mo. ung may 0,9,A,F etc… bad character lumalabaspls rep asap po. tnx

carol:

how to convert decimal to binary to octal and hexadecimal

Galwin:

been here!

galwin:

nice site. hope you could visit mine, too.

pathy:

FRIENDS FOREVER!! Miss you na!!!

ridvan:

aus, i seldom see lady programmers. hehe. keep it up. and oh yeah, i guess i saw you during the MICT Quiz Show held in cdo. :)
keep up the codes!

phengpheng:

I miss updating this blog… Sana may time and pc ako to learn new stuffs aside from my work…

support:

Congratulations, you’ve just completed the installation of this shoutbox.

pheng:

uy! you’re here again!

Jay:

Woooohhhh orange…sweat… nakakasilaw! hehe :)

jay:

tagboard flood hehe sensya… had nothing fun to do. :)

pheng:

jaaaaayyyyy….:) ketal man?:)

niel:

no spamming please :p hehehe joke lang jay.

Jay:

Uyyyyyy!!!! Grraaaaaaaiiiinnnneeee
:)
Sssshhhh, el sikret! :)
Niiiiiiiiiiiiieeeeeel
Sup dude!!!!
Paaaaaaaaaaaaaathy
Ketal!?

niel:

ei pheng! :D slick-elegant layout! love it!

Leave a message ▼