Turning on texture alpha crashes my program...

I’m following Nehe’s Lesson 8 - blending.
I have NVidia geForce 4 Ti4200 card. At the end of the lesson, Jeff mentiones that to turn alpha from textures on, we need to modify GL_RGB to GL_RGBA ( in all glTexImage2D calls). I did this. I’ve also loaded the glass.bmp file that comes with the project into photoshop, created alpha and saved the image as 32bit bmp file. The program compiles, but crashes as soon as it is run… any hints as to why?
Thank you,
Luke

did you try debugging? where exactly does it crash?

Do bmp files even have an alpha channel? If so, are they loadable by GLaux or whatever NeHe uses?

>Do bmp files even have an alpha channel? If so, are they loadable by GLaux or whatever NeHe uses

That was partially what I didn’t get. The author (Jeff) just states that the only thing one needs to change is the GL_RGB to GL_RGBA.

I did try to debug… I enter the main loop, step into and I get a message ‘Theres no source code available for current location…’ whatever that means.

I’ve also tried changing third parameter in glTexImage2D calls from 3 to 4 (to account for extra channel), but that didn’t work…

It seems to me that yes, bmp do have (can have) alpha channel, but they must be saved with it (eg. create extra channgel in PS and save it as 32bit BMP).

I think the problem might be in the AUX_RGBImageRec structure from glaux library… maybe it doesn’t support alpha channgels in BMP? but then again, there doesn’t seem to be anything like AUX_RGBAImageRec.

Any more clues?

Thank you,
Luke

@BigShooter:

i’m not sure about the possible-existing alpha channel of .BMP files, you better proof this issue.
but i think your bug lies in the non-existing alpha-channel in your image-data, that you supply to OpenGL; i can remember a bug that i had when applying texture/image-data to OpenGL which should be handled as RGBA-data but which contained no alpha-data.
you should be careful, by using glaux: perhaps you should check if the function(s) of glaux are supporting the alpha-channel, i’m not sure about it.
(and i would avoid using glaux, in general)

you should be careful, by using glaux: perhaps you should check if the function(s) of glaux are supporting the alpha-channel, i’m not sure about it.
(and i would avoid using glaux, in general)

