IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

OpenGL Discussion :

Textures tga/affichage


Sujet :

OpenGL

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre chevronné Avatar de seeme
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    430
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 430
    Par défaut Textures tga/affichage
    Bonjour
    Je voudrais utiliser le loader de http://www.levp.de/3d/ pour charger une image tga, et ensuite l'utiliser comme texture dans opengl.

    Je suis arrivé à cela:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
     
    #include <ltga.h>
    #include "ltga.cpp"
     
    LTGA tga;
    static GLuint pixel;             
     
     
    void init(void)
    {
        glClearColor(0.0, 0.0, 0.0, 0.0);
        glShadeModel(GL_SMOOTH);
     
        glGenTextures(1, &pixel);
        glBindTexture(GL_TEXTURE_2D, pixel);
        tga.LoadFromFile("mouton2.tga");
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tga.GetImageWidth(), tga.GetImageHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, tga.GetPixels());
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     
     
     
     
        glEnable(GL_DEPTH_TEST);
    }
     
    void display(void)
    {
     
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glEnable(GL_TEXTURE_2D);
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);    
        glBindTexture(GL_TEXTURE_2D, pixel);
        glEnable(GL_TEXTURE_2D);
            glBegin(GL_QUADS);
                              glTexCoord2f(0.0, 0.0);glVertex3f(-1.0, -1.0, 0.0);
                              glTexCoord2f(0.0, 1.0);glVertex3f(1.0, -1.0, 0.0);
                              glTexCoord2f(1.0, 1.0);glVertex3f(1.0, 1.0, 0.0);
                              glTexCoord2f(1.0, 0.0);glVertex3f(-1.0, 1.0, 0.0);
            glEnd();
     
        glutSwapBuffers();
    }
     
     
    void reshape(int w, int h)
    {
         glViewport(0, 0, (GLsizei)w, (GLsizei)h);
         glMatrixMode(GL_PROJECTION);
         glLoadIdentity();
         gluPerspective(60.0, (GLfloat)w/(GLfloat)h, 0.1, 20.0);;
         glMatrixMode(GL_MODELVIEW);
         glLoadIdentity();
     
         glMatrixMode(GL_MODELVIEW);
         glLoadIdentity();
     
    }
    Mais mon carré reste désespérement blanc :'(

    Quelqun pourrait m'éclairer?
    MErci d'avance

  2. #2
    Expert confirmé

    Avatar de fearyourself
    Homme Profil pro
    Ingénieur Informaticien Senior
    Inscrit en
    Décembre 2005
    Messages
    5 121
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 45
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : Ingénieur Informaticien Senior
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2005
    Messages : 5 121
    Par défaut
    Sans la possibilité de tester ton code,
    Ceci me semble étrange c'est tes coordonnées de texture par rapport à la position des vertex...
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
            glBegin(GL_QUADS);
                              glTexCoord2f(0.0, 0.0);glVertex3f(-1.0, -1.0, 0.0);
                              glTexCoord2f(0.0, 1.0);glVertex3f(1.0, -1.0, 0.0);
                              glTexCoord2f(1.0, 1.0);glVertex3f(1.0, 1.0, 0.0);
                              glTexCoord2f(1.0, 0.0);glVertex3f(-1.0, 1.0, 0.0);
            glEnd();
    Je mettrais plutôt:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
            glBegin(GL_QUADS);
                              glTexCoord2f(0.0, 0.0);glVertex3f(-1.0, -1.0, 0.0);
                              glTexCoord2f(1.0, 0.0);glVertex3f(1.0, -1.0, 0.0);
                              glTexCoord2f(1.0, 1.0);glVertex3f(1.0, 1.0, 0.0);
                              glTexCoord2f(0.0, 1.0);glVertex3f(-1.0, 1.0, 0.0);
            glEnd();
    Mais sans pouvoir tester, je peux me tromper...
    Jc

  3. #3
    Membre chevronné Avatar de seeme
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    430
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 430
    Par défaut
    J'ai testé avec les coordonnées que tu m'as fournis, mais rien de change, merci quand même.
    :'(

    Je n'ai pas de problème à la compilation, c'est vraiment bizzar... :'( :'(

    Voilà le code complet, mais c'ets vraiment le bordel (c'est un debut de jeux d'echec, je sais c'est pas très original)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
     
    /**************************
     * Includes
     *
     **************************/
     
    #include <stdlib.h>
    #include <gl/glut.h>
    #include <math.h>
    #include <ltga.h>
    #include "ltga.cpp"
     
     
     
    #define checkImageWidth 64
    #define checkImageHeight 64
     
     
    LTGA tga;
    void chekerDraw(void);
    void drawPion (float x, float z);
    static GLubyte checkImage[checkImageHeight][checkImageWidth][4];
    static GLuint texCheck, pixel;
    float rotateCamy=0.0, rotateCamx=0, xCam=0.0, yCam=1.0, zCam=3.0, posCam=0.0, xPiece=0.0, yPiece=0.0, zPiece=0.0;
    int x;
    void keyboard(unsigned char key, int x, int y);
     
     
     
     
     
     
     
    void makeCheckImage(void)
    {
         int i, j, c;
         for (i=0; i<checkImageHeight; i++)
         {
             for(j=0; j<checkImageWidth; j++)
             {
                      c= ((((i&0x8)==0)^((j&0x8))==0))*255;
                      checkImage[i][j][0] = (GLubyte) c;
                      checkImage[i][j][1] = (GLubyte) c;
                      checkImage[i][j][2] = (GLubyte) c;
                      checkImage[i][j][3] = (GLubyte) 255;
             }
         }
    }                  
     
     
    void myTimer(int value);
     
    void init(void)
    {
        glClearColor(0.0, 0.0, 0.0, 0.0);
        glShadeModel(GL_SMOOTH);
        /*makeCheckImage();
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
        
        glGenTextures(1, &texCheck);
        glBindTexture(GL_TEXTURE_2D, texCheck);
        
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage);
        */
     
     
        //unsigned char* pixels = tga.GetPixels();
     
        glGenTextures(1, &pixel);
        glBindTexture(GL_TEXTURE_2D, pixel);
        tga.LoadFromFile("mouton2.tga");
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, tga.GetImageWidth(), tga.GetImageHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, tga.GetPixels());
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     
     
     
     
        glEnable(GL_DEPTH_TEST);
    }
     
    void display(void)
    {
     
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
        //glBindTexture(GL_TEXTURE_2D, texCheck);
     
         glMatrixMode(GL_MODELVIEW);
         glLoadIdentity();
         //gluLookAt(zCam*cos(posCam), yCam, zCam*sin(posCam), 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
         gluLookAt(0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
     
         glMatrixMode(GL_PROJECTION);
         glPushMatrix();
         glTranslatef(0.0, 0.0, 0.0);
     
     
        glBindTexture(GL_TEXTURE_2D, pixel);
        glEnable(GL_TEXTURE_2D);
            glBegin(GL_QUADS);
                              glTexCoord2f(0.0, 0.0);glVertex3f(-1.0, -1.0, 0.0);
                              glTexCoord2f(1.0, 0.0);glVertex3f(1.0, -1.0, 0.0);
                              glTexCoord2f(1.0, 1.0);glVertex3f(1.0, 1.0, 0.0);
                              glTexCoord2f(0.0, 1.0);glVertex3f(-1.0, 1.0, 0.0);
            glEnd();
     
        //chekerDraw();
     
     
        glutSwapBuffers();
    }
     
     
    void reshape(int w, int h)
    {
         glViewport(0, 0, (GLsizei)w, (GLsizei)h);
         glMatrixMode(GL_PROJECTION);
         glLoadIdentity();
         gluPerspective(60.0, (GLfloat)w/(GLfloat)h, 0.1, 20.0);;
         glMatrixMode(GL_MODELVIEW);
         glLoadIdentity();
     
         glMatrixMode(GL_MODELVIEW);
         glLoadIdentity();
     
    }  
     
     
    int main (int argc, char** argv)
    {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
        glutInitWindowSize(800, 600);
        glutInitWindowPosition(100, 100);
        glutCreateWindow("See(me) my View");
        init();
        glutDisplayFunc(display);
        glutReshapeFunc(reshape);
        glutKeyboardFunc(keyboard);
        glutTimerFunc(1000/60,myTimer,x);
        glutMainLoop();
        return 0;
    }
     
     
     
    void myTimer(int value)
    {
       glutPostRedisplay();
       glutTimerFunc(1000/60, myTimer, 1);
     
    }
     
    void keyboard(unsigned char key, int x, int y)
    {
         switch(key)
         {
                    case 'q':
                         posCam+=0.1;
                         glutPostRedisplay();
                         break;
     
                    case 'd':
                         posCam-=0.1;
                         glutPostRedisplay();
                         break;
     
                    case 'z':
                         yCam+=0.1;
                         if(yCam>2.5)yCam-=0.1;
                         glutPostRedisplay();
                         break;
     
                    case 's':
                         yCam-=0.1;
                         if (yCam<0.2)yCam+=0.1;
                         glutPostRedisplay();
                         break;
     
                    case 'a':
                         if(zCam>=0.0)zCam-=0.1;
                         glutPostRedisplay();
                         break;
     
                    case 'e':
                         if(zCam!=3.0)zCam+=0.1;
                         glutPostRedisplay();
                         break;
     
                    default:
                         break;
         }
    }
     
     
    void chekerDraw(void)
    {
     
     
        glBegin(GL_QUADS);
                              glTexCoord2f(0.0, 0.0);glVertex3f(-1.0, 0.0, -1.0);
                              glTexCoord2f(0.0, 1.0);glVertex3f(1.0, 0.0, -1.0);
                              glTexCoord2f(1.0, 1.0);glVertex3f(1.0, 0.0, 1.0);
                              glTexCoord2f(1.0, 0.0);glVertex3f(-1.0, 0.0, 1.0);
            glEnd();
     
            glDisable(GL_TEXTURE_2D);
            glColor3ub(195, 110, 30);
            glBegin(GL_QUADS);//fond
                              glVertex3f(-1.2, -0.2, -1.2);
                              glVertex3f(1.2, -0.2, -1.2);
                              glVertex3f(1.2, -0.2, 1.2);
                              glVertex3f(-1.2, -0.2, 1.2);
            glEnd();
            glBegin(GL_QUADS);
                              glVertex3f(-1.2, -0.2, -1.2);
                              glVertex3f(-1.2, 0.0, -1.2);
                              glVertex3f(-1.2, 0.0, 1.2);
                              glVertex3f(-1.2, -0.2, 1.2);
            glEnd(); 
            glBegin(GL_QUADS);
                              glVertex3f(1.2, -0.2, -1.2);
                              glVertex3f(1.2, 0.0, -1.2);
                              glVertex3f(1.2, 0.0, 1.2);
                              glVertex3f(1.2, -0.2, 1.2);
            glEnd();   
            glBegin(GL_QUADS);
                              glVertex3f(1.2, -0.2, 1.2);
                              glVertex3f(1.2, 0.0, 1.2);
                              glVertex3f(-1.2, 0.0, 1.2);
                              glVertex3f(-1.2, -0.2, 1.2);
            glEnd();
            glBegin(GL_QUADS);
                              glVertex3f(1.2, -0.2, -1.2);
                              glVertex3f(1.2, 0.0, -1.2);
                              glVertex3f(-1.2, 0.0, -1.2);
                              glVertex3f(-1.2, -0.2, -1.2);
            glEnd();
            glBegin(GL_QUADS);
                              glVertex3f(-1.2, 0.0, -1.2);
                              glVertex3f(-1.0, 0.0, -1.2);
                              glVertex3f(-1.0, 0.0, 1.2);
                              glVertex3f(-1.2, 0.0, 1.2);
            glEnd();
            glBegin(GL_QUADS);
                              glVertex3f(1.0, 0.0, -1.2);
                              glVertex3f(1.2, 0.0, -1.2);
                              glVertex3f(1.2, 0.0, 1.2);
                              glVertex3f(1.0, 0.0, 1.2);
            glEnd();
            glBegin(GL_QUADS);
                              glVertex3f(-1.0, 0.0, -1.2);
                              glVertex3f(1.0, 0.0, -1.2);
                              glVertex3f(1.0, 0.0, -1.0);
                              glVertex3f(-1.0, 0.0, -1.0);
            glEnd();
            glBegin(GL_QUADS);
                              glVertex3f(-1.0, 0.0, 1.0);
                              glVertex3f(1.0, 0.0, 1.0);
                              glVertex3f(1.0, 0.0, 1.2);
                              glVertex3f(-1.0, 0.0, 1.2);
            glEnd();
            glPopMatrix();
     
    }

Discussions similaires

  1. Loader de textures TGA
    Par pottiez dans le forum Contribuez
    Réponses: 0
    Dernier message: 03/01/2011, 15h12
  2. charger une texture TGA
    Par info_amel dans le forum OpenGL
    Réponses: 5
    Dernier message: 02/04/2008, 16h07
  3. Réponses: 9
    Dernier message: 21/06/2007, 11h06
  4. Couleur transparente sur une texture TGA
    Par alex6891 dans le forum OpenGL
    Réponses: 13
    Dernier message: 29/07/2006, 22h16
  5. Textures et affichage
    Par batosai dans le forum DirectX
    Réponses: 2
    Dernier message: 06/12/2005, 22h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo