Im making a program, that has alot of bitmaps to be displayed on the screen, and i looked into using a texture to apply to a square, but apparently, openGL only works properly with bitmaps of dimensions with powers of 2, 64, 128, 256 etc.. however i need to be able to display bitmaps of any size
i made my own thing which drew the bitmaps per-pixel to the screen using GL_POINTS and glVertex2f, but even with just a small bitmap of 200*200, the CPU usage jumps into 99% from the normal values of 0 hopping around normally to 4 and maybe 8
is there a way of doing what i need doing without doing this, since its a right drag literally
(Note, that the bitmaps im drawing are almost never the actual size when displayed on the screen, and is almost always scaled)
im using my own class and functions to load bitmaps into a Bitmap24 object containing two unsigned ints for width and height along with other things, and an array of unsigned ints storing all the colour data in the the way such that given a coordinate (x,y) on the bitmap you can get the rgb colours via
m = 3*(y*width+x)
r = data[m];
g = data[m+1];
b = data[m+2];
this is mainly because i never got any other things i found for loading and saving bitmaps to work, and because its simple to use when you need to manipulate the bitmaps which is alot of what my program is doing
nolxev
May 14th, 2006, 03:28 PM
It's the function glTexImage2D that works only with power of two images, not OpenGL, all you have to do is to use gluBuild2DMipmaps one.
delta_luca
May 14th, 2006, 03:50 PM
It's the function glTexImage2D that works only with power of two images, not OpenGL, all you have to do is to use gluBuild2DMipmaps one.
so for me, i would have format = GL_RGB, type = GL_UNSIGNED_INT and data as the pointer to my 'data' array?
theres one more thing.
the bitmaps are part of a set of tools my program has for things like converting heightmaps to tangent space normal maps etc. so the bitmaps change. would i need to recreate the mipmaps when this happens?
nolxev
May 14th, 2006, 04:23 PM
The data array is the same of "const GLvoid *pixels" within glTexImage2D.
What mean the bitmaps change? With the gluBuild2DMipmaps call OGL generates the correct mipmaps that your current OGL running application need, you have not to worry about to select/change the mipmaps, OGL does it for you, simple you have to bind the texture to your quad positioned anywhere.
delta_luca
May 15th, 2006, 03:14 AM
What mean the bitmaps change?
As in the size and pixel colours change
nolxev
May 15th, 2006, 09:10 AM
Don't worry about that, load all bitmaps type you need and call the gluBuild2DMipmaps function.
Bornish
May 15th, 2006, 10:01 AM
@nolxev: Can we see a piece of sample code which takes a buffer of pixel data of size non-power of 2 (50x50 pixels of 24 bit RGB) and displays it using textures? How about replacing a portion of an existing texture using glTexSubImage2D? What are the known limitations (for ex., regarding maximum size) of gluBuild2DMipmaps?
nolxev
May 15th, 2006, 03:58 PM
I have not code here at this moment.
You have not problems with all other OGL calls (like glTexSubImage2D), you can use it if you have genereted the texture with gluBuild2DMipmaps because with gluBuild2DMipmaps call, if the data is not power of two, a copy of data is scaled up or down to the nearest power of two, at the end the texture is always power of two, this is what the utility function does besides builds a series of prefiltered texture maps.
About the max texture size you can generate, it depend also on your hardware, you can obtain it with glGetIntegerv with GL_MAX_TEXTURE_SIZE argument.
Bornish
May 16th, 2006, 12:39 AM
I have not code here at this moment.
You have not problems with all other OGL calls (like glTexSubImage2D), you can use it if you have genereted the texture with gluBuild2DMipmaps because with gluBuild2DMipmaps call, if the data is not power of two, a copy of data is scaled up or down to the nearest power of two, at the end the texture is always power of two, this is what the utility function does besides builds a series of prefiltered texture maps.So you know for sure that gluBuild2DMipmaps does resampling, but you don't know if sub-sampling or super-sampling. Ok, thanks! My personal choice would be to never use such function since better solution is to tile my imagery.About the max texture size you can generate, it depend also on your hardware, you can obtain it with glGetIntegerv with GL_MAX_TEXTURE_SIZE argument.That hardware limitation is regarding glTexImage2D. So, there isn't any other limitation regarding gluBuild2DMipmaps? I guess the only limitation would be speed related. Giving some large textures to resample will clearly not be efficient.
Thanks for your reply. It's good to see other OpenGL users around here.
Best regards,
nolxev
May 16th, 2006, 08:50 AM
I don't know but I'm sure it's supersampling :D
Tile the imagery is of course a good idea, but I think it depends sometimes on what you're doing. A big texture require too much MB of VRAM, so you need to split it and doing some streaming. I'm reading about QuakeWars MegaTexture these days, if you're interesting here is a link:
About the max texture size, maybe you're wrong (maybe), I think you know that gluBuild2DMipmaps call glTexImage2D to generate the textures, here is what happen when you load a 128x128 image:
So the GL_MAX_TEXTURE_SIZE regarding also gluBuild2DMipmaps because at the end it uses glTexImage2D.
delta_luca
May 17th, 2006, 04:20 PM
im having trouble getting this to work
like i said
in my Bitmap24 thing, i have two unsigned ints for the width and height of the bitmap, and then an array of unsigned ints for the pixel data from top to bottom going row by row, in the format [r,g,b , r,g,b , r,g,b , r,g,b]
so each pixel is each set of 3 uints.
GLuint texture;
//then in the GLINIT function called after the window is set up
What exactly is the problem? The texture is not generated or your quad doesn't appear on the screen?
delta_luca
May 18th, 2006, 02:24 AM
What exactly is the problem? The texture is not generated or your quad doesn't appear on the screen?
well i messed around a bit, and it seems the gluBuild2DMipmaps isnt generating the textures, because if i comment it out, i get a white quad, comment it back, i get a black quad, so it seems the textures are just black for whatever reason
Bornish
May 18th, 2006, 04:06 AM
@delta_luca: The documentation reads: "The gluBuild2DMipmaps function obtains the input image and generates all mipmap images (using gluScaleImage) so the input image can be used as a mipmapped texture image. To load each of the images, call glTexImage2D."
I don't know what exaclty are you supposed to pass as "pixels" parameter in the glTexImage2D call, but "level" parameter should be 0 for the original, but scaled image. I don't think you need gluBuild2DMipmaps, since you don't want overview (aka pyramids) for your image. The only requirement you have is to rescale your image to a power of two size, for which you can simply call gluScaleImage. You will need a second buffer to store the scaled pixels, though.
There's another possible problem with your code:so each pixel is each set of 3 uintsTry changing the 6th parameter:gluBuild2DMipmaps(GL_TEXTURE_2D,3,texmap.width,texmap.height,GL_RGB,GL_UNSIGNED_INT,texmap.data);Are you sure you have a pixel of 3 UINTS, 'cause Bitmap24 sounds to me like pixels of 3 bytes (3 * 8 = 24, while sizeof(int)=32)? Doesn't hurt to try GL_UNSIGNED_BYTE or GL_BYTE, too!
If still drawing black, use "imdebug.dll" which is a very useful tool which helps you send images from your application's memory as well as from texture memory to an external viewer. Is very simple to use: simply link to "imdebug.lib" and include "imdebug.h". Unfortunatelly I forgot from where "Image Debugger" can be downloaded, so I have attached the necessary files. To contact the author, William Baxter, try baxter@cs.unc.edu.
// after downloading the attachment, please change its extension to zip (zip uploading limit is 250 kb, while frm isn't)
Regards,
delta_luca
May 18th, 2006, 10:46 AM
There's another possible problem with your code:Try changing the 6th parameter:gluBuild2DMipmaps(GL_TEXTURE_2D,3,texmap.width,texmap.height,GL_RGB,GL_UNSIGNED_INT,texmap.data);Are you sure you have a pixel of 3 UINTS, 'cause Bitmap24 sounds to me like pixels of 3 bytes (3 * 8 = 24, while sizeof(int)=32)?
ive already realised and tried changing to GL_UNSIGNED_INT to no avail, and the reason its called Bitmap24, is because it loads and writes 24bit bitmaps specifically, each byte in the 24bit bitmap is written to an array of unsigned integers, although i can see that i could be wasting alot of space in doing that, rather than just storing as unsigned bytes
delta_luca
May 20th, 2006, 10:51 AM
i cant get either gluScaleImage or gluBuild2DMipMaps to work with my bitmaps, could it be that the data format these functions are expecting is different from the way i have the pixel data stored?
i.e. mine stores row by row from left to right in packets of 3 numbers
and maybe these functions are expecting it to be collumn by collumn from top to bottom or something?
Bornish
May 20th, 2006, 11:12 AM
i cant get either gluScaleImage or gluBuild2DMipMaps to work with my bitmaps, could it be that the data format these functions are expecting is different from the way i have the pixel data stored?
i.e. mine stores row by row from left to right in packets of 3 numbers
and maybe these functions are expecting it to be collumn by collumn from top to bottom or something?No, has nothing to do with order of pixels. In fact, haven't seen anything that expects columns by columns. But, can be a problem with the size of the pixel data. Try the ImDebug tool that I've attached in my previous post. It can really help debugging by narrowing the exact instruction that fails to achieve the expected result. BTW, are you checking any possible returned error codes? Can you try your OpenGL code with different kind of data? Have a small sample code scaling a normal 24 bit RGB image (3 bpp color image) and then load it as a texture. If that doesn't fail, then your problem is related with the type of buffer passed to glu... functions. I had once a similar problem when loading a grayscale image (8 bpp) and I had to pass GL_RED to glTexImage2D in order to load it as a texture. What other pixel transfer & pixel store settings you've made in your implementation? If you tried everything, doesn't hurt to test your implementation of a different brand of graphics card, since drivers may also have bugs or unsupported features (even when the documentation from the provider says are supporting all OpenGL 1.1 or 2.0 specs). For some graphics cards, their manufacturers may have available for download different versions of drivers, compiled by other companies (3dLabs has driver versions compiled by 3rd parties like MS...) because each "big" client may have different requirements. One of those versions may work for you. You'll have to deliver the driver instalation along with your software. One good such example is the OpenGL Overlay support which isn't properly supported in more than 9 out of 10 cards on the market. If you're still not able to find a solution, send me a small compileable sample code reproducing the problem and I'll try to figure out what is going on.
Regards,
delta_luca
May 20th, 2006, 12:07 PM
well i tried the imgdebug thing, but i could never get it to display my images properly, so if you would please.
It should work with any sized image, what im trying to do, is to resize the image to the nearest powers of 2, and then create the texture with glTexImage2D on the resized image, and display it, but it doesnt work and i cant figure out why
i dont know how to use the openGl error stuff either so i cant try and narrow it down with that
(note the libararies still have to be linked too, which would be gdi32, opengl32, and glu32 libararies)
delta_luca
May 23rd, 2006, 11:28 AM
no one :(
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.