Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[7f9531]: light.c Maximize Restore History

Download this file

light.c    105 lines (88 with data), 3.2 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
/* Asteroids3D - a first person game of blowing up asteroids
* Copyright (C) 2000 Stuart Mark Pomerantz <smp [at] psc edu>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* Stuart Pomerantz
* 3935 Stonecliffe drive
* Monroeville, PA 15146
*/
#include <GL/glut.h>
#include "asteroids3D.h"
/* light0 (the sun) position
* light1 (headlight) position & direction
* light2 torpedo tracer
*/
float l0_pos[4], l1_pos[4], l1_dir[4];
void gl_init_light(void) {
static const float global_ambient[] = {0.1, 0.1, 0.1, 1.0}; /* original */
//static const float global_ambient[] = {0.5, 0.5, 0.5, 1.0}; /* for debugging */
static const float ambient[] = {0.0, 0.0, 0.0, 1.0};
static const float diffuse[] = {1.0, 1.0, 0.8, 1.0}; /* slightly yellow sun */
static const float specular[] = {0.0, 0.0, 0.0, 1.0};
/* w = 0 implies a directional source (light coming parallel to this vector)*/
l0_pos[0] = 70.0;
l0_pos[1] = 0.0 ;
l0_pos[2] = 0.0 ;
l0_pos[3] = 0.0 ;
glEnable(GL_LIGHTING) ;
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,global_ambient);
glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER,1);
glEnable(GL_LIGHT0) ;
glLightfv(GL_LIGHT0,GL_AMBIENT,ambient) ;
glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuse) ;
glLightfv(GL_LIGHT0,GL_SPECULAR,specular) ;
glLightfv(GL_LIGHT0,GL_POSITION,l0_pos) ;
return ;
}
void toggle_headlight(void) {
static int headlight_activated = 0 ;
if(!headlight_activated) {
glEnable(GL_LIGHT1) ;
headlight_activated = 1 ;
} else {
glDisable(GL_LIGHT1) ;
headlight_activated = 0 ;
}
return ;
}
void gl_init_headlight(void) {
static const float ambient[] = {0, 0, 0, 1};
static const float diffuse[] = {1, 1, 1, 1}; /* white headlight */
static const float specular[] = {0, 0, 0, 1};
/* set the initial headlight position to be at the viewer's position */
l1_pos[0] = pos.x ;
l1_pos[1] = pos.y ;
l1_pos[2] = pos.z ;
l1_pos[3] = 1.0 ;
/* set the initial headlight direction to be down the positive z-axis,
* which is where the view was set to be in reset_view()
*/
l1_dir[0] = pos.x + zaxis.x ;
l1_dir[1] = pos.y + zaxis.y ;
l1_dir[2] = pos.z + zaxis.z ;
l1_dir[3] = 1.0 ;
glLightfv(GL_LIGHT1,GL_AMBIENT,ambient) ;
glLightfv(GL_LIGHT1,GL_DIFFUSE,diffuse) ;
glLightfv(GL_LIGHT1,GL_SPECULAR,specular) ;
glLightfv(GL_LIGHT1,GL_POSITION,l1_pos) ;
glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION,l1_dir) ;
glLightf(GL_LIGHT1,GL_SPOT_CUTOFF,20) ;
/* glLightf(GL_LIGHT1,GL_CONSTANT_ATTENUATION, 0.04) ;
glLightf(GL_LIGHT1,GL_QUADRATIC_ATTENUATION, 0.04) ;
*/
return ;
}