DjSnow, thanks for your help.
Unfortunately, I’m just learning to load BMP files (been learning OpenGl only for about 8 days now). So I don’t know of any other way to load any other formats. On the other side, I’m using glaux to load bmp because I don’t know any other way :slight_smile: I don’t know how to write a function that will load BMP, without the use of glaux… :-(((

Another beginner question…

If you simply change the parameter for glTexImage2D() from GL_RGB to GL_RGBA then you will be getting an exception on this call because Opengl will be tring to access memory that you haven’t allocated.

If you have a bitmap that is 16x16pixels and is RGB you will have allocated 16x16x3 bytes of data. If you tell it you have RGBA then it thinks you have 16x16x4 bytes of data, and will access memory accordingly. You need to expand your data and insert the required alpha component.

rgpc, I was only following a tutorial. And that is all that was said at the end of it. That if one wanted to loead a texture with alpha channel, that was the only change required. I guess that was wrong. I’m not sure how to expand memory. I was using the glaux library with AUX_RGBImageRec and auxDIBImageLoad(Filename). I thought those would automatically account for the alpha channel and accordingly modify/expand the needed memory. From what it seems to me now, is that glaux does not support bmps with alpha channels…? At least not the way I’ve used it…

The best advice I can give you (apart from going off and learning more about C/C++ and memory handling - unless of course you are using VB) is that you ditch BMP’s altogether and concentrate on using either TIF’s or TGA.

Both of these formats support compression and Alpha.

I think NeHe has some tut’s on TGA loading. If not then it’ll be on Gametutorials. As for TIF’s I think LIBTIF is the way to go (but I don’t use them so I can’t really say).

rgpc, thanks for all the info.
I’m using C/C++, I don’t even know vb :slight_smile:
The 'problem ’ is that in the past 3 years of my CS, there were no graphics courses, so it’s not a problem of memory management, but things like how do you read a BMP file in Windows (we did Unix) and what is the BMP file header structure etc… but that will all come with time. I’ll take your advice on the formats.
Thanks again,
Luke

Originally posted by BigShooter:
I’m following Nehe’s Lesson 8 - blending.
I have NVidia geForce 4 Ti4200 card. At the end of the lesson, Jeff mentiones that to turn alpha from textures on, we need to modify GL_RGB to GL_RGBA ( in all glTexImage2D calls). I did this. I’ve also loaded the glass.bmp file that comes with the project into photoshop, created alpha and saved the image as 32bit bmp file. The program compiles, but crashes as soon as it is run… any hints as to why?
Thank you,
Luke

Read again what he said:
The alpha value that is used for transparency can be read from a texture map just like color, to do this, you will need to get alpha into the image you want to load, and then use GL_RGBA for the color format in calls to glTexImage2D().

.bmps don’t support Alpha channels. (Unless you want to make a 8-bit grey scale image, and read that into your alpha buffer…) Keep reading the tutorials, and for the most part, most of the tutorials are for beginners.

[This message has been edited by Elixer (edited 08-06-2003).]

Elixer, I’ve been doing grphics for the past 10 years. C++ programming for 3, but just learning OpenGL. One thing I know for certain, BMPs do support alpha channel. To test: open PS, open bmp image (24bit), make a selection, save selection (alpha channel will be created), click save as and photoshop will ask you if you want to save as 24bit (no alpha) or 32bit (with alpha). Maybe the older bmps didn’t. Anyway, tutorials are for beginners, I’ll take my further questions to that section. Thanks for all the help guys. I’ll also try working with TIFF of TGA in the future.
Luke

I would recommend that you write an import filter for ppm’s (ascii), which is very easy, and you learn a lot about how image data is stored internally and turned into a texture. also, you have to care about the alpha channel yourself.

I’m a bit puzzled, BigShooter.
You say you’ve been doing graphics for the past 10 years, but in the same breath you say stuff like:

The 'problem ’ is that in the past 3 years of my CS, there were no graphics courses, so it’s not a problem of memory management, but things like how do you read a BMP file in Windows (we did Unix) and what is the BMP file header structure etc… but that will all come with time

What gives? Are you a beginner or an experienced graphics programmer? 10 years would qualify you as experienced, yet you show no evidence of having a clue.

uhm… if you followed the tutorial you would’ve seen nehe added the alpha manually.

Photoshop is able to save BMPs with 4 channels, that´s true. But Photoshop is also one of the only programs able to read those BMPs again. In general it is said BMPs don´t support an alpha-channel. Use TGAs instead.

Another tip: You said you read the Red Book. That´s fine. I didn´t read it, i don´t know what exactly gets explained in that book. I would advice you to get a copy of “The OpenGL Superbible”. It´s a book for beginners and since you already read the Red Book, it will tell you a lot of things again. But then there are a lot of examples how to USE OpenGL and how to do some stuff, not OpenGL related, but important, like loading a BMP or a TGA.

“did you try debugging” - i don´t think he meant that you should hit F5 and wait that the debugger gives you the message “you did this and that, and that´s wrong, you should do it this way - press OK to automatically correct the code”.
If you really do program for 3 years now, than you should know, that debugging is mostly done by YOU, not by your compiler.

In general even a beginner can find a lot of errors by himself (and that´s a good practice, too), without posting everything in a forum.
Pointing out, that you are doing OpenGL for only 10 days, now, is an excuse if you really don´t understand an OpenGL function or behaviour, but it is no excuse for not wanting to debug properly.

Happy (and error-free) coding.
Jan.

Nah. IMO the Superbible is crap, a complete waste of money and time. I really regret buying it.

For fricking file formats, head on over to Wotsit , or just use DevIL .

I don’t have hex editor on my pc here, but do this: Save 1x1 pixel BMP with alpha & open it with hex editor. The first sizeof(BITMAPINFOHEADER)+sizeof(BITMAPFILEHEADER) bytes (18 bytes if I’m not mistaken) is just a crap to give you or your program info about type, size etc (be aware photoshop isn’t filling all the fields as it should biSize that is biWidthbiHeight3). then byte 19+ is the rgb/rgba array. If you’ll save your BMP with alpha, that should mean you’ll have 18+4 bytes, if alpha is not saved then you’ll have only 18+3 bytes. To check this make alpha white or black & check is the last value in hex matching it FF(256) for white, 00(0) for black & somthing else for between.

BTW, usually BMP==TGA, because file headers match (18==18) & then info is ordinary BGR arrays, tga’s are usually bit larger as they can have a lot of footers and authoring info.
AND, NeHe’s TGA’s loading tutorial isn’t very good, read it & then compare headers with docs from wotsit. Find the difference

[This message has been edited by M/\dm/
(edited 08-07-2003).]

Kanckered, by ‘doing graphics’ I meant no programming :slight_smile: Just the artistic side of it :slight_smile: Programming graphics - only few past weeks :slight_smile:
Cheers,
Luke

@BigShooter / @all:
>>rgpc, I was only following a tutorial.
>>And that is all that was said at the end
>>of it.
this is one of the most affirming evidences for that, that most of the beginner tutorials are written by beeing total beginners themselves (the tutorial writers)

BigShooter, if you want to have fast success without getting bored with fileformats and something like that, i recommend you only one fileformat: RAW-data - there is no header, no compression, nearly each graphic program can load it, it’s quite fast (ok yes, until your image is smaller then 16384x16384x3 g) and there is definitively no trouble in reading it; it supports 3bpp and 4bpp (and of course 5/6bpp if you write a plugin/exporter/importer) - try this out; in times of 80GB harddisks, as a standard size, the argument, that uncompressed images are wasting too much harddisk space, is no more valid.

@zeckensack:
be careful with DevIL !!! i have commented the usage of DevIL enough in other forums, the main problem is: DevIL reads most of the images - yes, really, most of them; let us say 99,8% - but the last 0,2% of images, wich are not able to be read by DevIl, you get stucked into big headaches, and you are asking yourself all the time: “is it my bug, or DevIl-dev’s bug” - i have written an email to the guys, i have send them the pictures, which are not readable - but they don’t answer, it seems that the guys are “get pissed in their arrogancy about their own s-h-i-t”, and they didn’t answer - if you don’t believe me, i can send you a piece of code + images, to proof for yourself (and yes, i’m using a current version).

[This message has been edited by DJSnow (edited 08-07-2003).]