Load texture with Tao.DevIL VB.net

Started by
8 comments, last by papageorge 14 years, 5 months ago
Hello, I am writting about a known subject but I would appriciate if you could help me because I'm desperate with texture loading with Tao.Devil. My code is :

    Function DevILTextureLoader(ByVal texture As Integer, ByVal filename As String, ByVal m_width As Double, ByVal m_height As Double) As Integer

        If (gIsDevILInitialized = False) Then

            Il.ilInit()
            Ilu.iluInit()

            Il.ilEnable(Il.IL_ORIGIN_SET)
            Il.ilOriginFunc(Il.IL_ORIGIN_LOWER_LEFT)

            Il.ilEnable(Il.IL_TYPE_SET)
            Il.ilTypeFunc(Il.IL_UNSIGNED_BYTE)

            Il.ilEnable(Il.IL_FORMAT_SET)
            Il.ilFormatFunc(Il.IL_RGB)

            Ilut.ilutRenderer(Ilut.ILUT_WIN32)

            gIsDevILInitialized = True
        End If


        Dim ImgId As Integer = 0
        Il.ilGenImages(1, ImgId)


        Il.ilBindImage(ImgId)

        texture = Ilut.ilutGLLoadImage(filename)


        m_width = Il.ilGetInteger(Il.IL_IMAGE_WIDTH)
        m_height = Il.ilGetInteger(Il.IL_IMAGE_HEIGHT)



        Il.ilBindImage(0)
        Il.ilDeleteImage(ImgId)

        Return texture

    End Function


Thank you
Advertisement
You need to say what actually isn't working.

Why are you generating and binding your own image names, but using ilutGLLoadImage at the same time?

Try changing:
Ilut.ilutRenderer(Ilut.ILUT_WIN32)
to:
Ilut.ilutRenderer(Ilut.ILUT_OPENGL)
ok thank you :)

I changed some things but it is not correct.

 Function DevILTextureLoader(ByVal filename As String) As Integer        If (gIsDevILInitialized = False) Then            Il.ilInit()            Ilu.iluInit()            Il.ilEnable(Il.IL_ORIGIN_SET)            Il.ilOriginFunc(Il.IL_ORIGIN_LOWER_LEFT)            Il.ilEnable(Il.IL_TYPE_SET)            Il.ilTypeFunc(Il.IL_UNSIGNED_BYTE)            Il.ilEnable(Il.IL_FORMAT_SET)            Il.ilFormatFunc(Il.IL_RGB)            Ilut.ilutRenderer(Ilut.ILUT_OPENGL)            gIsDevILInitialized = True        End If       Dim texture As Integer       texture = Ilut.ilutGLLoadImage(filename)       Return texture    End Function


image = DevILTextureLoader("test.JPG")


and in the loop


        Gl.glEnable(Gl.GL_TEXTURE_2D)        Gl.glBindTexture(Gl.GL_TEXTURE_2D, image)        Gl.glBegin(Gl.GL_QUADS)        Gl.glTexCoord2d(0.0, 0.0)        Gl.glVertex2d(0.0, 0.0)        Gl.glTexCoord2d(1.0, 0.0)        Gl.glVertex2d(1.0, 0.0)        Gl.glTexCoord2d(1.0, 1.0)        Gl.glVertex2d(1.0, 1.0)        Gl.glTexCoord2d(0.0, 1.0)        Gl.glVertex2d(0.0, 1.0)        Gl.glEnd()
You still haven't said what's actually going wrong.

I noticed you don't call Ilut.ilutInit, try calling that in your initialization code.
Actually in the place of the texture I see a big black square
Well, I make a DLL version of SOIL (Simple Opengl Image Loader) library. You just need do call the DLL function and it's done.

//How to do it (C example, under windows)HMODULE module;FARPROC LoadTexture;GLuint tex;module = (HMODULE) LoadLibrary("SOIL.dll");LoadTexture = (FARPROC) GetProcAddress(module, "SOIL_LoadTexture");tex = LoadTexture("texture.png" /* or jpg, tga, etc */, GL_LINEAR, GL_CLAMP);//then if you wantglTexEnvf(...); //this is applied in current texture object.//when you're doneFreeLibrary(module);


It's size is just 68k.
You can't work with SOIL static lib becouse there's no VB version.
Feel free to try it: http://www.easy-share.com/1908389582/SOIL.dll
For regular PNG, JPG, BMP, GIF resources, I'd suggest throwing Tao.Devil away completely and going with System.Drawing instead:
Imports System.DrawingImports OpenTK.Graphics.OpenGLDim texid As Integer = GL.GenTexture()GL.BindTexture(TextureTarget.Texture2D, texid)Dim bmp As Bitmap = New Bitmap(filename)Dim data As BitmapData = bmp.LockData(New Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, , System.Drawing.Imaging.PixelFormat.Format32bppArgb)GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0)            bmp.UnlockBits(data)GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, CType(TextureMinFilter.Linear, Integer))GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, CType(TextureMagFilter.Linear, Integer))


Sorry for not posting Tao code, but this is what I had at hand. The code is trivial to convert, just replace "GL." with "Gl.gl" and make the various enumerations ALL_CAPS (e.g. Gl.GL_TEXTURE_2D).

Soil is a great library, but you'll have to write a .Net binding in order to use it, and there's absolutely no need to do this (since .Net already provides image loaders for most common formats).

[OpenTK: C# OpenGL 4.4, OpenGL ES 3.0 and OpenAL 1.1. Now with Linux/KMS support!]

Firstly Thank you all (and euxaristo Fiddler :)),

I have tried all the techniques (Currently I have a class with 8 loaders and i can post them if you want) but none of them is working :(

Does anyone have a working demo project written in vb.net that loads a texture (using any technique)?

I would be very useful to me
You are welcome. :)

When you say "not working", what exactly are you seeing?

For example, is it just a white color (instead of the texture)? This indicates one of the following:
(a) that you have forgotten to enable texturing (glEnable(GL_TEXTURE_2D))
(b) that you have not disabled mipmaps (glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR))
(c) that you are not binding the correct texture prior to rendering (glBindTexture())

It would really help if you posted the exact symptoms of the problem along with a screenshot. We have all suffered the same issues one time or another (white textures, wrong colors, textures upside-down, etc) and someone will probably manage to identify the issue as soon as you do that.

[OpenTK: C# OpenGL 4.4, OpenGL ES 3.0 and OpenAL 1.1. Now with Linux/KMS support!]

I post the project if you could please take a look :)

http://www.palamari.gr/test_texture.rar

This topic is closed to new replies.

Advertisement