資源簡介
真實(shí)感圖形的例子,可以移動(dòng)點(diǎn)光源產(chǎn)生陰影變化
代碼片段和文件信息
/*?Copyright?(c)?Mark?J.?Kilgard?1994.?*/
#include?
#include?
#include?
#include?
#define?TORUS?0
#define?TEAPOT?1
#define?DOD?2
#define?TET?3
#define?ISO?4
#define?QUIT?5
static?int?spin?=?0;
static?int?obj?=?TORUS;
static?int?begin;
void
menu_select(int?item) //定義選擇菜單
{
??if?(item?==?QUIT)
????exit(0);
??obj?=?item;
??glutPostRedisplay();
}
/*?ARGSUSED2?*/
void
movelight(int?button?int?state?int?x?int?y)
{
??if?(button?==?GLUT_LEFT_BUTTON?&&?state?==?GLUT_DOWN)?{
????begin?=?x;
??}
}
/*?ARGSUSED1?*/
void
motion(int?x?int?y)
{
??spin?=?(spin?+?(x?-?begin))?%?360;
??begin?=?x;
??glutPostRedisplay();
}
void
myinit(void)
{
??glEnable(GL_LIGHTING);
??glEnable(GL_LIGHT0);
??glDepthFunc(GL_LESS);
??glEnable(GL_DEPTH_TEST);
}
/*??Here?is?where?the?light?position?is?reset?after?the?modeling
?*??transformation?(glRotated)?is?called.??This?places?the?
?*??light?at?a?new?position?in?world?coordinates.??The?cube
?*??represents?the?position?of?the?light.
?*/
void
display(void)
{
??GLfloat?position[]?=
??{0.0?0.0?1.5?1.0};
??glClear(GL_COLOR_BUFFER_BIT?|?GL_DEPTH_BUFFER_BIT);
??glMatrixMode(GL_MODELVIEW);
??glPushMatrix();
??glTranslatef(0.0?0.0?-5.0);
??glPushMatrix();
??glRotated((GLdouble)?spin?0.0?1.0?0.0);
??glLightfv(GL_LIGHT0?GL_POSITION?position);
??glTranslated(0.0?0.0?1.5);
??glDisable(GL_LIGHTING);
??glColor3f(0.0?1.0?1.0);
??glutWireCube(
評(píng)論
共有 條評(píng)論