Advertisement

fast textures

Started by July 16, 2005 01:34 PM
7 comments, last by lc_overlord 19 years, 1 month ago
I am making an OpenGl game with lots of textures in it. To make it really fast I have put all the textures into one bitmap and used texture coordinates to select each texture. Is this the best way to do it or is there a simpler way?
Texture changes are pretty costly so your approach is good, providing you aren't using enormously dimensioned textures. What size is the bitmap?

Other things that you may want to know:

  • Older cards only support 256 x 256 maximum for textures. The cards, if I remember correctly, are very old however, Rage Pro and the like.
  • With certain kinds of filtering on, you may find fine detailed objects can get fuzzy around the edges due to the sampling algorithm OpenGL uses.

If you're wanting more speed-ups then look into display lists, vertex buffers and Vertex Buffer Objects (VBOs) for your geometry.

Hope that helped :)
--
Cheers,
Darren Clark
Advertisement
Basically I am making a little town center which must have a different shop sign logo on each of about 100 shops so anything that will speed up the teture changes would be a good thing.

At first I used lots of dib bitmaps. e.g.
dib[3] = new TDib("texture3.bmp");



and then to change each texture I use:
glNewList(1,GL_COMPILE); glTexImage2D(GL_TEXTURE_2D, 0, 3,dib[3]->Width(), dib[3]->Height(), 0, GL_RGB,  GL_UNSIGNED_BYTE, dib[3]->GetBits());//draw quad glEndList();


Ok, bear with with me as I'm pretty tired here :)

As far as I understand, glTexImage2D loads a block of pixels into video memory, and you're doing that every frame, although with using a list I'm not 100% sure. The way I've always done textures is like so:
// generate id for texture and bind itGLuint my_id;glGenTextures(1, &my_id);glBindTexture(GL_TEXTURE_2D, my_id);// set environment modes and filters (omitted for clarity)// no mipmaps needed so use glTexImage2DglTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, _width, _height, 0, GL_RGB, GL_UNSIGNED_BYTE, pDataArray);// free up data array as it's on video ram nowdelete[] pDataArray;


You only do this once per game. Afterwards, when you want to use the texture, just call glBindTexture(GL_TEXTURE_2D, my_id) and that will bind the texture for use. When you want to free the memory on the video ram, use glDeleteTextures(1, &my_id).

Hope that helps ;)
--
Cheers,
Darren Clark
Unfortunately I've only got OpenGL 1.0 on my computer so it doesn't have glBindTexture....
Bugger. Sorry I can't help you then mate :(
--
Cheers,
Darren Clark
Advertisement
Quote: Original post by paulbird
Unfortunately I've only got OpenGL 1.0 on my computer so it doesn't have glBindTexture....


Exactly what computer/graphics card/os are you using that only have ogl 1.0?
I'm just using what came with Borland 4.5 C++ which only included OpenGL 1.0 libraries and help documents. I tried once to install OpenGL 1.2 but it kept saying "uresolved external glBindTexture".

Would OpenGL 1.2 really speed things up that much? Or do you still need to put all the textures into one bitmap?
Well glBindTexture is one if the more important parts of openGL.
Do make shure that you can use openGL 1.2 or higher, if it doesn't compile with Borland 4.5 C++ then get 5.0 or higher, it's simple.

But putting textures in the same texturemap is still a good thing if you have a high amount of small textures.

This topic is closed to new replies.

Advertisement