OpenGL Glut et réaffichage de scène

Bonsoir à tous!

J’ai créé une scène 2D en OpenGL avec Glut.
Cette scène 2D comporte une texture de fond que j’ai réalisée au moyen d’un carré sur lequel j’ai appliqué une texture.

Lorsque je fais glutPostRedisplay(); tout la scène est rechargée, y compris la texture de fond, ce qui n’est pas très utile.
Aussi j’aimerai savoir si il y a moyen de faire en sorte que cette texture de fond (et le carré qui la supporte) ne soient pas rechargés lorsque je fais glutPostRedisplay();

En fait j’aimerai faire ça car mon portable est peu puissant, et lorsque je recharge la scène, réafficher la texture de fond prend 1s environ (si j’enlève la texture c’est quasi instantané), donc je me disai que si on évitai de réafficher la texture et qu’on la laissait en permanence il n’y aurait pas ce problème.

Est ce possible à réaliser ? Si oui comment puis-je faire ?

Merci, bonne soirée!

Je m’y connais pas trop mais je pense que ça a un rapport avec le stencil buffer (pour selectionner la zone ne nécessitant pas de remise à jour).
Edit: désolé, j’avais pas compris la question, ça m’apprendra à aller sur cafzone dès le réveil. :stuck_out_tongue:

tu recharge la texture d’ou ? si tu la recharge direct du disque dur, forcement ca va rammer et un petit glBindTexture(GL_TEXTURE_2D, texId) resoudra ton probleme
sinon, si tu veut dire que tu réaffiche la texture a chaque fois simplement, alors c’est un probleme de fill rate et la y’a pas vraiment de solution (a part changer le viewport pour qu’il n’affiche que la ou tu a besoin d’afficher (ou alors juste changer le rectangle de scission…) donc en fait il y a des possibilitée :stuck_out_tongue:

Faut que tu charges ta texture une seule fois. C’est surtout ca qui compte. Donc tu te créé une fonction qui la charge, tu l’appelle au tout debut et voila. Pas besoin de la charger 36 fois.
Tiens un bout de code pour utiliser des JPG (tu la’s peut etre deja mais bon…) :

[code]#include <GL/glut.h>
#include <jpeglib.h>

///////////////////////////////// DECODE JPG \\\\\\\\\\\\\\\\*
void DecodeJPG(jpeg_decompress_struct* cinfo, tImageJPG *pImageData)
{
// Read in the header of the jpeg file
jpeg_read_header(cinfo, TRUE);

// Start to decompress the jpeg file with our compression info
jpeg_start_decompress(cinfo);

// Get the image dimensions and row span to read in the pixel data
pImageData->rowSpan = cinfo->image_width * cinfo->num_components;
pImageData->sizeX &nbsp; = cinfo->image_width;
pImageData->sizeY &nbsp; = cinfo->image_height;

// Allocate memory for the pixel buffer
pImageData->data = new unsigned char[pImageData->rowSpan * pImageData->sizeY];

 
// Here we use the library’s state variable cinfo.output_scanline as the
// loop counter, so that we don’t have to keep track ourselves.

// Create an array of row pointers
unsigned char** rowPtr = new unsigned char*[pImageData->sizeY];
for (int i = 0; i < pImageData->sizeY; i++)

 rowPtr[i] = &(pImageData->data[i*pImageData->rowSpan]);

// Now comes the juice of our work, here we extract all the pixel data
int rowsRead = 0;
while (cinfo->output_scanline < cinfo->output_height) 
{

 // Read in the current row of pixels and increase the rowsRead count
 rowsRead += jpeg_read_scanlines(cinfo, &rowPtr[rowsRead], cinfo->output_height - rowsRead);
}

// Delete the temporary row pointers
delete [] rowPtr;

// Finish decompressing the data
jpeg_finish_decompress(cinfo);

}

///// This loads the JPG file and returns it’s data in a tImageJPG struct
tImageJPG *LoadJPG(const char *filename)
{
struct jpeg_decompress_struct cinfo;
tImageJPG *pImageData = NULL;
FILE *pFile;

// Open a file pointer to the jpeg file and check if it was found and opened 
if((pFile = fopen(filename, "rb")) == NULL) 
{

 // Display an error message saying the file was not found, then return NULL
 MessageBox(NULL, “Unable to load JPG File!”, “Error”, MB_OK);
 return NULL;
}

// Create an error handler
jpeg_error_mgr jerr;

// Have our compression info object point to the error handler address
cinfo.err = jpeg_std_error(&jerr);

// Initialize the decompression object
jpeg_create_decompress(&cinfo);

// Specify the data source (Our file pointer)	
jpeg_stdio_src(&cinfo, pFile);

// Allocate the structure that will hold our eventual jpeg data (must free it!)
pImageData = (tImageJPG*)malloc(sizeof(tImageJPG));

// Decode the jpeg file and fill in the image data structure to pass back
DecodeJPG(&cinfo, pImageData);

// This releases all the stored memory for reading and decoding the jpeg
jpeg_destroy_decompress(&cinfo);

// Close the file pointer that opened the file
fclose(pFile);

// Return the jpeg data (remember, you must free this data after you are done)
return pImageData;

}

///// This creates a texture in OpenGL that we can use as a texture map
void CreateTexture(UINT textureArray[], LPSTR strFileName, int textureID)
{
if(!strFileName)        // Return from the function if no file name was passed in
 return;
 
tImageJPG *pImage = LoadJPG(strFileName);  // Load the image and store the data

if(pImage == NULL) &nbsp; &nbsp; &nbsp; 	&nbsp;// If we can't load the file, quit!

 exit(0);

// Generate a texture with the associative texture ID stored in the array
glGenTextures(1, &textureArray[textureID]);

// Bind the texture to the texture arrays index and init the texture
glBindTexture(GL_TEXTURE_2D, textureArray[textureID]);

// Build Mipmaps (builds different versions of the picture for distances - looks better)
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pImage->sizeX, pImage->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pImage->data);

// Lastly, we need to tell OpenGL the quality of our texture map. &nbsp;GL_LINEAR_MIPMAP_LINEAR
// is the smoothest. &nbsp;GL_LINEAR_MIPMAP_NEAREST is faster than GL_LINEAR_MIPMAP_LINEAR, 
// but looks blochy and pixilated. &nbsp;Good for slower computers though. 

 
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR_MIPMAP_LINEAR);

// Now we need to free the image data that we loaded since OpenGL stored it as a texture
if (pImage) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// If we loaded the image
{

 if (pImage->data)      // If there is texture data
 {
 free(pImage->data);    // Free the texture data, we don’t need it anymore
 }

 free(pImage);        // Free the image structure
}
}[/code]

C’est ce que je fais, je charge la texture une fois pour toutes.

Par contre, lors de la mise à jour de la scène, il doit recalculer un max pour la réafficher à l’écran, vu que si je vire la texture du carré ça marche niquel.
Mon portable est vraiement pas puissant, il en faut peu pour le faire ramer.

c’est donc un probleme de fill rate, vu que ton quad prend tout l’ecran, la carte graphique a du mal a suivre quand il s’agit de tout remplir… essaye en baissant la resolution, normalement ca devrait nettement moins ramer. si sa rame toujours que tu a un autre truc qui te ralenti