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

Phong illumination model

September 15, 2006

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

All comments are moderated. Your comments will not appear here unless approved by the blog owner. Thank you.

Add a comment








     

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

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

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!

yue:

phengpheng!

pheng:

ur welcome!:)

Leave a message ▼