• 大小: 3KB
    文件类型: .cpp
    金币: 1
    下载: 0 次
    发布日期: 2021-05-29
  • 语言: C/C++
  • 标签: OpenGL  编程实例  C++  

资源简介

真实感图形的例子,可以移动点光源产生阴影变化

资源截图

代码片段和文件信息


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

评论

共有 条评论