Ejemplo n.º 1
0
int main(int argc, char** argv) {
    
    int aux;	
    // inicialización del GLUT
    glutInit( &argc, argv );
    // inicialiación de la ventana
    glutInitWindowSize( 1020, 850 );  //Tamaño de la Ventana Creada
    glutInitWindowPosition( 100, 100 );
    glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    glutCreateWindow( "Catastrofe Global - Fin del Sol" );
    glEnable(GL_SMOOTH);
    // inicialización de los datos del programa
    anos = 0;
    dia  = 0;
    hora = 0;
    min  = 0;
    explo= 0;
    mov  = 0;
    mov2 = 0.01;
    mov3 = 0;
    //derr = x; arr = y; z = z
    der  = -5;
    arr  = 5;
    z    = -35;
    //Variable para controlar el menú.
    value = 0;
    //Creamos el menú.
    createMenu();
    // registro de los eventos
    glutReshapeFunc (reshapeevent);
    glutDisplayFunc( displayevent );
    //Cambio de teclas por menú.
    glutSpecialFunc( specialkeyevent );
    //Controlamos no sólo las teclas especiales, las normales también 
    //(Para aumentar y reducir velocidad de rotación)
    //glutKeyboardFunc (Keyboard);
    glutIdleFunc( animacion );
    aux = carga_texturas();
    // lazo de eventos
    glutMainLoop();
    return 0;
}
Ejemplo n.º 2
0
int init_gl(void)
{

  int i,j;
	
	/* Vamos a preparar las matrices de proyección */

	glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45.0f,
		   (GLfloat) config.SCREEN_SIZE_X /
		   (GLfloat) config.SCREEN_SIZE_Y, 0.01f, 100000.0f);
	
	glGetDoublev(GL_PROJECTION_MATRIX,&matriz_proyeccion_A[0][0]);

	glLoadIdentity();
    gluPerspective(45.0f,
		   (GLfloat) config.SCREEN_SIZE_X /
		   (GLfloat) config.SCREEN_SIZE_Y, 0.01f, 100000.0f);

	glGetDoublev(GL_PROJECTION_MATRIX,&matriz_proyeccion_B[0][0]);

	glLoadIdentity();
	glOrtho(0,config.SCREEN_SIZE_X,0,config.SCREEN_SIZE_Y,-100,100);					
	glGetDoublev(GL_PROJECTION_MATRIX,&matriz_proyeccion_C[0][0]);

	glLoadMatrixd(&matriz_proyeccion_A[0][0]);

	fprintf(logs,"Matrices de proyección creadas\n");



    /* Esto resetea la matriz de modelado y la de la camara*/


	glMatrixMode(GL_MODELVIEW);

	glLoadIdentity();

    glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient0);	
    glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse0);	
   	glLightfv(GL_LIGHT0, GL_POSITION, LightPosition0);	

    glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient1);	
    glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse0);	


    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHT1);
    
	glEnable(GL_LIGHTING);
	

	
  /* Inicialización de la matriz camara */
  glGetFloatv(GL_MODELVIEW_MATRIX,&camara[0][0]);
	
	camara[2][2]=1.0f;
	camara[3][2]=-1.0f;


	fprintf(logs,"Camara inicializada\n");

    /* Ahora establecemos el color de fondo por defecto. Está en formato RGBA y lo ponemos a negro */

	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    
	/* Estas 3 líneas habilitan del Buffer de profundidad*/
	
	glClearDepth(1.0f);
    
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);

	glEnable (GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    
	/* Esta función sirve para optimizar el renderizado, y se utiliza para muchas cosas. En este caso es para
	hacer un buen cálculo de la perspectiva perdiendo un poco de rendimiento*/

	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    
 	fprintf(logs,"Iniciando carga de texturas...\n");

	/* Cargamos la textura */

	glEnable(GL_TEXTURE_2D);
	glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 );
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	





  if (carga_texturas()!=0) {
		sys_msg("Las texturas no se ha podido cargar");

	}

	else 
		fprintf(logs,"Texturas cargadas..\n");
 

	glShadeModel(GL_FLAT);			/* SMOOTH SHADING */

  glEnable(GL_POINT_SMOOTH);
	glCullFace(GL_BACK);
	glEnable(GL_CULL_FACE);
	
	glLineWidth(5.0f);
	glEnable(GL_LINE_SMOOTH);
	disparo_laser.ttl=0;
	
	/* Creamos un par de fuentes */

	fprintf(logs,"Cargando fuentes..\n");
	fuentes[0]=carga_fuente("fuentes/def.tga",15,-6);
	if (fuentes[0]==NULL) {
		sys_msg("Error crítico cargando fuentes!");
		exit (-1);
	}
	
    fuentes[1]=carga_fuente("fuentes/agulon.tga",16,-4);
	if (fuentes[1]==NULL) {
		sys_msg("Error crítico cargando fuentes!");
		exit (-1);
	}
   
	fprintf(logs,"Fuentes cargadas..\n");

	/* Creando el espacio de entorno */

  fprintf(logs,"Creando el espacio\n");
	if (!init_espacio()) {
		sys_msg("Error al crear espacio\n!");
		exit (-1);
	}

	fprintf(logs,"Fuentes cargadas..\n");

    /* Inicializamos OpenAL */
    if ( InicializarAudio ( ) != 0 ){
        fprintf (logs, "No funciona el sistema de audio\n");
        audio_on = 0;
    } else {
        fprintf(logs,"OpenAL funcionando\n");
    }

    /* Cargamos sonidos y musica*/
    if ( audio_on == 1){
        CargaSonido ("ws_datos/sonidos/laser.wav", 0);
         fprintf(logs,"Cargado sonido del laser\n");
        /*CargaSonido ("ws_datos/sonidos/motor_nuestro.wav", 1);
         fprintf(logs,"Cargado sonido de nuestra nave\n");*/
        CargaSonido ("ws_datos/sonidos/sonido_nave_enemiga.wav", 2);
         fprintf(logs,"Cargado sonido de la nave enemiga\n");
        CargarMusica ("ws_datos/musicas/prueba.ogg");
         fprintf (  logs, "Cargado musica\n");
    }


   

	fprintf(logs,"OpenGL inicializado sin errores críticos...\n");  			
	
	return 0;
	
}