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 :

application de texture opengl


Sujet :

OpenGL

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Juin 2005
    Messages
    6
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2005
    Messages : 6
    Par défaut application de texture opengl
    bonjour
    je suis débutant en progammation c++
    je voudrais texturer plusieurs bitmap sur le cube une à une toutes les dix
    secondes par exemple
    les images s'affichent bien sur le cube mais le cube ne tourne plus et le
    prog est très long a demarrer
    comment faire????
    voici mon code ci-dessous compilé sur dev-cpp
    merci d'avance
    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
    #include <windows.h>
    #include <gl/gl.h>
    #include <gl/glu.h>
    #include <gl/glaux.h>
    #include <time.h>
     
     
    WNDCLASS wc;
    MSG msg;
    HWND hWnd;
    HDC	DC;
    HGLRC RC;
    int Img;
    unsigned texture[1];
    char* fichier="photo1.bmp";
    char* fichier1="photo2.bmp";      
    char* fichier2="photo3.bmp";
     
    void LoadTexture(char* fichier)
        {  
        AUX_RGBImageRec *texture1;
    	texture1=auxDIBImageLoad(fichier);
    	glGenTextures (1, &texture[0]);  
    	glBindTexture (GL_TEXTURE_2D, texture[0]);
    	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, 3, texture1->sizeX, texture1->sizeY, 0,
        GL_RGB, GL_UNSIGNED_BYTE, texture1->data);
        };      
     
    void RePaint ()
    {
    	static float angle=0;
        glClear(GL_COLOR_BUFFER_BIT|  //efface le frame buffer et le Z-buffer
                GL_DEPTH_BUFFER_BIT);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();             //réinitialise la matrice
        gluLookAt(-2,0,0,0,0,0,0,1,0);
        glRotatef(angle,1,2,3);
        glRotatef(angle,3,0,1);
        angle+=0.05f;                 // vitesse de rotation                                 
    //----------------------------DESSIN--CUBE-------------------------------                               
     
        glBegin(GL_POLYGON);      
             glTexCoord2f(1.0,1.0);glVertex3f(-0.5,0.5,0.5);
             glTexCoord2f(1.0,0.0);glVertex3f(-0.5,-0.5,0.5);
             glTexCoord2f(0.0,0.0);glVertex3f(0.5,-0.5,0.5);
             glTexCoord2f(0.0,1.0);glVertex3f(0.5,0.5,0.5);
        glEnd();
     
        glBegin(GL_POLYGON);      
             glTexCoord2f(1.0,0.0);glVertex3f(0.5,0.5,0.5);
             glTexCoord2f(1.0,1.0);glVertex3f(0.5,-0.5,0.5);
             glTexCoord2f(0.0,1.0);glVertex3f(0.5,-0.5,-0.5);
             glTexCoord2f(0.0,0.0);glVertex3f(0.5,0.5,-0.5);
        glEnd();
        glBegin(GL_POLYGON);      
             glTexCoord2f(1.0,0.0);glVertex3f(0.5,0.5,-0.5);
             glTexCoord2f(1.0,1.0);glVertex3f(0.5,-0.5,-0.5);
             glTexCoord2f(0.0,1.0);glVertex3f(-0.5,-0.5,-0.5);
             glTexCoord2f(0.0,0.0);glVertex3f(-0.5,0.5,-0.5);
        glEnd();
        glBegin(GL_POLYGON);      
     
             glTexCoord2f(1.0,1.0);glVertex3f(-0.5,0.5,-0.5);
             glTexCoord2f(1.0,0.0);glVertex3f(-0.5,-0.5,-0.5);
             glTexCoord2f(0.0,0.0);glVertex3f(-0.5,-0.5,0.5);
             glTexCoord2f(0.0,1.0);glVertex3f(-0.5,0.5,0.5);
        glEnd();
        glBegin(GL_POLYGON);      
             glTexCoord2f(1.0,1.0);glVertex3f(-0.5,0.5,-0.5);
             glTexCoord2f(1.0,0.0);glVertex3f(-0.5,0.5,0.5);
             glTexCoord2f(0.0,0.0);glVertex3f(0.5,0.5,0.5);
             glTexCoord2f(0.0,1.0);glVertex3f(0.5,0.5,-0.5);
        glEnd();
        glBegin(GL_POLYGON);      
             glTexCoord2f(1.0,0.0);glVertex3f(-0.5,-0.5,-0.5);
             glTexCoord2f(1.0,1.0);glVertex3f(-0.5,-0.5,0.5);
             glTexCoord2f(0.0,1.0);glVertex3f(0.5,-0.5,0.5);
             glTexCoord2f(0.0,0.0);glVertex3f(0.5,-0.5,-0.5);
        glEnd();
    	SwapBuffers (DC);
    }
    void InitPixelFormat (HDC hDC)
    {
          PIXELFORMATDESCRIPTOR pfd =
          {
               sizeof (PIXELFORMATDESCRIPTOR),
               1,
               PFD_SUPPORT_OPENGL | PFD_TYPE_RGBA | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER,
               16,
               0, 0, 0, 0, 0, 0, 0, 0,	0, 0, 0, 0, 0,
               16,
               0, 0, 0, 0, 0, 0, 0
          };
          SetPixelFormat (hDC, ChoosePixelFormat (hDC, &pfd), &pfd);
    }
    LRESULT CALLBACK WindowProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {        
    	switch (uMsg)
    	{              
     
    	case WM_CREATE:        
            DC=GetDC (hWnd);
            InitPixelFormat (DC);
            RC = wglCreateContext (DC);
            wglMakeCurrent (DC, RC);
            glEnable (GL_DEPTH_TEST); 
            glClearColor (0,0,1,0); 
            glEnable(GL_TEXTURE_2D);
     
            break;                    	                                
    	case WM_CLOSE:
            wglMakeCurrent (NULL, NULL);
            wglDeleteContext (RC);
            ReleaseDC (hWnd,DC);
    		PostQuitMessage (0);
    		break;
        case WM_SIZE:
        	glViewport (0,0,LOWORD (lParam),HIWORD (lParam));
        	glMatrixMode (GL_PROJECTION);
        	glLoadIdentity ();
        	gluPerspective (45,(float)(LOWORD(lParam))/(float)(HIWORD(lParam)),1,100);   	
        	break;              
        case WM_PAINT:                             
        	RePaint ();
            Img++;
            switch(Img)
            {
            case 1:LoadTexture(fichier);
                 break;
            case 2:LoadTexture(fichier1);
                 break;
            case 3:LoadTexture(fichier2);
                 break;
            default:Img=0;
            }                             	
        	break;                         	
    	default:
    		return DefWindowProc (hWnd,uMsg,wParam,lParam);
    		break;
    	}
    	return 0;
    }                          
    int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int CmdShow)
    {
    	wc.style = CS_OWNDC;
    	wc.lpfnWndProc = WindowProc;
    	wc.cbClsExtra = 0;
    	wc.cbWndExtra = 0;
    	wc.hInstance = hInstance;
    	wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
    	wc.lpszMenuName = NULL;
    	wc.lpszClassName = "OGL";
     
    	RegisterClass(&wc);
     
    	hWnd = CreateWindow
    	("OGL", "Fenetre OpenGL",
    	WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE|WS_SYSMENU|WS_MINIMIZEBOX|WS_MAXIMIZEBOX,
    	0, 0, 200, 200, NULL, NULL, hInstance, NULL
    	);
     
        while (GetMessage(&msg, NULL, 0, 0)) {          
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);		
            }                                                                                       
    	return 0;
    }

    [Balises CODE rajoutées par Loulou24, merci d'y penser à l'avenir]

  2. #2
    Rédacteur
    Avatar de bafman
    Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    2 574
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Novembre 2003
    Messages : 2 574
    Par défaut
    oula... moi a ta place je chargerait toutes les textures en memoire au demarrage...
    * Il est infiniment plus simple de faire rapidement un code qui marche que de faire un code rapide qui marche
    * pour faciliter les recherches, n'oubliez pas de voter pour les réponses pertinentes
    Mes articles

  3. #3
    Membre confirmé
    Homme Profil pro
    Développeur Java
    Inscrit en
    Juin 2005
    Messages
    64
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Juin 2005
    Messages : 64
    Par défaut
    oula... moi j'utiliserais les balises code dans mon message :
    - ça conserve l'indentation (comme ça c'est plus lisible)
    - c'est plus joli (comme ça, plus de monde le lit)
    - c'est dans les règles du forum (donc c'est mieux)

Discussions similaires

  1. Application de textures OpenGL
    Par Fiquet dans le forum Contribuez
    Réponses: 0
    Dernier message: 21/12/2010, 14h58
  2. [DevIL] Aide DevIL pour chargement texture Opengl
    Par CPPTryer dans le forum DevIL
    Réponses: 1
    Dernier message: 10/02/2006, 16h47
  3. texture opengl-sdl
    Par ffomnislash dans le forum OpenGL
    Réponses: 20
    Dernier message: 21/07/2005, 12h14
  4. [ActiveX] Texturing OpenGL
    Par MaGaX dans le forum OpenGL
    Réponses: 10
    Dernier message: 17/03/2005, 18h06

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