A laide eclairage et texturing opengl !!Problemes!!

zerailkiller Messages postés 19 Date d'inscription lundi 14 mars 2005 Statut Membre Dernière intervention 30 avril 2009 - 31 août 2005 à 02:17
cs_keil Messages postés 52 Date d'inscription jeudi 22 mai 2003 Statut Membre Dernière intervention 25 octobre 2005 - 31 août 2005 à 12:00
Bonjour a tous, voila je suis en train de developper un petit doom like (je suis debutant sous opengl) .Jai fais un cube map et lorsque j applique ma texture sur le sol, plus moyen d avoir d éclairage,jai vraiment besoin d aide MERCI d avance voici mon code

7 réponses

zerailkiller Messages postés 19 Date d'inscription lundi 14 mars 2005 Statut Membre Dernière intervention 30 avril 2009
31 août 2005 à 02:19
#include <gl/glut.h>
#include "loadppm.c"


char texFileName[] = "sol.ppm";
PPMImage *image;


GLfloat minX=0.0,maxX=1.0;



void Reshape (int w, int h)
{
glMatrixMode( GL_PROJECTION ); //on veut définir la projection
glLoadIdentity();
glFrustum( -1., 1., -1., 1., 1.5, 300);
gluLookAt(0,0,10,0,0,0,0,1,1);
glMatrixMode( GL_MODELVIEW ); //retour modélisation - visualisation
glViewport( 0, 0, 640 , 480 );
}



void InitGL()
{
image = LoadPPM(texFileName);



glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);


/* glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 1, 3, image->sizeX, image->sizeY,
0, GL_RGB, GL_UNSIGNED_BYTE, image->data);
*/
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image->sizeX, image->sizeY,GL_RGB, GL_UNSIGNED_BYTE, image->data);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glEnable(GL_TEXTURE_2D);
//glEnable(GL_FOG);
GLfloat color[4] = {0.1,0.01,0.01,0.01};
GLfloat lightpos[4] = { 20,20,20,0};
GLfloat amb[4] = {0,0,0,1};
GLfloat dif[4] = {1,1,1,1};
GLfloat spec[4] = {1,1,1,1};


GLfloat matamb[4] = {0,0,0,1};
GLfloat matdif[4] = {1,1,1,1};
GLfloat matspec[4] = {1,1,1,1};
GLfloat emiss[4] = {0.3,0.1,0.1,1};


glFogf(GL_FOG_START,200);
glFogfv(GL_FOG_COLOR,color);
glFogf(GL_FOG_END,600);
glFogf (GL_FOG_DENSITY, .03);
glHint (GL_FOG_HINT, GL_DONT_CARE);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0,GL_POSITION,lightpos);
glLightfv(GL_LIGHT0,GL_AMBIENT,amb);
glLightfv(GL_LIGHT0,GL_DIFFUSE,dif);
glLightfv(GL_LIGHT0,GL_SPECULAR,spec);


