예제 #1
0
int main(int argc, char** argv)
{
	PrintControls();
	InitGlut(argc, argv, "Lesson 405: Grass");
	NewLight();
    InitNx();
    glutMainLoop();
	ReleaseNx();
	return 0;
}
예제 #2
0
/**
 * Creates and sets up the hero entity
 * @return The hero entity created
 */
Entity_T *SetupHero()
{
	int i, x;
	const GLfloat SPRITE_WIDTH = 32.0f / 128;
	const GLfloat SPRITE_HEIGHT = 48.0f / 192;
	Rect frames[20];
	Animation_T animations[MAX_ANIMATIONS];
	Entity_T *e = NewEntity();
	e->currentAnimation = 0;
	e->currentFrame = 0;
	e->sprite = NewSprite();
	e->body = cpBodyNew(100.0f, 100.0f);
	e->size.x = TILE_WIDTH;
	e->size.y = 1.5f * TILE_HEIGHT;
	e->shape = cpBoxShapeNew(e->body, e->size.x/2, e->size.y/2);
	

	for(i = 0;i < 20;i++)
	{
		frames[i].x = (i % 4) * SPRITE_WIDTH;
		frames[i].y = 1.0f - (i/4+1) * SPRITE_HEIGHT;
		frames[i].w = SPRITE_WIDTH;
		frames[i].h = SPRITE_HEIGHT;
	}
	
	for(x = 0;x < 4;x++)
	{
		animations[x].numFrames = 1;
		animations[x].frames[0] = x*4;
		animations[x].frameLengths[0] = 100;
		animations[x].flags = ANIMFLAG_NONE;
	}

	for(x = 4;x < 8;x++){
		animations[x].numFrames = 4;
		for(i = 0;i < 4;i++){
			animations[x].frames[i] = (x-4)*4+i;
			animations[x].frameLengths[i] = 100;
		}
		animations[x].flags = ANIMFLAG_NONE;
	}
	SetupSprite(e->sprite, "hero.png", frames, 20, animations, 8);
	//Set up the hero's inner light
	e->light = NewLight();
	e->light->brightness = 0.75f;
	e->light->color.x = 1.0f;
	e->light->color.y = .95f;
	e->light->color.z = 0.5f;
	e->light->span = TILE_WIDTH / 2;
	e->light->offset.x = TILE_WIDTH / 2;
	e->light->offset.y = 0;
	SET_FLAG(e->flags, ENTFLAG_LIGHT);
	e->next = NULL;
	return e;
}
예제 #3
0
Entity_T *SetupObject(int object)
{
	int i, x;
	const GLfloat SPRITE_WIDTH = 32.0f / 128;
	const GLfloat SPRITE_HEIGHT = 48.0f / 192;
	Rect frames[20];
	Animation_T animations[MAX_ANIMATIONS];
	Entity_T *e = NewEntity();
	e->currentAnimation = 0;
	e->currentFrame = 0;
	e->sprite = NewSprite();
	e->body = cpBodyNew(1.0f, 1.0f);
	e->size.x = TILE_WIDTH;
	e->size.y = 1.5f * TILE_HEIGHT;
	e->shape = cpBoxShapeNew(e->body, e->size.x/2, e->size.y/2);
	
	frames[0].x = 0;
	frames[0].y = 0;
	frames[0].w = 1;
	frames[0].h = 1;
	
	animations[0].numFrames = 1;
	animations[0].frames[0] = 0;
	animations[0].frameLengths[0] = 100;
	animations[0].flags = ANIMFLAG_NONE;

	//TODO: Kludgy as heck, redo later.
	switch(object){
	case 0:
		SetupSprite(e->sprite, "torch.png", frames, 1, animations, 1);
		e->light = NewLight();
		e->light->color.x = 1.0f;
		e->light->color.y = 0.0f;
		e->light->color.z = 1.0f;
		e->light->brightness = 0.75f;
		e->light->span = TILE_WIDTH * .75f;
		e->light->offset.x = TILE_WIDTH / 2;
		e->light->offset.y = 0;
		SET_FLAG(e->flags, ENTFLAG_LIGHT);
		e->currentAnimation = 0;
		e->currentFrame = 0;
		e->dir = ENTDIR_DOWN;
		break;
	}
	return e;
}
예제 #4
0
void SetupDefaultLights()
{
  GlLight *light;
  GlLight *light2;
  float fogcolor[4] = {0.75,.5,.4,1};
  ShaderProg = LoadShaderProgram("shaders/lighting1.vert","shaders/lighting1.frag");
  

   light=NewLight();
      light->ambientLight[0] =0.50f;
      light->ambientLight[1] =0.50f;
      light->ambientLight[2] =0.50f;
      light->ambientLight[3] =1.0f;
  
      light->diffuseLight[0] =1.0f;
      light->diffuseLight[1] =1.0f;
      light->diffuseLight[2] =1.0f;
      light->diffuseLight[3] =1.0f;
  
      light->specLight[0] =0.50f;
      light->specLight[1] =0.50f;
      light->specLight[2] =0.50f;
      light->specLight[3] =1.0f;
  
      light->direction[0] =1.0f;
      light->direction[1] =0.0f;
      light->direction[2] =0.0f;
      
      light->pos[0] =32.0f;
      light->pos[1] =15.0f;
      light->pos[2] =-32.0f;
      light->pos[3] =1.0f;
      light->spotEdge = 90.0f;
      light->spotAngle = 180.0f;
      light->useRot = 1;
      light->rot.x = 0;
      light->rot.y = 0;
      light->rot.z = 0;
      
      light2=NewLight();
      light2->ambientLight[0] =0.4f;
      light2->ambientLight[1] =0.4f;
      light2->ambientLight[2] =0.4f;
      light2->ambientLight[3] =1.0f;
  
      light2->diffuseLight[0] =1.0f;
      light2->diffuseLight[1] =1.0f;
      light2->diffuseLight[2] =1.0f;
      light2->diffuseLight[3] =1.0f;
  
      light2->specLight[0] =1.0f;
      light2->specLight[1] =1.0f;
      light2->specLight[2] =1.0f;
      light2->specLight[3] =1.0f;
  
      light2->direction[0] =1.0f;
      light2->direction[1] =0.0f;
      light2->direction[2] =0.0f;
      
      light2->pos[0] =32.0f;
      light2->pos[1] =590.0f;
      light2->pos[2] =-32.0f;
      light2->pos[3] =1.0f;
      light2->spotAngle =90.0f;
      light2->spotEdge = 180.0f;
      light2->useRot = 1;
      light2->rot.x = 0;
      light2->rot.y = 0;
      light2->rot.z = 180;


      
      glLightf(GL_LIGHT0,GL_CONSTANT_ATTENUATION, 0.0f);
      glLightf(GL_LIGHT0,GL_LINEAR_ATTENUATION, 0.02f);
      glLightf(GL_LIGHT0,GL_QUADRATIC_ATTENUATION, 0.000002f);
      glLightf(GL_LIGHT1,GL_CONSTANT_ATTENUATION, 0.001f);
      glLightf(GL_LIGHT1,GL_LINEAR_ATTENUATION, 0.02f);
      glLightf(GL_LIGHT1,GL_QUADRATIC_ATTENUATION, 0.000002f);
      glEnable(GL_LIGHT0);
      glEnable(GL_LIGHT1);
      glEnable(GL_FOG);
      glFogfv(GL_FOG_COLOR,fogcolor);
      glFogi(GL_FOG_MODE, GL_EXP);
      glFogf(GL_FOG_DENSITY, 0.001f);
      glFogf(GL_FOG_START, 1.0f);
      glFogf(GL_FOG_END, 2000.0f);
      /*
  light=NewLight();
  light->ambientLight[0] =0.7f;
  light->ambientLight[1] =0.7f;
  light->ambientLight[2] =0.7f;
  light->ambientLight[3] =1.0f;
  
  light->diffuseLight[0] =1.0f;
  light->diffuseLight[1] =1.0f;
  light->diffuseLight[2] =1.0f;
  light->diffuseLight[3] =1.0f;
  
  light->specLight[0] =1.0f;
  light->specLight[1] =1.0f;
  light->specLight[2] =1.0f;
  light->specLight[3] =1.0f;
  
  light->direction[0] =0.0f;
  light->direction[1] =0.0f;
  light->direction[2] =1.0f;
  
  light->pos[0] =32.0f;
  light->pos[1] =15.0f;
  light->pos[2] =32.0f;
  light->pos[3] =1.0f;
  light->spotEdge = 0.0f;
  light->spotAngle = 180.0f;
  light->useRot = 1;
  light->rot.x = 0;
  light->rot.y = 0;
  light->rot.z = 180;
  
  light2=NewLight();
  light2->ambientLight[0] =0.9f;
  light2->ambientLight[1] =0.9f;
  light2->ambientLight[2] =0.9f;
  light2->ambientLight[3] =1.0f;
  
  light2->diffuseLight[0] =1.0f;
  light2->diffuseLight[1] =1.0f;
  light2->diffuseLight[2] =1.0f;
  light2->diffuseLight[3] =1.0f;
  
  light2->specLight[0] =1.0f;
  light2->specLight[1] =1.0f;
  light2->specLight[2] =1.0f;
  light2->specLight[3] =1.0f;
  
  light2->direction[0] =0.0f;
  light2->direction[1] =0.0f;
  light2->direction[2] =1.0f;
  
  light2->pos[0] =0.0f;
  light2->pos[1] =0.0f;
  light2->pos[2] =-32.0f;
  light2->pos[3] =1.0f;
  light2->spotAngle =0.0f;
  light2->spotEdge = 90.0f;
  light2->useRot = 1;
  light2->rot.x = 0;
  light2->rot.y = 0;
  light2->rot.z = 0;*/
  /*
  light=NewLight();
  light->ambientLight[0] =1.0f;
  light->ambientLight[1] =1.0f;
  light->ambientLight[2] =1.0f;
  light->ambientLight[3] =1.0f;
  
  light->diffuseLight[0] =1.0f;
  light->diffuseLight[1] =1.0f;
  light->diffuseLight[2] =1.0f;
  light->diffuseLight[3] =1.0f;
  
  light->specLight[0] =1.0f;
  light->specLight[1] =1.0f;
  light->specLight[2] =1.0f;
  light->specLight[3] =1.0f;
  
  light->direction[0] =0.0f;
  light->direction[1] =0.0f;
  light->direction[2] =1.0f;
  
  light->pos[0] =0.0f;
  light->pos[1] =0.0f;
  light->pos[2] =-32.0f;
  light->pos[3] =0.0f;
  light->spotEdge = 1.0f;
  light->spotAngle = 45.0f;
  light->useRot = 1;
  light->rot.x = 0;
  light->rot.y = 0;
  light->rot.z = 0;
  
  */
/*  glLightf(GL_LIGHT0,GL_CONSTANT_ATTENUATION, 0.0f);
  glLightf(GL_LIGHT0,GL_LINEAR_ATTENUATION, 0.02f);
  glLightf(GL_LIGHT0,GL_QUADRATIC_ATTENUATION, 0.000002f);
  glLightf(GL_LIGHT1,GL_CONSTANT_ATTENUATION, 0.001f);
  glLightf(GL_LIGHT1,GL_LINEAR_ATTENUATION, 0.02f);
  glLightf(GL_LIGHT1,GL_QUADRATIC_ATTENUATION, 0.000002f);
  glLightf(GL_LIGHT2,GL_CONSTANT_ATTENUATION, 0.001f);
  glLightf(GL_LIGHT2,GL_LINEAR_ATTENUATION, 0.02f);
  glLightf(GL_LIGHT2,GL_QUADRATIC_ATTENUATION, 0.000002f);
  glEnable(GL_LIGHT0);
  glEnable(GL_LIGHT1);
//  glEnable(GL_LIGHT2);
  glEnable(GL_FOG);
  glFogfv(GL_FOG_COLOR,fogcolor);
  glFogi(GL_FOG_MODE, GL_EXP);
  glFogf(GL_FOG_DENSITY, 0.001f);
  glFogf(GL_FOG_START, 0.8f);
  glFogf(GL_FOG_END, 2000.0f);*/

}