Example #1
0
void VueCarte::genererCarte(ConfigurationCarte const& configurationCarte)
{
	chargerTexture();
	/*
	ID DECORS :
	0 : plateforme
	1 : boite3x3
	2 : herbe
	3 : boitesEscalier
	4 : fumee
	5 :	baseTeleporteur
	6 : traitTeleporteur
	7 : cercleTeleporteur

	id decors / niveauAffichage / abscisse / ordonnee / tailleX / tailleY

	0	0	0	225	15	1
	0	0	575	225	18	1
	1	0	325	350	1	1
	2	0	525	350	19	1
	3	0	0	425	1	1
	0	0	325	425	28	1
	4	0	0	575	1	1
	0	0	0	675	15	1
	0	0	575	675	18	1
	5	0	725	625	1	1
	6	1	725	575	1	1	
	7	1	725	525	1	1
	6	1	725	475	1	1
	7	1	725	425	1	1
	6	1	725	375	1	1
	*/

	for (unsigned int i = 0; i < configurationCarte.decors.size(); i++)
	{
		ajouterDecors(getCle(configurationCarte.decors[i].getCleDecors()),
			configurationCarte.decors[i].getAbscisse(),
			configurationCarte.decors[i].getOrdonnee(),
			configurationCarte.decors[i].getTailleLigne(),
			configurationCarte.decors[i].getTailleColonne(),
			configurationCarte.decors[i].getNiveauAffichage());
	}
}
Example #2
0
void load_texture(char numero_sauvegarde[100])
{
 glEnable(GL_TEXTURE_2D);
 glColor3ub(WHITE_COLOR);

 GLuint matexture = chargerTexture(numero_sauvegarde);

 glColor3ub(WHITE_COLOR);

 glBindTexture(GL_TEXTURE_2D, matexture);
 glBegin(GL_QUADS);
     glTexCoord2d(0,1);  glVertex2d(0,SIZE_MENU_WIDTH);
     glTexCoord2d(0,0);  glVertex2d(0,HAUTEUR_ECRAN);
     glTexCoord2d(1,0);  glVertex2d(LARGEUR_ECRAN,HAUTEUR_ECRAN);
     glTexCoord2d(1,1);  glVertex2d(LARGEUR_ECRAN,SIZE_MENU_WIDTH);
 glEnd();

 glDisable(GL_TEXTURE_2D);

 glColor3ub(WHITE_COLOR);
}
Example #3
0
bool loadMtl(char* filename, Material** material, int* nbFinal) {

    printf("\tLoading MTL file '%s'\n", filename);

    FILE* file = fopen(filename, "r");
    if (file == NULL)
    {
        puts("Error");
        return false;
    }

    clock_t start = clock();

    ElemString* pileName = NULL;
    ElemString* pileTexture = NULL;
    ElemString* pileNormalMap = NULL;
    ElemString* pileSpecularMap = NULL;
    ElemVec3* pileAmbient = NULL;
    ElemVec3* pileDiffuse = NULL;
    ElemVec3* pileSpecular = NULL;
    ElemVec3* pileExponent = NULL;

    char lineHeader[128];
    char chaine[128] = "";
    Vec3 vecTemp;
    int i;
    bool mtlIsBeingDefined = false;

    while( 1 )
    {
        // read the first word of the line
        int res = fscanf(file, "%s", lineHeader);

        // Nouveau matériau, on stocke le nom
        if ( stricmp( lineHeader, "newmtl" ) == 0 && res != EOF)
        {
            if (mtlIsBeingDefined == false)
            {
                mtlIsBeingDefined = true;
            }

            fscanf(file, "%s", chaine);
            pileName = empilerStr(pileName, chaine);
            pileTexture = empilerStr(pileTexture, "");
            pileNormalMap = empilerStr(pileNormalMap, "");
            pileSpecularMap = empilerStr(pileSpecularMap, "");
            pileExponent = empiler(pileExponent, (Vec3) {
                20, 0, 0
            });
            pileSpecular = empiler(pileSpecular, (Vec3) {
                1, 1, 1
            });
            pileDiffuse = empiler(pileDiffuse, (Vec3) {
                1, 1, 1
            });
            pileAmbient = empiler(pileAmbient, (Vec3) {
                1, 1, 1
            });

        }
        else
        {
            if (mtlIsBeingDefined)
            {
                mtlIsBeingDefined = false;

            }
            // EOF = End Of File. Quit the loop.
            if (res == EOF)
                break;

            // Texture diffuse
            else if ( stricmp( lineHeader, "map_Kd" ) == 0 )
            {
                fscanf(file, "%s", chaine);
                strcpy(pileTexture->chaine, chaine);
            }
            // Normal map
            else if ( stricmp( lineHeader, "map_bump" ) == 0 || stricmp( lineHeader, "map_Disp" ) == 0 )
            {
                fscanf(file, "%s", chaine);
                strcpy(pileNormalMap->chaine, chaine);
            }
            // Specular map
            else if ( stricmp( lineHeader, "map_Ks" ) == 0)
            {
                fscanf(file, "%s", chaine);
                strcpy(pileSpecularMap->chaine, chaine);
            }

            // Couleur ambiante
            else if ( stricmp( lineHeader, "Ka") == 0)
            {
                fscanf(file, "%f %f %f", &vecTemp.x, &vecTemp.y, &vecTemp.z );
                pileAmbient->vec = vecTemp;
            }
            // Couleur diffuse
            else if ( stricmp( lineHeader, "Kd") == 0)
            {
                fscanf(file, "%f %f %f", &vecTemp.x, &vecTemp.y, &vecTemp.z );
                pileDiffuse->vec = vecTemp;
            }
            // Couleur spéculaire
            else if ( stricmp( lineHeader, "Ks" ) == 0 )
            {
                fscanf(file, "%f %f %f\n", &vecTemp.x, &vecTemp.y, &vecTemp.z );
                pileSpecular->vec = vecTemp;
            }
            // Exponent spéculaire
            else if ( stricmp( lineHeader, "Ns" ) == 0 )
            {
                fscanf(file, "%f", &vecTemp.x);
                pileExponent->vec = vecTemp;
            }

            else
            {
                // Probably a comment, eat up the rest of the line
                char stupidBuffer[1000];
                fgets(stupidBuffer, 1000, file);
            }
        }

    }

    int nb = getElemNumberStr(pileName);

    char** names = dumpListeToArrayStr(pileName);
    char** textures = dumpListeToArrayStr(pileTexture);
    char** normalMaps = dumpListeToArrayStr(pileNormalMap);
    char** specularMaps = dumpListeToArrayStr(pileSpecularMap);
    Vec3* ambient = dumpVec3ListeToArray(pileAmbient);
    Vec3* diffuse = dumpVec3ListeToArray(pileDiffuse);
    Vec3* specular = dumpVec3ListeToArray(pileSpecular);
    unsigned int* exponent = dumpListeToArray(pileExponent);

    *material = malloc(sizeof(Material) * nb);

    for (i = 0 ; i < nb ; i++ )
    {
        (*material)[i].type = NONE;

        strcpy((*material)[i].nom, names[i]);
        if (strlen(textures[i]) > 0)
        {
            (*material)[i].texture = chargerTexture(textures[i], GL_LINEAR_MIPMAP_LINEAR);
            (*material)[i].type |= COLOR_MAP;
        }

        if (strlen(normalMaps[i]) > 0)
        {
            (*material)[i].normalMap = chargerTexture(normalMaps[i], GL_LINEAR_MIPMAP_LINEAR);
            (*material)[i].type |= NORMAL_MAP;
        }

        if (strlen(specularMaps[i]) > 0)
        {
            (*material)[i].specularMap = chargerTexture(specularMaps[i], GL_LINEAR);
            (*material)[i].type |= SPECULAR_MAP;
        }

        if ((*material)[i].type == NONE)
        {
            (*material)[i].shader = ShaderLibrary_Get("noTexNoLight");
            printf("Shader noTexNoLight choosen for [%s]\n", names[i]);
        }
        else
        {
            (*material)[i].shader = ShaderLibrary_Get("fullset");
            printf("Shader fullset choosen for [%s]\n", names[i]);
        }

        (*material)[i].ambient = ambient[i];
        (*material)[i].diffuse = diffuse[i];
        (*material)[i].specular = specular[i];
        (*material)[i].exponent = exponent[i];
    }

    *nbFinal = nb;

    fclose(file);

    puts("Ok");
    printf("\t%d Materials loaded, ", nb);
    printf("time used: %.3f seconds\n", ((float)clock() - start) / CLOCKS_PER_SEC);

    return true;
}