Sign in to follow this  
nickme

opentk:how to read texture1D files

Recommended Posts

nickme    253
hi

i am trying to read a file into texture1D. i know how to read an image into texture2D. i had problem converting it to read texture1D. i just dont know how to use Bitmap..LockBits() for texture1D.

here is the code for loading texture2D:

[source lang="csharp"]
static public int LoadTexture(string filename)
{
// If a filename isn't provided, throw an error.
if (String.IsNullOrEmpty(filename))
throw new ArgumentException(filename);

// Generate an OpenGL texture handle and bind to it.
int id = GL.GenTexture();
GL.BindTexture(TextureTarget.Texture2D, id);

// Load up the bitmap image from a file on the computer.
Bitmap bmp = new Bitmap(filename);

// Lock the image's data into system memory so it can be used by OpenGL. We are forcing a
// 32-bit alpha/red/green/blue pixel format.
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

// With the image locked, we can tell OpenGL to store the bitmap's scan data into our texture buffer.
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba,
bmpData.Width, bmpData.Height, 0,
OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmpData.Scan0);

// Last, we unlock the bitmap. At this point, the Bitmap is no longer needed and can be discarded.
bmp.UnlockBits(bmpData);

// We also need to tell OpenGL how to render the texture when it is either smaller or larger than the
// original bitmap size. Here, we are using nearest as we want to see the pixels without any filtering.
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter,
(int)TextureMinFilter.Nearest);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter,
(int)TextureMinFilter.Nearest);

// Finally, we return the texture buffer handle back to the application for later use.
return id;
}
[/source]

thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this