OPENGL TEXTURE BMP [Résolu]

Signaler
Messages postés
71
Date d'inscription
samedi 21 mai 2005
Statut
Membre
Dernière intervention
21 octobre 2007
-
Messages postés
546
Date d'inscription
vendredi 13 février 2004
Statut
Membre
Dernière intervention
9 janvier 2008
-
bonjour
voici mon code compilé sur dev-cpp
c'est un cube tournant 3D affichant un bmp sur les six faces
je voudrais texturer plusieurs bmp sur les six faces une à une toutes les dix secondes par exemple
comment ?
merci d'avance pour les tuyaux

#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;
unsigned texture[1];


void LoadTexture()
{
AUX_RGBImageRec *texture1;
texture1 = auxDIBImageLoad("tamira.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);
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);
LoadTexture();

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 ();
break;
default:
return DefWindowProc (hwnd,uMsg,wParam,lParam);
break;
}
return 0;
}


int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
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", "CUBE PHOTO",
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;
}


J'ai essayer cela mais le prog est très long a s'executer et le cube ne tourne plus


WNDCLASS wc;
MSG msg;
HWND hWnd;
HDC DC;
HGLRC RC;
unsigned texture[1];


void LoadTexture1()
{
AUX_RGBImageRec *texture1;
texture1 = auxDIBImageLoad("tamira.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);
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 LoadTexture2()
{
AUX_RGBImageRec *texture2;
texture2 = auxDIBImageLoad("tamira2.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);
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, texture2->sizeX, texture2->sizeY, 0,
GL_RGB, GL_UNSIGNED_BYTE, texture2->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:


time_t heuredebut;


heuredebut=time(NULL);


time_t actuel;


while(difftime(actuel,heuredebut)<5)


{


actuel=time(NULL);


}


diapo++;


switch(diapo)


{


case 1:LoadTexture1();


break;


case 2:LoadTexture2();


break;


default:diapo=0;


}


RePaint ();


break;


default:


return DefWindowProc (hwnd,uMsg,wParam,lParam);


break;


}


return 0;

1 réponse

Messages postés
546
Date d'inscription
vendredi 13 février 2004
Statut
Membre
Dernière intervention
9 janvier 2008
1
il faut utiliser glBindTexture() pour choisir la texture courante ainsi pour tes six faces si tu veux une texture diffentes sur chacunes d'entre elles tu utilise glBindTexture() 6 fois avant de dessiner les polygones