but this has the same result as putting any other parameter instead of 5. Isn't that the mipmap level? where 0 si the base level? What i am missing here?
P.S. I do generate mipmaps for the image and upload each mipmap with glTexImage2D. No errors occur during this setup(i check this with glGetError()).
[s]You should create the texture once with glTexImage2D, specifying the total number of mip-levels, and then use glTexSubImage2D to upload the different levels.[/s]
EDIT: Incorrect.
You should create the texture once with glTexImage2D, specifying the total number of mip-levels, and then use glTexSubImage2D to upload the different levels.
Thanks for the quick reply!
Ok, so i've done things like this:
glGenTextures(1, &texID);
glBindTexture(GL_TEXTURE_2D, texID);
int i;
for (i=0; i<image->getNumMipmaps(); i++)
{
if (i==0)
glTexImage2D(GL_TEXTURE_2D, image->getNumMipmaps(),
bytesPerPixel, width >> i,
height >> i, 0, bytesPerPixel==1 ? GL_LUMINANCE : (bytesPerPixel==3 ? GL_RGB : (bytesPerPixel==1 ? GL_LUMINANCE : GL_RGBA)),
GL_UNSIGNED_BYTE, image->getData(i));
else
glTexSubImage2D(GL_TEXTURE_2D, i, 0, 0, width >> i,
height >> i, bytesPerPixel==1 ? GL_LUMINANCE : (bytesPerPixel==3 ? GL_RGB : (bytesPerPixel==1 ? GL_LUMINANCE : GL_RGBA)),
GL_UNSIGNED_BYTE, image->getData(i));
printf("error: %d\n", glGetErrro());
}
But i receive GL_INVALID_ENUM after each iteration. Now i have cut off the code and boiled it down to just
The errors are gone(also this can't be the final version, because i need my own mipmaps for pydamidal displacement mapping). Now i stiil can't access the mipmaps in the fragment shader. Whatever i plug into texture2DLod as the level parameter i get the same result. Here's the code:
Is the texture in GLSL a sampler2D?
Also, what texture do you test with?
Try an RGBA image where you can clearly see the difference if another mip-level is used. GL_LUMINANCE is deprecated, but it should still work..
Yes, the texture is a sampler2D. I"m using a RGB texture which is in fact a grayscale image, every component of the three is equal to the same value. The output i'm expecting is a blurred/pixelated image , because i'm selecting a mipmap of 6, out out of 9 total.
Show your shader code. It works fine for me to use textureLod like that together with gluBuild2DMipmaps, as well as when using glGenerateMips after specifying mip-level 0 with glTexImage2d instead, at GL 3.3.
I tested the following minimal fragment shader:
#version 330 core
uniform sampler2D tex0;
in vec2 varTexCoord;
out vec4 outColor;
Show your shader code. It works fine for me to use textureLod like that together with gluBuild2DMipmaps, as well as when using glGenerateMips after specifying mip-level 0 with glTexImage2d instead, at GL 3.3.
I tested the following minimal fragment shader:
#version 330 core
uniform sampler2D tex0;
in vec2 varTexCoord;
out vec4 outColor;