I still have problems generating a mipmap.
Here is what I currently have:
//?? glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
GLint dim = (int)(sqrt(vfgUtility::NextPowerOfTwo(particles->GetParticlesCount())));
//?? gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, 128, 128, GL_RGB, GL_UNSIGNED_BYTE, BUFFER_OFFSET(0));
// Get back values at certain mipmap level
glGetTexImage(energyValuesTex->GetProps()->target, 1, energyValuesTex->GetProps()->format_ext, energyValuesTex->GetProps()->type,pixels);
for(int i=0; i<21; i+=3) cout << (float)(pixels[i]) << ", " << (float)(pixels[i+1]) << ", " << (float)(pixels[i+2]) << endl;
Currently I fill my texture with all the same values, so I would expect that the first level mipmap averages out to approximately the same value. I just can’t seem to get this to work. Did I forget something?
You should either use glTexImage2D in a loop or gluBuild2DMipmaps.
Try with gluBuild2DMipmaps.
With glTexImage2D you will have to downscale texture by yourself and make sure you generate proper mipmap sizes.
gluBuild2DMipmaps will do the above for you. If you use it you don’t have to use any kind of generate mipmap stuff.
By the way, you don’t have to enable texture to use TexImage nor GetTexImage, but it’s no problem if you do.
Thank your for your reply. I see the difference now.
Let me check if I’m correct:
glTexImages allows to manually fill a texture at a certain level.
gluBuild2DMipmaps automates this resizing. (It crashes for me, I’m not sure why yet)
glGenerateMipmapEXT can only be used for FBO rendered textures (?)
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE) I’m not sure about yet.
Is any of these methods hardware rendered?
gluBuild2DMipmaps will crash if the source image is not power of two in size.
What you should do is use gluScaleImage when manually creating your mipmaps with glTexImage2D.
Currently my texture is 128 square, so that should be no problem.
Actually I only need to calcultate the average of the entire texture, so that is the final mipmap.
I guess the current approach is not hardware rendered. Will this be costly to do using gluScaleImage?!
The generate mipmaps stuff is a driver level auto-generation capaility that might be hardware accelerated it generates based on level zero which could be rendered with the right extensions.
gluBuild2DMipmaps is a software utility that ultimately calls glTexImage for each level. You can also do your own calls to glTexImage.
If that software is crashing it is very probably because you have given image data that is not correctly described by your image parameters and/or is incompatible with the texture format you have bound.
You don’t say what your BUFFER_OFFSET() macro does but that whole build2dmipmaps call is hardcoded and may be incompatile with the internal and external texture format your non hardcoded teximage call.
RGB textures are not always RGB format internal and/or external and in this case size matters A LOT.
I was considering the gluScaleImage to manually do the mipmapping, not to resize to a 2^n texture.
The macro I use can be found is several OpenGL specs in the examples:
#define BUFFER_OFFSET(i) ((char *)NULL + (i))
Nothing fancy there, except that I read from a PB. Since I receive my values back through a transform feedback I need to somehow turn this into a mipmapped texture.
The parameters for my texture:
properties.unit = GL_TEXTURE5;
properties.target = GL_TEXTURE_2D;
properties.format_int = GL_RGB;
properties.format_ext = GL_RGB;
properties.type = GL_UNSIGNED_BYTE;
I just want to be able to call glTexImage for the smallest (1 texel) mipmap, but I can’t get it generated :S.
Ah, thank you so much for the clear overview!!
So what I should be using is the glGenerateMipmapEXT in combination with the correct TexParameter!
How can I verify if glGenerateMipmapEXT actually performs the mipmapping? The values I get back from glGetTexImage are just a bunch of garbage.