Axelill's picture

TexParameter problem

Hello, it's me again.

Now I have another problem. I want to import a texture and set some parameter of the texture.

So, to set the parameter of the texture you need to use for example in opengl (c language)

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

so should become something like that in c#

GL.TexParameter(GL.Enums.TextureTarget.TEXTURE_2D, GL.Enums.TextureParameterName.TEXTURE_MAG_FILTER, GL.Enums.All.LINEAR);

But there is no functions with an enum as last parameter(one with float and one with an integer).

I think there is just something I do not understand. Maybe a cast would be enough.

Does someone know what is wrong and why (some explanations bout the meaning of the last parameter would be really appreciated)

Thanks.

edit: is there a way to load images with openTk or do we need to use the c# bitmap or tao.devil?


Comments

Comment viewing options

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

Yeah, a cast is necessary:

GL.TexParameter(GL.Enums.TextureTarget.TEXTURE_2D, GL.Enums.TextureParameterName.TEXTURE_MAG_FILTER, (int)GL.Enums.All.LINEAR);

The last parameter has to be an 'int', not an 'enum', because it can take values from many different enums - you have to find the correct enum and cast it (GL.Enums.All is the easiest solution). The same thing occurs in some other functions too, but TexParameter is the most prominent case. The specs were defined with C in mind, where you don't have such problems (all GL_* enums are defined as 'const int').

edit: is there a way to load images with openTk or do we need to use the c# bitmap or tao.devil?
I don't know of any image loaders suitable for C#/OpenGL (other than Tao.DevIL and System.Drawing), however it isn't very hard to build one on top of System.Drawing/OpenTK to abstract away the details. The only problem with this approach is that Bitmap doesn't automatically support DDS compressed textures, but almost everything else will be handled automatically.

Axelill's picture

Ok, I did the cast and use Tao.devil now. It works (in x86 at least)

I do not know if devil is x64 capable. if yes, anyone has an idea where I can find the x64 version already built for windows ? (lazy : i do not want to compile)

What type of file can System.drawing load ? (jpeg, bmp, .tga) ? I can ot find internet this piece of informations.

Axel.

the Fiddler.'s picture

System.Drawing.Bitmap supports jpeg, png, bmp, gif and tiff formats. While not as comprehensive as DevIL, they should be enough for most uses.

Inertia has written a texture manager class over Tao.DevIL which seems very useful.

Inertia's picture

Unless you want the exercise to write your own Texture loader, you can take a look at http://www.taoframework.com/node/438
It should be fairly easy to port to use OpenTK commands, if you don't like Tao.OpenGL. It was designed primarily for the use with OpenGL 2D Textures and can load compressed .dds files, including MipMaps. Basically it can load all file formats which DevIL supports (neither Compression nor Mipmaps for those tho).

Thanks for the hint, 64-Bit support is something I haven't really considered.

Edit: Thanks for the flowers :P I've considered porting the Manager to OpenTK aswell, but wanted some feedback/corrections first before doing so. It was kinda funny posting the Manager at the Tao forums and then instantly find a post here in the forum, where people ask about texture loading (kinda proves my point in the other post) :-)

Axelill's picture

ok. I do not really need .dds but i really need .tga at least so SYstem.drawing is no good.

I will take a look at inertia texture loader. The 64 bits problem does not come from your texture loader nor Tao.devil.

It just the devil.dll ilut.dll ilu.dll from the devil library that you can download on the website is a 32 bits version.

or at least I think the problem comes from this. So the only think is to compile devil on a 64 bits windows to get the right .dll.

Axel.

the Fiddler.'s picture

I have this problem as well, lack of 64-bit libraries makes testing the Tao Framework painful on 64-bit platforms. I'll suggest adding the 64-bit dependencies along the 32-bit ones in Tao.

Axelill's picture

How can we do that ? Is tao.Library need to be modified ?

the Fiddler.'s picture

I meant suggest to the Tao developers :) No, there's no need to change Tao.DevIL, just need to compile DevIL and the rest of the libraries in 64-bit mode.

samat's picture

Hello!
I am trying to translate
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB);, but I can't write
GL.TexParameter(OpenTK.Graphics.OpenGL.TextureTarget.Texture2D, OpenTK.Graphics.OpenGL.All.TextureCompareModeArb, OpenTK.Graphics.OpenGL.All.CompareRToTextureArb);
because OpenGL.TexParameter accepts only OpenGL.TextureParameterName, but there is no TextureCompareModeArb in it.
Is that right?

the Fiddler's picture

You need to add a cast like this:

using OpenTK.Graphics.OpenGL;
 
GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)(int)All.TextureCompareModeArb, (int)All.CompareRToTextureArb);

In general, core enums, like TextureParameterName, don't contain non-core tokens, like TextureCompareModeArb. New tokens are only added once (if) an extension is promoted to core in some future OpenGL version. Yes there are exceptions to this rule, but in the long run this is the only way to keep things manageable (there are 300+ OpenGL extensions with thousands of new tokens).