light&material.zip

  • PUDN用户
    了解作者
  • Visual C++
    开发工具
  • 8KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 17
    下载次数
  • 2005-08-23 01:32
    上传日期
关于光照和材质的演示教程,通过鼠标移动修改参数来显示不同的效果
light&material.zip
  • www.pudn.com.txt
    218B
  • lightmaterial.c
    41.4KB
内容介绍
/* lightmaterial.c Nate Robins, 1997 Tool for teaching about OpenGL lighting & material properties. */ #include <math.h> #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #include <string.h> #include <GL/glut.h> #include "glm.h" #include "materials.h" #pragma comment( linker, "/entry:\"mainCRTStartup\"" ) // set the entry point to be main() typedef struct _cell { int id; int x, y; float min, max; float value; float step; char* info; char* format; } cell; cell light_pos[4] = { { 1, 210, 30, -5.0, 5.0, -2.0, 0.01, "Specifies X coordinate of light vector.", "%.2f" }, { 2, 270, 30, -5.0, 5.0, 2.0, 0.01, "Specifies Y coordinate of light vector.", "%.2f" }, { 3, 330, 30, -5.0, 5.0, 2.0, 0.01, "Specifies Z coordinate of light vector.", "%.2f" }, { 4, 390, 30, 0.0, 1.0, 1.0, 1.0, "Specifies directional (0) or positional (1) light.", "%.2f" }, }; cell light_Ka[4] = { { 5, 200, 60, 0.0, 1.0, 0.0, 0.01, "Specifies ambient red intensity of the light.", "%.2f" }, { 6, 260, 60, 0.0, 1.0, 0.0, 0.01, "Specifies ambient green intensity of the light.", "%.2f" }, { 7, 320, 60, 0.0, 1.0, 0.0, 0.01, "Specifies ambient blue intensity of the light.", "%.2f" }, { 8, 380, 60, 0.0, 1.0, 1.0, 0.01, "Specifies ambient alpha intensity of the light.", "%.2f" }, }; cell light_Kd[4] = { { 9, 200, 90, 0.0, 1.0, 1.0, 0.01, "Specifies diffuse red intensity of the light.", "%.2f" }, { 10, 260, 90, 0.0, 1.0, 1.0, 0.01, "Specifies diffuse green intensity of the light.", "%.2f" }, { 11, 320, 90, 0.0, 1.0, 1.0, 0.01, "Specifies diffuse blue intensity of the light.", "%.2f" }, { 12, 380, 90, 0.0, 1.0, 1.0, 0.01, "Specifies diffuse alpha intensity of the light.", "%.2f" }, }; cell light_Ks[4] = { { 13, 200, 120, 0.0, 1.0, 1.0, 0.01, "Specifies specular red intensity of the light.", "%.2f" }, { 14, 260, 120, 0.0, 1.0, 1.0, 0.01, "Specifies specular green intensity of the light.", "%.2f" }, { 15, 320, 120, 0.0, 1.0, 1.0, 0.01, "Specifies specular blue intensity of the light.", "%.2f" }, { 16, 380, 120, 0.0, 1.0, 1.0, 0.01, "Specifies specular alpha intensity of the light.", "%.2f" }, }; cell spot_direction[3] = { { 17, 250, 260, -1.0, 1.0, 1.0, 0.01, "Specifies X coordinate of spotlight direction vector.", "%.2f" }, { 18, 310, 260, -1.0, 1.0, -1.0, 0.01, "Specifies Y coordinate of spotlight direction vector.", "%.2f" }, { 19, 370, 260, -1.0, 1.0, -1.0, 0.01, "Specifies Z coordinate of spotlight direction vector.", "%.2f" }, }; cell spot_exponent = { 20, 210, 290, 0.0, 128.0, 30.0, 1.0, "Specifies intensity distribution of spotlight.", "%.0f" }; cell spot_cutoff = { 21, 410, 290, 0.0, 91.0, 91.0, 1.0, "Specifies maximum spread angle of spotlight (180 = off).", "%.0f" }; cell Kc = { 22, 120, 410, 0.0, 5.0, 1.0, 0.01, "Specifies constant attenuation factor.", "%.2f" }; cell Kl = { 23, 215, 410, 0.0, 5.0, 0.0, 0.01, "Specifies linear attenuation factor.", "%.2f" }; cell Kq = { 24, 315, 410, 0.0, 5.0, 0.0, 0.01, "Specifies quadratic attenuation factor.", "%.2f" }; cell material_Ka[4] = { { 25, 220, 260, 0.0, 1.0, 0.2, 0.01, "Specifies ambient red reflectance of the material.", "%.2f" }, { 26, 280, 260, 0.0, 1.0, 0.2, 0.01, "Specifies ambient green reflectance of the material.", "%.2f" }, { 27, 340, 260, 0.0, 1.0, 0.2, 0.01, "Specifies ambient blue reflectance of the material.", "%.2f" }, { 28, 400, 260, 0.0, 1.0, 1.0, 0.01, "Specifies ambient alpha reflectance of the material.", "%.2f" }, }; cell material_Kd[4] = { { 29, 220, 290, 0.0, 1.0, 0.8, 0.01, "Specifies diffuse red reflectance of the material.", "%.2f" }, { 30, 280, 290, 0.0, 1.0, 0.8, 0.01, "Specifies diffuse green reflectance of the material.", "%.2f" }, { 31, 340, 290, 0.0, 1.0, 0.8, 0.01, "Specifies diffuse blue reflectance of the material.", "%.2f" }, { 32, 400, 290, 0.0, 1.0, 1.0, 0.01, "Specifies diffuse alpha reflectance of the material.", "%.2f" }, }; cell material_Ks[4] = { { 33, 220, 320, 0.0, 1.0, 1.0, 0.01, "Specifies specular red reflectance of the material.", "%.2f" }, { 34, 280, 320, 0.0, 1.0, 1.0, 0.01, "Specifies specular green reflectance of the material.", "%.2f" }, { 35, 340, 320, 0.0, 1.0, 1.0, 0.01, "Specifies specular blue reflectance of the material.", "%.2f" }, { 36, 400, 320, 0.0, 1.0, 1.0, 0.01, "Specifies specular alpha reflectance of the material.", "%.2f" }, }; cell material_Ke[4] = { { 37, 220, 350, 0.0, 1.0, 0.0, 0.01, "Specifies red emitted light intensity of the material.", "%.2f" }, { 38, 280, 350, 0.0, 1.0, 0.0, 0.01, "Specifies green emitted light intensity of the material.", "%.2f" }, { 39, 340, 350, 0.0, 1.0, 0.0, 0.01, "Specifies blue emitted light intensity of the material.", "%.2f" }, { 40, 400, 350, 0.0, 1.0, 1.0, 0.01, "Specifies alpha emitted light intensity of the material.", "%.2f" }, }; cell material_Se = { 41, 200, 380, 0.0, 128.0, 50.0, 1.0, "Specifies the specular exponent of the material.", "%.0f" }; cell lmodel_Ka[4] = { { 42, 220, 260, 0.0, 1.0, 0.2, 0.01, "Specifies ambient red intensity of the entire scene.", "%.2f" }, { 43, 280, 260, 0.0, 1.0, 0.2, 0.01, "Specifies ambient green intensity of the entire scene.", "%.2f" }, { 44, 340, 260, 0.0, 1.0, 0.2, 0.01, "Specifies ambient blue intensity of the entire scene.", "%.2f" }, { 45, 400, 260, 0.0, 1.0, 1.0, 0.01, "Specifies ambient alpha intensity of the entire scene.", "%.2f" }, }; cell local_viewer = { 46, 460, 340, 0.0, 1.0, 0.0, 1.0, "Specifies infinite (0.0) or local (1.0) light model.", "%.1f" }; cell two_side = { 47, 415, 390, 0.0, 1.0, 0.0, 1.0, "Specifies one (0.0) or two (1.0) sided lighting.", "%.1f" }; GLfloat eye[3] = { 0.0, 0.0, 3.0 }; GLfloat at[3] = { 0.0, 0.0, 0.0 }; GLfloat up[3] = { 0.0, 1.0, 0.0 }; GLboolean world_draw = GL_TRUE; GLMmodel* pmodel = NULL; GLint selection = 0; GLfloat spin_x = 0.0; GLfloat spin_y = 0.0; void redisplay_all(void); GLdouble projection[16], modelview[16], inverse[16]; GLuint window, world, screen, command; GLuint sub_width = 256, sub_height = 256; GLvoid *font_style = GLUT_BITMAP_TIMES_ROMAN_10; void setfont(char* name, int size) { font_style = GLUT_BITMAP_HELVETICA_10; if (strcmp(name, "helvetica") == 0) { if (size == 12) font_style = GLUT_BITMAP_HELVETICA_12; else if (size == 18) font_style = GLUT_BITMAP_HELVETICA_18; } else if (strcmp(name, "times roman") == 0) { font_style = GLUT_BITMAP_TIMES_ROMAN_10; if (size == 24) font_style = GLUT_BITMAP_TIMES_ROMAN_24; } else if (strcmp(name, "8x13") == 0) { font_style = GLUT_BITMAP_8_BY_13; } else if (strcmp(name, "9x15") == 0) { font_style = GLUT_BITMAP_9_BY_15; } } void drawstr(GLuint x, GLuint y, char* format, ...) { va_list args; char buffer[255], *s; va_start(args, format); vsprintf(buffer, format, args); va_end(args); glRasterPos2i(x, y); for (s = buffer; *s; s++) glutBitmapCharacter(font_style, *s); } void cell_draw(cell* cell) { glColor3ub(0, 255, 128); if (selection == cell->id) { glColor3ub(255, 255, 0); drawstr(10, 525, cell->info); glColor3ub(255, 0, 0); } if (cell->id == 21 && cell->value > 90.0) /* treat cutoff specially */ drawstr(cell->x, cell->y, cell->format, 180.0); else drawstr(cell->x, cell->y, cell->format, cell->value); } int cell_hit(cell* cell, int x, int y) { if (x > cell->x && x < cell->x+60 && y > cell->y-20 && y < cell->y+10) return cell->id; return 0; } void cell_update(cell* cell, int update) { if (selection != cell->id) r
评论
    相关推荐
    • test7-光照演示.zip
      OpenGL初学教程实例,光照关系的演示
    • 光照模型.rar
      光照环境的三棱锥,当光照射到一个物体表面上时,会出现三种情形。首先,光可以通过物体表面向空间反射,产生反射光;其次,对于透明物体,光可以穿透该物体并从另一端射出,产生透射光;最后,部分光被物体表面吸收...
    • 光照传感器.rar
      网上大多数关于光照传感器的程序都是51,我们写了一份关于32的程序,这样我们在熟悉的单片机上也能编程
    • PS模拟自然光照滤镜
      模拟自然光照滤镜 非常好用的一款PHOTOSHOP的滤镜 在这里共享给大家
    • 光照校正 MATLAB
      光照均匀校正 MATLAB代码 只能对灰度图像进行处理
    • 光照模型算法
      计算机图形学:利用VC++实现冯氏光照模型,
    • android 光照
      一个介绍android opengl 光照的学习工程
    • matlab的光照校正
      matlab的光照校正
    • 种植1.1-光照.rar
      这是一个光照小板20万量程的程序,基于STC15F2K60S2单片机编写,经过量产检验的程序
    • 光照实例.zip
      是用c语言在单片机上经行编程,是用PCF8591经行数模转换