Quick image display

I program a 2D game in which I need to copy many images of various sizes, going from 48x48 to 1024x768 pixels.

Everything works fine using glDrawPixels, but it is terribly slow (typically 30 fps on a XP2000+ and GF4, worse than UT2003…). I presume it is caused by the bandwidth limitation between the GPU and the processor memory (maybe I’m wrong, but I’ve tried to change everything - pixel format, pixel transfers are set to default, UNPACK_ALIGNEMENT that I have set to 1 since my images are 24 or 32 bits, and so on -, and it was still too slow.

So, what I would like is to be able to load in the video memory pictures of any size, like in Direct3D, but if I’m right it has to be powers of 2 in OpenGL…

I suppose there must be simple solutions to this problem, but I’ve been through many tutorials and faqs without finding an answer (for example, NeHe always uses small textures, which is not a problem) ? Does anybody have an idea ?

And sorry for my poor English…

Unless I’m confused about what you’re tring to do, perhaps glTexSubImage would help?

Raster graphics are too slow indeed. Do NOT use glDrawPixels, but use textured quads. Bind the texture you need and then render the quad. It is so simple. Oh. Dont forget to enter ortho2d mode. I guess you know that though.

>kaysoft : indeed, glDrawPixel IS too slow, and I should use textures. But I think the regular size for textures is 64, 128 or 256, and I have pictures from completely different sizes, that is the problem…

>yakusa : thanks for the link, but I don’t understand : glTexSubImage2D is for modifying a part of an existent texture, which still has to have a special size !

By the way, after looking closely, my textures don’t look right, the transparent parts kinda ‘slaver’, ask for a screenshot if this isn’t clear…
After reducing my code to the bare minimum, it looks like, with a standard Ortho2D projection :

glGenTextures(1, &texture[0]) ;
glBindTexture(GL_TEXTURE_2D, texture[0]) ;
glTexImage2D(GL_TEXTURE_2D, 0, 3, BMP[18].sizeX, BMP[18].sizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, BMP[18].imageData) ;

glBindTexture(GL_TEXTURE_2D, texture[0]);
	glTexCoord2f(0.0f, 0.0f); glVertex2i(0, 0);
	glTexCoord2f(1.0f, 0.0f); glVertex2i(BMP[18].sizeX, 0);
	glTexCoord2f(1.0f, 1.0f); glVertex2i(BMP[18].sizeX, BMP[18].sizeY);
	glTexCoord2f(0.0f, 1.0f); glVertex2i(0, BMP[18].sizeY);

See anything wrong ?

Let’s be more simple : I have for example a 600x300 pix image, what is the fastest way to display it (not using glDrawPixels I mean) ?

Make texture with size of power of two but bigger than yours, in your case 1024x512, now map only the part you want to display on quad. If you think you lost too much space pack some other, smaller images to that texture in unused space.

You’re right, I will do that, even if I don’t find it very satisfactory. Direct3D can load textures from any size, but I guess it just hides the fact that it stocks them in bigger textures…

By the way, I found the mistake in my texture loading, so don’t bother : the third argument of glTexImage2D must be 4 or GL_RGBA in rgba mode…

And thanks for your help !