glMaterialfv(GL_FRONT,GL_AMBIENT,matamb);
glMaterialfv(GL_FRONT,GL_DIFFUSE,matdif);
glMaterialfv(GL_FRONT,GL_SPECULAR,matspec);
glMaterialfv(GL_FRONT,GL_EMISSION,emiss);
glMaterialf(GL_FRONT,GL_SHININESS,100);
glShadeModel(GL_SMOOTH);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
}
0
zerailkiller Messages postés 19 Date d'inscription lundi 14 mars 2005 Statut Membre Dernière intervention 30 avril 2009
31 août 2005 à 02:20
void Draw()
{


glClearColor(0,0.3,0.9,0);


glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //Efface le framebuffer et le depthbuffer



glLoadIdentity();
glColor3f(0.0,0.5,0.5);//arme
railgun();

if (tir>0)
{
glPushMatrix();


glBegin(GL_LINES);
glColor3f(1,0.0,0.1);
glVertex3i(8,-3,0);
glVertex3i(1,-3,-3000);
glEnd();
glBegin(GL_LINES);
glColor3f(1,0.1,0.1);
glVertex3i(9,-3,0);
glVertex3i(2,-3,-3000);
glEnd();
glBegin(GL_LINES);
glColor3f(1,0.1,0.1);
glVertex3i(8,-4,0);
glVertex3i(1,-4,-3000);
glEnd();
glBegin(GL_LINES);
glColor3f(1,0.1,0.1);
glVertex3i(9,-4,0);
glVertex3i(1,-4,-3000);
glEnd();

glPopMatrix();
tir+=-0.1;
}



glRotatef(camanglex,1,0,0);
glRotatef(camangley,0,1,0);
glTranslatef(coordx,coordy-25,coordz);//camera




/* monde tout mettre
ici
*/

glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f(-100,0 , -100);
glTexCoord2f(5, 0); glVertex3f(-100,0 , 100);
glTexCoord2f(5, 5); glVertex3f(100, 0, 100);
glTexCoord2f(0, 5); glVertex3f(100, 0, -100);


glEnd();

glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f(-100,50 , -100);
glTexCoord2f(5, 0); glVertex3f(-100,50 , 100);
glTexCoord2f(5, 5); glVertex3f(100, 50, 100);
glTexCoord2f(0, 5); glVertex3f(100, 50, -100);


glEnd();


glPushMatrix();

glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f(-100,50 , -100);
glTexCoord2f(1, 0); glVertex3f(-100,0 , -100);
glTexCoord2f(1, 5); glVertex3f(-100, 0, 100);
glTexCoord2f(0, 5); glVertex3f(-100, 50, 100);


glEnd();
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f(100,50 , -100);
glTexCoord2f(1, 0); glVertex3f(100,0 , -100);
glTexCoord2f(1, 5); glVertex3f(-100, 0, -100);
glTexCoord2f(0, 5); glVertex3f(-100, 50, -100);


glEnd();
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f(100,50 , 100);
glTexCoord2f(5, 0); glVertex3f(-100, 50, 100);
glTexCoord2f(5, 1); glVertex3f(-100, 0, 100);
glTexCoord2f(0, 1); glVertex3f(100,0 , 100);


glEnd();
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f(100,50 ,-100);
glTexCoord2f(1, 0); glVertex3f(100,0 , -100);
glTexCoord2f(1, 5); glVertex3f(100, 0, 100);
glTexCoord2f(0, 5); glVertex3f(100, 50, 100);


glEnd();
glPopMatrix();



glPopMatrix();



glPushMatrix();
glColor3f(1,1,0);
glTranslatef(10,250,-200);
glutSolidSphere(10,20,20);
glPopMatrix();
glPushMatrix();
glColor3f(0,0,0.1);
doom();
glPopMatrix();




normalise(camanglex);
normalise(camangley);
mousecam();
calculs();


glutSwapBuffers();
glutPostRedisplay(); //Uniquement pour GLUT
}



int main( int argc, char *argv[ ], char *envp[ ] )

{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(640 ,480); //Optionnel
glutInitWindowPosition(0,0);
glutCreateWindow("DOOM 9");
glutWarpPointer(320,240);
glutKeyboardFunc(trucavecdestouches);


glutPassiveMotionFunc(madafakamouse);
glutPassiveMotionFunc(madafakamouse2);
glutMouseFunc(boutonsouris);


InitGL();

glutReshapeFunc(Reshape);
glutDisplayFunc(Draw);

//glutFullScreen();

glutMainLoop();



return 0;

}
0
luhtor Messages postés 2023 Date d'inscription mardi 24 septembre 2002 Statut Membre Dernière intervention 28 juillet 2008 6
31 août 2005 à 10:35
Je crois qu'un petit glGenTextures, et glBindTexture seraient les bienvenu.



variable globale: GLuint texture_id;





glGenTextures (1, &texture_id);

glBindTexture(GL_TEXTURE_2D, texture_id);



gluBuild2DMipmaps(GL_TEXTURE_2D, 3, image->sizeX, image->sizeY,GL_RGB, GL_UNSIGNED_BYTE, image->data);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

glEnable(GL_TEXTURE_2D);
0
zerailkiller Messages postés 19 Date d'inscription lundi 14 mars 2005 Statut Membre Dernière intervention 30 avril 2009
31 août 2005 à 11:08
MErci beaucoup luhtor ,Je vais essayer. :)
0

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

Posez votre question
zerailkiller Messages postés 19 Date d'inscription lundi 14 mars 2005 Statut Membre Dernière intervention 30 avril 2009
31 août 2005 à 11:51
Par contre une derniere chose ,
coment dire a opengl quelle texture on veux mapper dans le draw() (ma fonction de dessin) lorsquon applique les coordonnées de la texture aux vertex?

merci :)
0
zerailkiller Messages postés 19 Date d'inscription lundi 14 mars 2005 Statut Membre Dernière intervention 30 avril 2009
31 août 2005 à 11:58
c est bon jai trouvé , merci eaucoup luthor de m avoir appris ces trucs, j aurais mis des heures a trouver sinon,allez tcho ++++++++++++++
0
cs_keil Messages postés 52 Date d'inscription jeudi 22 mai 2003 Statut Membre Dernière intervention 25 octobre 2005
31 août 2005 à 12:00
la fonction glBindTexture(int Type, int Texture_ID) te permet de sélectionner la texture à appliquer.

Si tu veux désactiver l'application de texture sur une surface, utilise glDisable(GL_TEXTURE_2D);

glGenLists(int nb) te renvoi un entier si nb = 1 ou sinon un tableau
d'entier qui te serviront à attribuer un ID aux textures que tu
chargeras avec ce que luthor t'as donné
0
Rejoignez-nous