Example #1
0
void initOpenGL(){
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);
	glEnable(GL_NORMALIZE);
	glEnable(GL_LIGHT0);
	glClearColor(1.0f, 1.0f, 1.0f, 0.0f);

	int w,h;
	GLenum format, type;
	GLvoid *data;
	load_targa("yellobrk.tga", w, h, format, type, data);
	
	glGenTextures(2, &texture[0]);	
	glBindTexture(GL_TEXTURE_2D, texture[0]);
	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
	gluBuild2DMipmaps(GL_TEXTURE_2D, 3, w, h, format, type, data);

}
void Inicjuj( sf::RenderWindow &app )
{
    font.loadFromFile( "fonts/comicbd.ttf" );

    std::string str( "Ladowanie textur..." );
    CStopWatch timer;

    pisz( app, str );

    const char *chTextures[ LiczbaTextur ] = {  "textures/background.tga",
                                                "textures/cross.tga",
                                                "textures/life.tga",
                                                "textures/blood.tga",
                                                "textures/enemy.tga",
                                                "textures/comet.tga",
                                                "textures/bullet.tga",
                                                "textures/award.tga" };

    GLsizei width, height;
    GLenum format, type;
    GLvoid *pixels;

    glPixelStorei(GL_UNPACK_ALIGNMENT,1);

    for ( int i = 0; i < LiczbaTextur; ++i ){

        if ( !load_targa( chTextures[i], width, height, format, type, pixels) ){
            str = "Brak pliku ";
            str += chTextures[i];
            pisz( app, str );
            while ( timer.GetElapsedSeconds() < 1.0f ){
                continue;
            }
        }

        glGenTextures(1,&t_textures[ i ]);
        glBindTexture(GL_TEXTURE_2D, t_textures[ i ]);
        gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA,width,height,format,type,pixels);

        delete [] (unsigned char *)pixels;
    }

    str = "Ladowanie modeli...";
    pisz( app, str );

    load_obj( "models/award/WoodenBox02.obj", model_award );
    load_obj( "models/comet/Rock.obj", model_rock );
    load_obj( "models/bullet/bullet.obj", model_bullet );
    load_obj( "models/SpaceShip/fighter.obj", model_space_ship );

    str = "Ladowanie dzwiekow...";
    pisz( app, str );

    const char *chMusic[ LiczbaDzwiekow ] = {   "sounds/MenuBackground#1.ogg",
                                                "sounds/MenuBackground#2.ogg",
                                                "sounds/Background.ogg",
                                                "sounds/fire.ogg",
                                                "sounds/Award.ogg",
                                                "sounds/ColShipComet.ogg",
                                                "sounds/ColShipShip.ogg",
                                                "sounds/CometExplo.ogg",
                                                "sounds/lifeLost.ogg",
                                                "sounds/ShipExplo.ogg",
                                                "sounds/hit.ogg" };

    for ( int i = 0; i < LiczbaDzwiekow; ++i ){
        if ( !sounds[i].openFromFile( chMusic[i] ) ){
            str = "Brak pliku ";
            str += chMusic[i];
            pisz( app, str );
            while ( timer.GetElapsedSeconds() < 1.0f ){
                continue;
            }
        }
    }

    sounds[0].setRelativeToListener( true );
    sounds[1].setRelativeToListener( true );
    sounds[2].setRelativeToListener( true );
    sounds[3].setRelativeToListener( true );
    sounds[4].setRelativeToListener( true );
    sounds[8].setRelativeToListener( true );
    sounds[10].setRelativeToListener( true );

    sounds[2].setLoop( true );
    sounds[2].setVolume( 20 );

    sounds[9].setMinDistance( 7.0f );
    sounds[9].setAttenuation( 15.0f );
    sounds[7].setMinDistance( 7.0f );
    sounds[7].setAttenuation( 15.0f );

    sf::Listener::setGlobalVolume( 100.f );
    sf::Listener::setDirection( 0.0f, 0.0f, -1.0f );

    str = "Inicjowaie list wyswietlania...";
    pisz( app, str );

    ///Lista tla!
    list_SkyBox = glGenLists( 1 );
    glNewList( list_SkyBox, GL_COMPILE );

        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, t_textures[0] );

        glBegin( GL_QUADS );
            ///Tyl
            glNormal3f( 0.0f, 0.0f, 1.0f );

            glTexCoord2f(0, 1); glVertex3f(-1, -1, 1);
            glTexCoord2f(1, 1); glVertex3f(1, -1, 1);
            glTexCoord2f(1, 0); glVertex3f(1, 1, 1);
            glTexCoord2f(0, 0); glVertex3f(-1, 1, 1);

        glEnd();

        glDisable( GL_TEXTURE_2D );

    glEndList();

    ///Lista celownika
    list_cross = glGenLists( 1 );
    glNewList( list_cross, GL_COMPILE );

        glColor3fv( White );

        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
        glEnable( GL_BLEND );

        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, t_textures[1] );

        glBegin( GL_QUADS );

            glNormal3f( 0.0f, 0.0f, 1.0f );

            glTexCoord2f(0, 1); glVertex3f(-1, -1, 1);
            glTexCoord2f(1, 1); glVertex3f(1, -1, 1);
            glTexCoord2f(1, 0); glVertex3f(1, 1, 1);
            glTexCoord2f(0, 0); glVertex3f(-1, 1, 1);

        glEnd();

        glDisable( GL_TEXTURE_2D );

        glDisable( GL_BLEND );

    glEndList();

    ///lista zycia
    list_life = glGenLists( 1 );
    glNewList( list_life, GL_COMPILE );

        glColor3fv( White );

        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
        glEnable( GL_BLEND );

        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, t_textures[2] );

        glBegin( GL_QUADS );

            glNormal3f( 0.0f, 0.0f, 1.0f );

            glTexCoord2f(0, 1); glVertex3f(-1, -1, 1);
            glTexCoord2f(1, 1); glVertex3f(1, -1, 1);
            glTexCoord2f(1, 0); glVertex3f(1, 1, 1);
            glTexCoord2f(0, 0); glVertex3f(-1, 1, 1);

        glEnd();

        glDisable( GL_TEXTURE_2D );

        glDisable( GL_BLEND );

    glEndList();

    ///lista krwi
    list_blood = glGenLists( 1 );
    glNewList( list_blood, GL_COMPILE );

        glColor3fv( White );

        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
        glEnable( GL_BLEND );

        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, t_textures[3] );

        glBegin( GL_QUADS );

            glNormal3f( 0.0f, 0.0f, 1.0f );

            glTexCoord2f(0, 1); glVertex3f(-1, -1, 1);
            glTexCoord2f(1, 1); glVertex3f(1, -1, 1);
            glTexCoord2f(1, 0); glVertex3f(1, 1, 1);
            glTexCoord2f(0, 0); glVertex3f(-1, 1, 1);

        glEnd();

        glDisable( GL_TEXTURE_2D );

        glDisable( GL_BLEND );

    glEndList();

    list_dron = glGenLists( 1 );
    glNewList( list_dron, GL_COMPILE );

        glEnable( GL_LIGHTING );
        glEnable( GL_LIGHT0 );

        glEnable( GL_COLOR_MATERIAL );
        glColorMaterial( GL_FRONT, GL_AMBIENT );

        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, t_textures[4] );

        glRotatef( -90.0f, 1.0f, 0.0f, 0.0f );
        glScalef( 0.22f, 0.22f, 0.22f );

        glCallList( model_space_ship );

        glDisable( GL_TEXTURE_2D );


        glDisable( GL_COLOR_MATERIAL );
        glDisable( GL_LIGHTING );

    glEndList();

    list_award = glGenLists( 1 );
    glNewList( list_award, GL_COMPILE );

    glEnable( GL_TEXTURE_2D );
    glBindTexture( GL_TEXTURE_2D, t_textures[7] );

    glEnable( GL_LIGHTING );
    glEnable( GL_LIGHT0 );

    glEnable( GL_COLOR_MATERIAL );
    glColorMaterial( GL_FRONT, GL_AMBIENT );

    glCallList( model_award );

    glDisable( GL_COLOR_MATERIAL );
    glDisable( GL_LIGHTING );

    glDisable( GL_TEXTURE_2D );

    glEndList();

    list_rock = glGenLists( 1 );
    glNewList( list_rock, GL_COMPILE );

        glEnable( GL_LIGHTING );
        glEnable( GL_LIGHT0 );

        glEnable( GL_COLOR_MATERIAL );
        glColorMaterial( GL_FRONT, GL_AMBIENT );

        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, t_textures[5] );

        glCallList( model_rock );

        glDisable( GL_TEXTURE_2D );

        glDisable( GL_COLOR_MATERIAL );
        glDisable( GL_LIGHTING );

    glEndList();

    list_bullet = glGenLists( 1 );
    glNewList( list_bullet, GL_COMPILE );

        glEnable( GL_TEXTURE_2D );
        glBindTexture( GL_TEXTURE_2D, t_textures[6] );

        glScaled(0.7,0.7,0.7);
        glCallList( model_bullet );

        glDisable( GL_TEXTURE_2D );

    glEndList();

    str = "Pobieranie rankingu...";
    pisz( app, str );

    if ( DownloadFile() ) {
        str = "Pobieranie zakonczone...";
    } else {
        str = "Nie udalo sie pobrac rankingu!";
    }

    pisz( app, str );

    while ( timer.GetElapsedSeconds() < 1.0f ){
        continue;
    }

    str = "Tworzenie rankingu...";
    pisz( app, str );

    std::ifstream fin( "ranking.txt" );

        if ( fin.good() ) {
            for ( int i = 0; i < 10; ++i ) {
                fin >> Top10[i].punkty;
                fin >> Top10[i].zycia;
                fin >> Top10[i].statki;
                fin >> Top10[i].nagrody_zdobyte;
                fin >> Top10[i].rozwalone_nagrody;
                fin >> Top10[i].rozbite_asteroidy;
                char ch;
                fin.get( ch );
                ch = 'p';
                while ( ch != '\n' && ch != '\r' ) {
                    fin.get( ch );
                    Top10[i].name += ch;
                }
            }
        } else {
void GenerateTextures()
{
	// zmienne użyte przy obsłudze plików TARGA
	GLsizei width, height;
	GLenum format, type;
	GLvoid *pixels;

	// tryb upakowania bajtów danych tekstury
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	// wskazówki do kompresji tesktur
	glHint(GL_TEXTURE_COMPRESSION_HINT, texture_compression_hint);

	// wczytanie tekstury white_skin_guy_black_hairs.tga
	GLboolean error = load_targa("white_skin_guy_black_hairs.tga", width, height, format, type, pixels);

	// błąd odczytu pliku
	if (error == GL_FALSE)
	{
		printf("Niepoprawny odczyt pliku white_skin_guy_black_hairs.tga");
		exit(0);
	}

	// utworzenie identyfikatora tekstury
	glGenTextures(1, &LENA);

	// dowiązanie stanu tekstury
	glBindTexture(GL_TEXTURE_2D, LENA);

	// definiowanie tekstury z kompresją
	glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB, width, height, 0, format, type, pixels);

	// utworzenie identyfikatora tekstury
	glGenTextures(1, &LENA_UNC);

	// dowiązanie stanu tekstury
	glBindTexture(GL_TEXTURE_2D, LENA_UNC);

	// definiowanie tekstury bez kompresji
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, format, type, pixels);

	// porządki
	delete[](unsigned char*)pixels;

	// wczytanie tekstury white_skin_guy_black_hairs_gray.tga
	error = load_targa("white_skin_guy_black_hairs_gray.tga", width, height, format, type, pixels);

	// błąd odczytu pliku
	if (error == GL_FALSE)
	{
		printf("Niepoprawny odczyt pliku white_skin_guy_black_hairs_gray.tga");
		exit(0);
	}

	// utworzenie identyfikatora tekstury
	glGenTextures(1, &LENA_GRAY);

	// dowiązanie stanu tekstury
	glBindTexture(GL_TEXTURE_2D, LENA_GRAY);

	// definiowanie tekstury z kompresją
	glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_LUMINANCE, width, height, 0, format, type, pixels);

	// utworzenie identyfikatora tekstury
	glGenTextures(1, &LENA_GRAY_UNC);

	// dowiązanie stanu tekstury
	glBindTexture(GL_TEXTURE_2D, LENA_GRAY_UNC);

	// definiowanie tekstury bez kompresji
	glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0, format, type, pixels);

	// porządki
	delete[](unsigned char*)pixels;

	// wybór bieżącej tekstury
	texture = LENA;
}
Example #4
0
void GenerateTextures()
{
	// zmienne użyte przy obsłudze plików TARGA
	GLsizei width, height;
	GLenum format, type;
	GLvoid *pixels;

	// tryb upakowania bajtów danych tekstury
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

	// wczytanie tekstury Venus utworzonej ze zdjęć sondy Magellan
	GLboolean error = load_targa("saturn.tga", width, height, format, type, pixels);

	// błąd odczytu pliku
	if (error == GL_FALSE)
	{
		printf("Niepoprawny odczyt pliku saturn.tga");
		exit(0);
	}

	// utworzenie identyfikatora tekstury
	glGenTextures(1, &VENUS);

	// dowiązanie stanu tekstury
	glBindTexture(GL_TEXTURE_2D, VENUS);

	// utworzenie tekstury wraz z mipmapami
	gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, width, height, format, type, pixels);

	// porządki
	delete[](unsigned char*)pixels;

	// wczytanie tekstury z hipsometryczną (fizyczną) mapą Ziemi
	error = load_targa("saturn.tga", width, height, format, type, pixels);

	// błąd odczytu pliku
	if (error == GL_FALSE)
	{
		printf("Niepoprawny odczyt pliku saturn.tga");
		exit(0);
	}

	// utworzenie identyfikatora tekstury
	glGenTextures(1, &EARTH);

	// dowiązanie stanu tekstury
	glBindTexture(GL_TEXTURE_2D, EARTH);

	// utworzenie tekstury wraz z mipmapami
	gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, width, height, format, type, pixels);

	// porządki
	delete[](unsigned char*)pixels;

	// wczytanie tekstury Marsa utworzonej ze zdjęć sond Viking
	error = load_targa("saturn.tga", width, height, format, type, pixels);

	// błąd odczytu pliku
	if (error == GL_FALSE)
	{
		printf("Niepoprawny odczyt pliku saturn.tga");
		exit(0);
	}

	// utworzenie identyfikatora tekstury
	glGenTextures(1, &MARS);

	// dowiązanie stanu tekstury
	glBindTexture(GL_TEXTURE_2D, MARS);

	// utworzenie tekstury wraz z mipmapami
	gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, width, height, format, type, pixels);

	// porządki
	delete[](unsigned char*)pixels;

	// wczytanie tekstury Jowisza
	error = load_targa("saturn.tga", width, height, format, type, pixels);

	// błąd odczytu pliku
	if (error == GL_FALSE)
	{
		printf("Niepoprawny odczyt pliku saturn.tga");
		exit(0);
	}

	// utworzenie identyfikatora tekstury
	glGenTextures(1, &JUPITER);

	// dowiązanie stanu tekstury
	glBindTexture(GL_TEXTURE_2D, JUPITER);

	// utworzenie tekstury wraz z mipmapami
	gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, width, height, format, type, pixels);

	// porządki
	delete[](unsigned char*)pixels;

	// identyfikator bieżącej tekstury
	texture = EARTH;
}