1

Hello tout le monde.
Après m'être mis un peu à GU (sur PSP), je me suis décidé à tester OpenGL (qui est assez similaire, d'ailleurs) sur PC.
Mais voilà je n'arrive pas à texturer mes triangles. J'ai pourtant activé GL_TEXTURE_2D et tout, mais pas moyen: la couleur des vertices est toujours utilisée à la place. Est-ce que j'aurais loupé quelque chose?

1) A l'initialisation, je mets un pixelFormat comme toujours, et je crée un contexte OpenGL.
2) Avant de commencer à dessiner, je paramètre mon environnement pour de la 2D.
3) Ensuite, je fais un truc du style:
	unsigned long testImage[32][32];
	int x, y;
	for (y=0;y<32;y++)
		for (x=0;x<32;x++)
			testImage[y][x] = (x+y)<<2;

	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glTexImage2D(GL_TEXTURE_2D, 0, 4, 32, 32, 0,
		GL_RGBA, GL_UNSIGNED_BYTE, testImage);
	glEnable(GL_TEXTURE_2D);

	glBegin(GL_QUADS); 
		glTexCoord2f(0.0, 0.0); glVertex2i(0, 0);
		glTexCoord2f(0.0, 1.0); glVertex2i(0, 32);
		glTexCoord2f(1.0, 1.0); glVertex2i(32, 32);
		glTexCoord2f(1.0, 0.0); glVertex2i(32, 0);
	glEnd(); 
//	glDrawPixels(32,32, GL_RGBA, GL_UNSIGNED_BYTE, testImage);
	glFlush();

	SwapBuffers(wglGetCurrentDC());

Note: le glDrawPixels commenté fonctionne et dessine bien mon carré (sauf qu'il a la tête à l'envers, mais ça doit être mon ortho2D qui est faux). J'ai essayé des milliers de possibilités, copié des exemples, etc. mais rien n'a fonctionné. Je pense qu'il manque quelque chose pour pouvoir utiliser directement ces textures...

Merci d'avance ^^
avatar
Highway Runners, mon jeu de racing à la Outrun qu'il est sorti le 14 décembre 2016 ! N'hésitez pas à me soutenir :)

https://itunes.apple.com/us/app/highway-runners/id964932741

2

-

3

Merci beaucoup. Malheureusement ça n'a rien changé sad J'ai toujours mon écran de fond et mon quad n'est pas texturé. Est-ce qu'il y aurait autre chose?
Voici mon code:
unsigned long testImage[32][32];
GLuint mytexture=1;

void InitTexture()		{
	int x, y;
	for (y=0;y<32;y++)
		for (x=0;x<32;x++)
			testImage[y][x] = (x+y)<<2;

	glGenTextures(1, &mytexture); 
	glBindTexture(GL_TEXTURE_2D, mytexture); 
	glTexImage2D(GL_TEXTURE_2D, 0, 4, 32, 32, 0, GL_RGBA, GL_UNSIGNED_BYTE, testImage); 

	glEnable(GL_TEXTURE_2D);
//    glShadeModel(GL_FLAT);
}

void DrawScene()		{
	mgl->StartDrawing();
	mgl->ClearScreen(0);

	mgl->GradientRect(0,0,mgl->width,mgl->height, RGB(0,0,128), RGB(0,0,128), RGB(255,255,255), RGB(255,255,255));

	glBindTexture(GL_TEXTURE_2D, mytexture); 
	glBegin(GL_QUADS); 
		glTexCoord2f(0.0, 0.0); glVertex2i(0, 0);
		glTexCoord2f(0.0, 1.0); glVertex2i(0, 32);
		glTexCoord2f(1.0, 1.0); glVertex2i(32, 32);
		glTexCoord2f(1.0, 0.0); glVertex2i(32, 0);
	glEnd(); 
//	glDrawPixels(32,32, GL_RGBA, GL_UNSIGNED_BYTE, testImage);
	glFlush();

	SwapBuffers(wglGetCurrentDC());
}
[...]
LRESULT CALLBACK WndProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
		case WM_INITDIALOG:
			//CMyGL = la classe que j'ai commencé à écrire. Pour l'instant, elle fait rien de spécial.
			mgl = new CMyGL;
			mgl->hWnd = hDlg;
			mgl->InitGfx();
			InitTexture();
			SetTimer(hDlg, 1, 20, NULL);
			return TRUE;

		case WM_TIMER:
			DrawScene();
			break;
	return FALSE;
}

Merci d'avance.
avatar
Highway Runners, mon jeu de racing à la Outrun qu'il est sorti le 14 décembre 2016 ! N'hésitez pas à me soutenir :)

https://itunes.apple.com/us/app/highway-runners/id964932741

4

-

5

