Boonerm's picture

Texturing an object - problem

Hi,

a new week, a new problem ^^

i try to texture an object and uses these lines of code for loding the texture:

            megaTexture = sceneObjects._megaTexture;
            System.Drawing.Imaging.BitmapData megaTexture_data = megaTexture.LockBits(new Rectangle(0, 0, megaTexture.Width, megaTexture.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            megaTexture.UnlockBits(megaTexture_data);
 
            megaTextureID = GL.GenTexture();
            GL.ActiveTexture(TextureUnit.Texture2);
            GL.BindTexture(TextureTarget.Texture2D, megaTextureID);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
            GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Replace);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, megaTexture_data.Width, megaTexture_data.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, megaTexture_data.Scan0);

and then to draw it these lines:

            GL.Enable(EnableCap.Texture2D);
            GL.BindTexture(TextureTarget.Texture2D, megaTextureID);
            GL.Begin(BeginMode.Quads);
            GL.TexCoord2(0.0f, 0.0f);
            GL.Vertex3(-1.0f, 1.0f, -3.0f);
            GL.TexCoord2(0.0f, 1.0f);
            GL.Vertex3(1.0f, 1.0f, -3.0f);
            GL.TexCoord2(1.0f, 0.0f);
            GL.Vertex3(1.0f, -1.0f, -3.0f);
            GL.TexCoord2(1.0f, 1.0f);
            GL.Vertex3(-1.0f, -1.0f, -3.0f);
            GL.End();
            GL.Disable(EnableCap.Texture2D);

The problem is that the object just appears in one color all over it. it seems that the color is mixed from all colors in the picture. i've tried different textures with different sizes. but only the color all over the object changes. the texture is loaded properly than it works very well in my shader.

does anyone see my fault this time ;)

thanks for reading and help.


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Tal's picture

I think that you didn't setup the parameters correctly(because the link I'll give). I think that your problem is cause because your parameters said this: 1 pixel = 1 unit in texture cords. For being sure that this is the problem, replace the 1f in all your cordinates to 2f and if this is the problem, you will see 4 pixel from the texture instead 1.
However, this parameters may help you:
http://www.opentk.com/node/259
**edit**
Ok so I looked here and find out what is the problem.
TextureMinFilter and TextureMagFilter should be Linear and not Nearest.

Boonerm's picture

i think its not the problem of the linear param. its just for the color calculation.

i tried to set the first pixel in the upper right corner to a color that not appear in the image and the quad appears in that color too.

so the texcoord func does not work proberly. i've also set the uv_coords of the texcoord to 2f and above but the result remains the same.

i think i miss something linke setup the uv-coords the right way. but 1 pixel is not an unit nor the coords are normalized between 0 and 1.

dont have a clue what to do now...

any other ideas

--edit--
and it makes no difference how i change the texcoords. its still show the first pixel in the upper right corner all over

Tal's picture

Try to load the texture by this code(again):
http://www.opentk.com/node/259

Boonerm's picture

where is the glu-class? or which directive to use for?

Tal's picture

oops, this is for loading texture with mipmap...
So just use the manual:
http://www.opentk.com/doc/graphics/textures/loading

Boonerm's picture

this is the code i use ^^
and this code doesnt work for me

Tal's picture

Please check what is happens when you use Linear flag instead.
You might right and it won't matter, but try to give it a chance.
Also, the format in your code is bitmap, so is it the source texture format?

Boonerm's picture

so i tried different flags - nearly all available ^^

but i ve found the problem with the solution.

here it is.

at first i forgot the GL.Enable(EnableCap.Texture2D); in the onload-func.
the texture i load in the code above is for a shader. so i activate a shader unit. these texture cant be used to texture an object with the default-pipeline of opengl. dunno why.

so ive loaded the texture again without activating a textureunit and there it is. it works.

and for all who want to see whats the use for i attached a pic of the program.

thanks for help.

AttachmentSize
final.JPG195.5 KB