   gluBuild2DMipmaps
  Hi AllHave a question for all the good folks here...I am reading this article Fast Blurring...In Trick three...the author suggests scaling 40x25 upto 320x200 to achieve the blurring effect.I understand that mip maps can be generated using gluBuild2DMipmaps api.Now i assume i have to draw a fullscreen quad, but how do i force opengl to use the mipmap level i desire (in this case 40x25).I am using ortho projection to draw a quad.Thanks in advance.[Edited by - Sa77 on June 19, 2006 1:12:31 AM]
  gluBuildMipmaps should never be used (use generate_mipmaps instead)also im not 100% sure what u wantu have a 40x25 sized texture + u want to scale it to 320x200?one method is to create both textures at startup (the 320x200 one being blank)then bind the 40x25 one and set an orthogonal proj + viewport of 320x200mapping.draw the texture to that viewport and use glCopyTexSubImage2d(...) to update the result into the 320x200 texture   ;Quote:Original post by zedzeekgluBuildMipmaps should never be used (use generate_mipmaps instead)also im not 100% sure what u wantu have a 40x25 sized texture + u want to scale it to 320x200?one method is to create both textures at startup (the 320x200 one being blank)then bind the 40x25 one and set an orthogonal proj + viewport of 320x200mapping.draw the texture to that viewport and use glCopyTexSubImage2d(...) to update the result into the 320x200 textureHey Zedzeek, on the generate_mipmaps, why not use gluBuildMipmaps() if you aren't planning on doing any updates to your textures? I know if you are dynamically rendering to a texture or updating it, then it would be better to use generate_mipmaps. So is there a performance hit for using generate_mipmaps vs. gluBuildMipmaps()? I would assume so due to the textures not being updated... Thanks   ;  took me some to time to understand what generate_mipmaps meant (cuz i am new to opengl :)). I understand it means using the following code...glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE );Right?As to what i am trying to achieve is learning opengl, and trying to implement what this article Fast Blurring... is saying. And that is:1. Just draw something on screen. could be a simple trianle, quad or an image.2. copy it to a texture.3. try to blur it. I understand there are other approaches (which i want to learn one by one), but seems this is the most often talked about approach considering the constraints like low end hardware that do no support pixel shaders etc. So i thought of starting coding from there.My overall aim is to understand various techniques, there limitations and under which circumstances they can be used. So just want to try my hand on it.[Edited by - Sa77 on June 19, 2006 1:39:29 AM];  Forgot to ask the real question!Lets say we have a mipmapped texture of level n. What this really means is:1> there are n textures each power of 2 size smaller than the previous.2> each tex is "more blurred" version of the previous. And that to done by hardware.So when drawing, all these textures will be used to draw the quad based on "some distance" function (i dont know how itexactly works, hope to clear this one soon!).But i just want to use the "most blurred" texture (all though slow), its just like making Nth level the base level and using it just like a normal texture with no mipmapping!Hope it clears your doubts.   ;  I think you're on the wrong track with all this mip-map stuff...I would do this:Game is rendering scene at XXX by YYY pixels (lets say 800 by 600) and you want a blur texture with dimensions QQ by ZZ (lets say 40 by 25).1)Copy the screen to a blank texture [A] (size 800,600).2)Set an ortho matrix with top,left as 0,0 and bottom,right as 800,6003)Render a quad using the texture [A] with coords; 0,0 40,254)Copy the screen to a blank texture  (size 40,25)Now you have a texture of the screen, and a blurred texture of the screen.Now say you wanted to overlay the blurred one and the regular screen:5)Render a quad with texture [A] with coords; 0,0 800,6006)Enable alpha blending, set colour 255,255,255,1287)Render a quad with texture  with coords; 0,0 800,600-) Reset stuff so you can render the next frame...8)...Disable alpha blending...9)...Set your regular perspective matrix...;  In my anon post above, the method I'm explaining is what he means in the article when he says "It may be possible to render the scene to the back buffer, and then use API or hardware code to create the MIP-maps "auto-magically.""   ;Quote:Hey Zedzeek, on the generate_mipmaps, why not use gluBuildMipmaps()gluBuildMipmaps doesnt handle all texture typesits also ~10x slower   ;  Sounds good and thanks for explaining :)As i understand now (3) and (4) are the steps where blurring will occur automatically?And JUST a small clarification: In 4)Copy the screen to a blank texture  (size 40,25)...I copy screen rect(0,0,40,45) to same size texture, so that there is no scaling in this step.Also i had read about horizontal and vertical blurring (separable...) here Real time glow and here Low spec.... I could not follow this second article. Seems to me that what i asked earlier and this seperable stuff are related.Can someone throw more light on it?PS: This article mentions GL_TEXTURE_RECTANGLE_NV, which i assume, is an opengl extension. So do i really require it? I assume this is only needed if the textures are not power of 2.;  different question/issue with gluBuild2DMipmaps:in building a 3d app i have gone through and tried to be as systematic about my approach as possible.  so by doing this i first figured out how to load images (using the DevIL library) when the program has the names hard coded.  this worked.  so then i decided i would load the correct file names from the .3ds file and then use the same method (except instead of using the hardcoded names it now takes the names from the custom object that has the name stored in it).  this however doesn't work if gluBuild2DMipmaps is in the function.here is the working source (including the rest of the main) with the part that doesn't work commented out.int main(){  DEVILINIT();  if(!Load3dsFile("Arzion.3ds"))  {    cout << "failed to load map!" << endl;    char a;    cin >> a;    glfwTerminate();    return 1;  }    int running = GL_TRUE;  glfwInit();    if(!glfwOpenWindow(WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0, 0, 0, 32, 0, GLFW_WINDOW))  {    glfwTerminate();    return EXIT_FAILURE;  }  glfwSetWindowPos(50, 70);  glfwSetWindowTitle("GLFW Game");  initializecallbacks();  initializevisuals();//--------------------------------//// WORKING TEXTURE LOADING SOURCE ////--------------------------------//    texturefilename[0] = "grass.png";  texturefilename[1] = "spaceshiptexture.bmp";  for(int i = 0; i < 2; i++)  {    ilGenImages(1, &ImageName);    ilBindImage(ImageName);    if(ilLoadImage(texturefilename) == IL_FALSE)    { cout << "unable to open: " << texturefilename << endl;    }    else    { Texture = ilutGLBindTexImage(); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), GL_RGB8, GL_UNSIGNED_BYTE, ilGetData()); ilDeleteImages(1, &ImageName);    }  }//----------------------------------//// UNWORKING TEXTURE LOADING SOURCE ////----------------------------------////  for(int i = 0; i < testobj.nummaterials; i++)//  {// cout << "i part 1: " << i << endl;// cout << "\tLoading texture: " << testobj.materials.texture.filename << endl;// ilGenImages(1, &ImageName);// cout << "\t\tImageName: " << ImageName << endl;// ilBindImage(ImageName);// cout << "\t\t\ti: " << i << endl;  // if(ilLoadImage(const_cast<char*> (testobj.materials.texture.filename.c_str())) == IL_FALSE)// {//   cout << "unable to open: " << testobj.materials.texture.filename << endl;// }// else// {//   testobj.materials.texture.textureidnum = ilutGLBindTexImage();//   cout << "\t\t\t\ttestobj.materials.texture.textureidnum: " << testobj.materials.texture.textureidnum << endl;//   gluBuild2DMipmaps(GL_TEXTURE_2D, 3, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), GL_RGB8, GL_UNSIGNED_BYTE, ilGetData());// }// ilDeleteImages(1, &ImageName);////    cout << "\t\t\t\t\ttestobj.nummaterials part 2: " << testobj.nummaterials << endl;//    cout << "\t\t\t\t\t\ti part 2: " << i << endl;//  }    DLid = createmapDL();glfwSwapInterval(0);while(running){display();}glfwTerminate();return EXIT_SUCCESS;}you'll notice that in the unworking section i have a lot of "cout" statements.  these are for quick and dirty error checking to see where the issue is (and double check that file names are correct).when i use the "unworking" section but leave the gluBuild2DMipmaps commented out i get this as the console output:  (apparently this doesn't allow for blank space so all the '\t' formatting doesn't show up)Quote:i part 1: 0   Loading texture: ImageName: 2    i: 0unable to open:    testobj.nummaterials part 2: 6  i part 2: 0i part 1: 1   Loading texture: ImageName: 3    i: 1unable to open:    testobj.nummaterials part 2: 6  i part 2: 1i part 1: 2   Loading texture: METAL FL.TIF ImageName: 4    i: 2  testobj.materials.texture.textureidnum: 1    testobj.nummaterials part 2: 6  i part 2: 2i part 1: 3   Loading texture: BLDG_EXT.TIF ImageName: 5    i: 3  testobj.materials.texture.textureidnum: 2    testobj.nummaterials part 2: 6  i part 2: 3i part 1: 4   Loading texture: NMCWINDO.TIF ImageName: 6    i: 4  testobj.materials.texture.textureidnum: 3    testobj.nummaterials part 2: 6  i part 2: 4i part 1: 5   Loading texture: BEAVER L.TIF ImageName: 7    i: 5  testobj.materials.texture.textureidnum: 4    testobj.nummaterials part 2: 6  i part 2: 5however, when i uncomment the gluBuild2DMipmaps this is the output:Quote:i part 1: 0   Loading texture: ImageName: 2    i: 0unable to open:    testobj.nummaterials part 2: 6  i part 2: 0i part 1: 1   Loading texture: ImageName: 3    i: 1unable to open:    testobj.nummaterials part 2: 6  i part 2: 1i part 1: 2   Loading texture:then i get an error (i believe it is a bounds error because that is what the dev-c++ debugger said when i tried to run it, but i really don't know how to use the debugger ... thus my use of the output method) and the program crashes.obviously if you look at my code there is no reason why the value of "i" would change between the two cout statements, but apparently it is.  up until that point the two versions (with and without the build2dmipmap call) run the same.  oh, the reason why there is the "unable to open" statement is because two of the materials my modeler used don't have textures associated with them.i posted on the opengl.org boards looking for help when i thought it was just i was calling gluBuild2DMipmaps incorrectly, but i think it goes beyond that now.  has anyone else seen something like this or have any clue on what is causing this and how to fix it?any help will be great, thanks!   