Sign in to follow this  
ReKlipz

gluBuild2DMipMaps() problems...

Recommended Posts

OK, I'm currently adding texturing to Quake III maps that I have loaded... when I call gluBuild2DMipMaps with either of these 2 textures: textures/gothic_door/km_arena1columna2R.jpg textures/gothic_door/km_arena1columna2L.jpg it crashes... their dimensions are as follows: 66 x 640 for both I have ABSOLUTELY no idea as to why it crashes... IDK if its an internal file error, and my jpg loader doesnt recognize it(It should, it is libJPEG for christ sake), and the image loads in Photoshop just fine, so I'm sure its not the file. I read somewhere that glBuild2DMipMaps will automatically resize non ^2 textures to ^2 textures... is this correct? also, i believe there are other textures for other maps that are NOT ^2, and they work fine(I believe this is right, if I remember correctly...) yes, actually theres quite a bit of them, 320 x 768, 256 x 640 and more, and they all load fine If anyone has any clue as to what may be causing this problem, feel free to help! Thanks a bunch! ~ReKlipz PS, i can post the images themselves if someone wants to do testing with them, or if you have quake III, you can open the game00.pk3 file, and browse to the textures/gothic_door/km_arena1columna2R.jpg or textures/gothic_door/km_arena1columna2L.jpg and use that... thanks again!

Share this post


Link to post
Share on other sites
OK, I just found a page that talks about glTexImage2D()

I am thinking about switching to use that... and using glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE) to generate mipmaps...

the post said that:
so as long as your driver supports OGL 1.4 (all Geforce and Radeons do with latest drivers), you can use it... (http://www.gamedev.net/community/forums/topic.asp?topic_id=252132), is this true?

my question is, should I convert to use glTexImage2D, and if so, what should i pass in for the level parameter of glTexImage2D...

thanks yet again!
~ReKlipz

Share this post


Link to post
Share on other sites
Hi

check what the error is, I don`t remember right now, but glubuild2dmipmaps is supposed to return a glu error message if it fails. check what the error message contain. you can use gluErrorString to get more information.

Fredrik

Share this post


Link to post
Share on other sites
The most likely problem is that the sourcefmt and internalfmt you are setting with gluBuild2DMipmaps is not compatible with your input image. This is a shot in the dark, but you may have got one or both of them not set to GL_RGB (which would be the correct values for a jpeg image).

If that doesn't work, please post the line of code where you are calling gluBuild2dMipMaps.

Share this post


Link to post
Share on other sites
well, srcformat and internal format are both being set to GL_RGB...

And now, for some weird reason, It works just fine, and loads the images... the only thing I changed was a memory leak in the TGA loader... but that shouldnt matter at all... but yet, when I comment out the free(colorbuffer) line that was the fix... It crashes... this is strange, but there is a TGA being loaded before it...

So I guess it wasnt a problem with gluBuild2DMipMaps in itself, some memory error was the case, I did check to see that gluBuild2DMipMaps was returning 0, and if not, log the error, but it never got that far, it crashed inside of gluBuild2DMipMaps...

bool CreateGLTexture(mn_Texture *texture) {
glGenTextures(1, &texture->texID);
glBindTexture(GL_TEXTURE_2D, texture->texID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D, texture->format, texture->width, texture->height, texture->format, GL_UNSIGNED_BYTE, texture->imageData);

if(texture->imageData)
free(texture->imageData);

return true;
}


thanks again for all your help!

answers to why the leak would cause the crash would be appreciated also(im fairly new to c++, this engine is my first endeavour with the language, but I have hade soem experience with DirectX 8 in VB, and that just wasnt cuttin it, lol)
~ReKlipz

Share this post


Link to post
Share on other sites
Quote:
... answers to why the leak would cause the crash would be appreciated also(im fairly new to c++, this engine is my first endeavour with the language, but I have had some experience with DirectX 8 in VB, and that just wasn't cuttin' it, lol)
~ReKlipz

bump

Share this post


Link to post
Share on other sites
Quote:
I read somewhere that glBuild2DMipMaps will automatically resize non ^2 textures to ^2 textures... is this correct?

yes but u should never use it for that in fact u should never use glubuildimages fullstop
use GL_GENERATE_MIPMAP instead much faster
if your textures are not power of 2 (and u want most users to use your program or care about higher performance)
open up the images in a paint program + either resize them to power of 2 or padd the border so its power of 2

Share this post


Link to post
Share on other sites
Couldn't I just resize them using either the libpng(if the image is a png), or libjepg(if the image is a jpg), or use OGL to do it if it is something else(TGA)...

also, if anyone knows where i can find how to properly use glTexImage2d().. in replacement of glubuildmipmaps.. great thanks goes out to you also, lol

~ReKlipz

Share this post


Link to post
Share on other sites
I suggest you keep using gluBuildMipmaps and use GL_GENERATE_MIPMAP if it's supported.

How to use glTexImage2D? It's in the GL spec.
Typically, for best performance textures should be 32 bit, BGRA format, so your call would be

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, texels)

Every card sends this directly to memory cause they support them natively.

Why don't you resize them using photoshop or irfanview or some such?

Share this post


Link to post
Share on other sites
Well, I CAN do that, but I'm writing an engine, where even though no one else would really be using it(prob wont go public), I'd like it to be realisic, and not all the textures it gets will be ^2... in fact, the textures used by Quake III are not... so I feel I should support them, and why wouldn't you, if all it takes is a simple resize function...

get what I mean?

and as for the glTexImage2D(), If I want to make a level 3 mipmapped image(original img = 0, second smallest = 1 third smallest = 2, last = 3), how do i do that? like this?:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, texels)
glTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA8, w0, h0, 0, GL_BGRA, GL_UNSIGNED_BYTE, texels0)
glTexImage2D(GL_TEXTURE_2D, 2, GL_RGBA8, w1, h1, 0, GL_BGRA, GL_UNSIGNED_BYTE, texels1)
glTexImage2D(GL_TEXTURE_2D, 3, GL_RGBA8, w2, h2, 0, GL_BGRA, GL_UNSIGNED_BYTE, texels2)

or do i somehow have all the imagedata in concession somehow and call this:
glTexImage2D(GL_TEXTURE_2D, 3, GL_RGBA8, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, texels)?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this