Texure coloring issue

Started by
-1 comments, last by Goober King 16 years, 4 months ago
So I thought I would try and make a little graphics application I've thought about for some time now. To do it I decided to use the TAO framework so I could use OpenGl with c# and .net. I've used OpenGl basics before so I know my way around the basic setup code and such. Now in the past I wrote or "wrote" my own file loader for texturing but that won't work here and given the type of application I'm making I decided it was a far better plan to use the Bitmap class for the loading of image files. That way I could let people select a much wider range of formats and saves me a heck of a lot of trouble. Anyway long story short is I got it working sort of. Images load but the color is off. First you can see the basic setup here Its a windows form with an OGL window which shows your entry level multicolored triangle and a solid quad. The quad is drawn second and I have it rotating. Now where things get interesting is here Depending on a couple of things the color of both the textured quad and the triangle(drawn first) are altered. Even if I don't draw the quad at all, loading the texture causes the triangle to be rendered wrong. Its like I loose the ability to draw the color red or the color green at all. Giving me a green/blue or blue/red triangle but not the red/green/blue I should have. What puzzles me why the triangle is effected at all given that its drawn first and even more so when the quad isn't drawn at all. My first guess was that the pixel data was being stored as BGRA and BGR instead of RGB but that doesn't work or add up as the color shifts are consistent with loosing a color channel not having them sorted wrong. After that I'm not sure what to do or where the problem is so I can go hunting. All I can do now is tell smarter people how I got here. So to get the image data from the bitmap class loaded as a texture some hoop jumping had to be made. Basically it goes like this. Image is loaded from a file and checked for alpha data. A byte array copy (memory stream) of the bitmap is made to get around the lack of any direct way to access the image data and to avoid using slow get pixel color functions. Then a non-managed copy of the image data is made so I can get the pointer to the image data OpenGL needs. In this copy I jump ahead 54-bytes to skip the stored header information otherwise the texture data is sheared. If i were to jump only 53-bytes then the color shifts I see change. For example I would loose all my greens instead of all my reds. Which leads me to believe I'm doing something wrong here. I could probably use a different loading solution and bypass the issue but I would rather understand what is happening. Plus as it stands what I have now if I get it working will fit my need very well. Anyway I will post code for whatever part someone feels is needed.
------------------------------------------------------------- neglected projects Lore and The KeepersRandom artwork

This topic is closed to new replies.

Advertisement