Merci, mais ça ne marche toujours pas cry (et je n'ai pas tout ton code donc je peux pas compiler)
Ca doit être mon initialisation de OpenGL qui est foireuse. smile
//Interne
BOOL CMyGL :: SetupPixelFormat()
{
	static PIXELFORMATDESCRIPTOR pfd =
	{
		sizeof(PIXELFORMATDESCRIPTOR),  // size of this pfd
		1,                              // version number
		PFD_DRAW_TO_WINDOW |            // support window
		  PFD_SUPPORT_OPENGL |          // support OpenGL
		  PFD_DOUBLEBUFFER,             // double buffered
		PFD_TYPE_RGBA,                  // RGBA type
		32,                             // 32-bit color depth
		0, 0, 0, 0, 0, 0,               // color bits ignored
		0,                              // no alpha buffer
		0,                              // shift bit ignored
		0,                              // no accumulation buffer
		0, 0, 0, 0,                     // accum bits ignored
		32,                             // 32-bit z-buffer
		0,                              // no stencil buffer
		0,                              // no auxiliary buffer
		PFD_MAIN_PLANE,                 // main layer
		0,                              // reserved
		0, 0, 0                         // layer masks ignored
	};
	int pixelformat;

	if ( (pixelformat = ChoosePixelFormat(hdc, &pfd)) == 0 )
	{
		MessageBox(NULL, "ChoosePixelFormat failed", "", 0);
		return FALSE;
	}

	if (SetPixelFormat(hdc, pixelformat, &pfd) == FALSE)
	{
		MessageBox(NULL, "SetPixelFormat failed", "", 0);
		return FALSE;
	}

	return TRUE;
}

void CMyGL::InitGfx()			{
	PIXELFORMATDESCRIPTOR pfd;
	int         n;					//Index du pixelFormat

	//On va dessiner sur la fenêtre
	hdc = GetDC(hWnd);

	//Initialise le pixelFormat
	if (!SetupPixelFormat())
		return;

	n = GetPixelFormat(hdc);
	DescribePixelFormat(hdc, n, sizeof(pfd), &pfd);

	CreateRGBPalette();

	hrc = wglCreateContext(hdc);
}

void CMyGL :: StartDrawing()		{
	wglMakeCurrent(hdc, hrc);
	//En réalité il ne faut le faire qu'à chaque redimensionnement
		GetClientRect(hWnd, &oldRect);
		width = oldRect.right;
		height = oldRect.bottom;
		//Code repris
			glViewport(0, 0, oldRect.right, oldRect.bottom);
			glMatrixMode(GL_PROJECTION);
			glLoadIdentity();
			gluOrtho2D(0, oldRect.right, oldRect.bottom, 0);
			glMatrixMode(GL_MODELVIEW);
			glLoadIdentity();
			glTranslatef(0.375, 0.375, 0.0);

	//NE PAS FAIRE TOUJOURS
	// pour les dégradés
	glShadeModel(GL_SMOOTH); 
	//Alpha standard (marche bien)
	glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA);
	//Teinte (teinte si alpha=255, opaque si alpha=0)
//	glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_COLOR);
	glEnable(GL_BLEND);
}

InitGfx: au début
StartDrawing: chaque frame
avatar
Highway Runners, mon jeu de racing à la Outrun qu'il est sorti le 14 décembre 2016 ! N'hésitez pas à me soutenir :)

https://itunes.apple.com/us/app/highway-runners/id964932741

6

-

7

Bon tant pis, merci quand même pour ton aide smile
Je n'ai pas pu poster hier, mais voici mon code source (projet complet) si quelqu'un voudrait bien m'aider svp chinois
http://infernobox.dyndns.org/brunni/MyOGL.zip
Merci d'avance.
avatar
Highway Runners, mon jeu de racing à la Outrun qu'il est sorti le 14 décembre 2016 ! N'hésitez pas à me soutenir :)

https://itunes.apple.com/us/app/highway-runners/id964932741

8

C'est bon j'ai réussi en recommençant à zéro. smile
Sinon j'ai regardé un peu quelques tutoriaux (dont celui de nehe qui est vraiment super) et j'aurais encore quelques questions:
- Comment est gérée la mémoire vidéo? Est-ce possible comme sur PSP d'utiliser des textures qui sont en RAM sans avoir à les uploader en VRAM à chaque fois?
- Quand est-ce que la texture est copiée en mémoire vidéo? (après glGenTextures?)
Merci d'avance ^^
avatar
Highway Runners, mon jeu de racing à la Outrun qu'il est sorti le 14 décembre 2016 ! N'hésitez pas à me soutenir :)

https://itunes.apple.com/us/app/highway-runners/id964932741

9

OpenGL se charge de la gestion de l'emplacement des objets vidéo, ce n'est pas à toi de t'en occuper.