[Open GL]Afficher plusieurs images

Résolu
goutbouyo Messages postés 429 Date d'inscription mardi 6 juillet 2004 Statut Membre Dernière intervention 12 janvier 2008 - 10 sept. 2004 à 20:31
goutbouyo Messages postés 429 Date d'inscription mardi 6 juillet 2004 Statut Membre Dernière intervention 12 janvier 2008 - 10 sept. 2004 à 22:22
Salut, c'est encore moi, désolé ...

En fait c'est que je n'arrive pas à charger plusieurs images.

J'utilise ça :

Je charge une image :

void LoadTexture()
{
AUX_RGBImageRec *texture1;
texture1 = auxDIBImageLoad("machin2.bmp");
glGenTextures (1, &texture[0]);
glBindTexture (GL_TEXTURE_2D, texture[0]);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, 3, texture1->sizeX, texture1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture1->data);
};

Ensuite je l'applique comme ça :

glTexCoord2i(0,0);glVertex3i (x1,y,z1);

Je fais comment si je veux mettre 2 images différentes à 2 endroits différents ???

J'ai essayer en remettant glTexImage2D(GL_TEXTURE_2D, 0, 3, texture2->sizeX, texture2->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture2->data); et en ayant crée une 2ème image mais ça marche pas.

8 réponses

cs_djl Messages postés 3011 Date d'inscription jeudi 26 septembre 2002 Statut Membre Dernière intervention 27 novembre 2004 7
10 sept. 2004 à 20:47
unsigned LoadTexture(const char *image)
{
AUX_RGBImageRec *texture1;
unsigned id;
texture1 = auxDIBImageLoad(image);

glGenTextures (1, &id);
glBindTexture (GL_TEXTURE_2D, id);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, 3, texture1->sizeX, texture1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture1->data);

return id;
};

// dans la partie init
unsigned texture1, texture2;

texture1 = LoadTexture("machin1.bmp");
texture2 = LoadTexture("machin2.bmp");

dans le rendu

glBinTexture( ..., texture1 );

//dessin

glBindTexture( ..., texture2 );

// dessin
3
goutbouyo Messages postés 429 Date d'inscription mardi 6 juillet 2004 Statut Membre Dernière intervention 12 janvier 2008
10 sept. 2004 à 22:11
C'est ça , avec ça ça marche :

void CreateList()
{
FILE *fmap;
fmap=fopen("map.txt","r");
fscanf(fmap,"%d",&n);

cube2=glGenLists(2);
glNewList(cube2, GL_COMPILE);

LoadTexture("machin2.bmp");

while (i!=25)
{
glBegin (GL_QUADS);
line :
fgets( ligne, sizeof ligne, fmap );
if( (strstr( ligne, "//" ) ligne)||(strstr( ligne, "\n" ) ligne) ) goto line;
else
{
sscanf(ligne,"%d%d%d",&x1,&y,&z1);
glTexCoord2i(1,0);glVertex3i (x1,y,z1);

fgets( ligne, sizeof ligne, fmap );
sscanf(ligne,"%d%d%d",&x1,&y,&z1);
glTexCoord2i(1,1);glVertex3i (x1,y,z1);

fgets( ligne, sizeof ligne, fmap );
sscanf(ligne,"%d%d%d",&x1,&y,&z1);
glTexCoord2i(0,1);glVertex3i (x1,y,z1);

fgets( ligne, sizeof ligne, fmap );
sscanf(ligne,"%d%d%d",&x1,&y,&z1);
glTexCoord2i(0,0);glVertex3i (x1,y,z1);

}

glEnd();
i+=1;
}

LoadTexture("cube.bmp");

glNewList(cube2, GL_COMPILE);
while (i!=n)
{

glBegin (GL_QUADS);
line2 :
fgets( ligne, sizeof ligne, fmap );
if( (strstr( ligne, "//" ) ligne)||(strstr( ligne, "\n" ) ligne) ) goto line2;
else
{
sscanf(ligne,"%d%d%d",&x1,&y,&z1);
glTexCoord2i(1,0);glVertex3i (x1,y,z1);

fgets( ligne, sizeof ligne, fmap );
sscanf(ligne,"%d%d%d",&x1,&y,&z1);
glTexCoord2i(1,1);glVertex3i (x1,y,z1);

fgets( ligne, sizeof ligne, fmap );
sscanf(ligne,"%d%d%d",&x1,&y,&z1);
glTexCoord2i(0,1);glVertex3i (x1,y,z1);

fgets( ligne, sizeof ligne, fmap );
sscanf(ligne,"%d%d%d",&x1,&y,&z1);
glTexCoord2i(0,0);glVertex3i (x1,y,z1);

}

glEnd();
i+=1;
}

i=0;

fclose(fmap);

glEndList();

}

Dis moi ce que t'en penses STP.
3
goutbouyo Messages postés 429 Date d'inscription mardi 6 juillet 2004 Statut Membre Dernière intervention 12 janvier 2008
10 sept. 2004 à 21:10
Ca me met des erreurs quand je met :

texture1 = LoadTexture("machin1.bmp");
texture2 = LoadTexture("machin2.bmp");

'texture1' : missing storage-class or type specifiers
'texture2' : missing storage-class or type specifiers

Donc à la place de : glBindTexture(GL_TEXTURE_2D, texture1 );

J'ai mis : LoadTexture("machin.bmp");
et plus loin : LoadTexture("machin2.bmp");

Mais le problème c'est que ça m'aafiche la même image partout !!!
0
cs_djl Messages postés 3011 Date d'inscription jeudi 26 septembre 2002 Statut Membre Dernière intervention 27 novembre 2004 7
10 sept. 2004 à 21:17
ba oui c'est glBind qui te permet de selectionner la texture a partir de l'identifiant

comment tu as declarer texture1 et texture2 ?
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
goutbouyo Messages postés 429 Date d'inscription mardi 6 juillet 2004 Statut Membre Dernière intervention 12 janvier 2008
10 sept. 2004 à 21:51
J'ai fait ça :
unsigned texture1 = LoadTexture("machin.bmp");
unsigned texture2 = LoadTexture("machin2.bmp");

et ça marche.

Par contre avec glbind ça m'affiche des surfaces blanches ...

Ja'i vu qu'on pouvait utiliser qu'une seule image par display liste, c'est ça ???
0
cs_djl Messages postés 3011 Date d'inscription jeudi 26 septembre 2002 Statut Membre Dernière intervention 27 novembre 2004 7
10 sept. 2004 à 21:54
c'est quoi le code de ta display list ?
0
cs_djl Messages postés 3011 Date d'inscription jeudi 26 septembre 2002 Statut Membre Dernière intervention 27 novembre 2004 7
10 sept. 2004 à 22:15
oui comme ca ca devrais marcher
0
goutbouyo Messages postés 429 Date d'inscription mardi 6 juillet 2004 Statut Membre Dernière intervention 12 janvier 2008
10 sept. 2004 à 22:22
Ok merci beaucoup encore une fois !!!

C'est cool l'aide qu'on peut trouver sur ce site.
@+++++++
0
Rejoignez-nous