Using tao.opengl in c#, to open textures

I’m working with openGL in C#, and i’m getting some problems translating my c++ openGL experience to c#.

I´m using Tao.OpenGL, and all was quite cool until i find that the texture opening and mapping doesn’t work.

There’s no “auxDIBImageLoad()”, i tried something with bitmaps, but i’m getting nervous, and i can’t seem to find any documentation that helps.

Any help?
Thanks

Use System.Drawing.Image class.

Load your image with .NET API, use the LockBits function to access the raw data image (LockBits give you BitmapData and use Scan0 to get the pointer to the raw data.)

It’s a bit some work, but it works fine (Image class loads PNG, Jpeg, BMP, GIF )

Thanks for your help.

Meanwhile i’ve made some progress using textureBitmap class, although i loose quality, because afterwords i build a mipmap:

Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, //target
3, //internal format : RGB so 3 components textureBitmap.Width, //image size
textureBitmap.Height,
Gl.GL_RGB, //fomat : RGB
Gl.GL_UNSIGNED_BYTE,
bitmapdata.Scan0);//picture represented as a byte array

I tried to build a texImage2D, but the result was blank:
// Gl.glTexImage2D(Gl.GL_TEXTURE_2D, //Target
0, //level
Gl.GL_RGB,//internalFormat
textureBitmap.Width, //Width
textureBitmap.Height, //Height
0, //border
Gl.GL_BGR, //Format
Gl.GL_BITMAP, //Type
bitmapdata.Stexelscan0);

I’ll try with Image class, but i think that my loss of quality is due to the mipMap2D.

Thank you again.

Some clarifications :

gluBuild2DMipmaps does two things :

  1. rescale a Non-Power-of-Two texture to the nearest smaller Power-Of-Two (quite ugly rescale btw)
  2. fill all mipmaps levels with rescaled version of texture (4 pixels averaged to 1)

to solve 2) :

  • use glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE ); on your texture. Most hardware support this extension.
  • or don’t use mipmaps :
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

to solve 1), either do it offline with a good image program (Gimp,Photoshop…) or take advantage of modern hardware able to use NPOT textures (not so common, so I don’t recommend it)

Are you doing the Lockbits correctly ?

In the Lockbits function, there is a parameter to set the prefered output format.

For example, if you load 8-bit image, you can pass a Lockbits with RGB 24bit and the function will convert from 8bit to RGB 24bit.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.