I know you need to create/set the Context but I'm sort of lost in doing so.
I define my thread such as:
loadTextures = new Thread(new ParameterizedThreadStart(Texture.LoadTextures));
I start the thread with the following call passing it a list of filenames of extra textures I need to load:
loadTextures.Start(texturesToLoad);
Finally my Thread execution is a single one shot thread execution:
public void LoadTexture()
{
GL.GenTextures(1, out glTexture);
GL.BindTexture(TextureTarget.Texture2D, GLTexture);
Bitmap bmp = new Bitmap(Bitmap.FromFile(filename));
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmpData.Width, bmpData.Height, 0,
OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bmpData.Scan0);
GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
bmp.UnlockBits(bmpData);
bmp.Dispose();
Loaded = true;
}
public static void LoadTextures(object list)
{
List<Texture> textures = (List<Texture>)list;
foreach (Texture texture in textures)
texture.LoadTexture();
}
I've trying setting the glControl from the main form's CurrentContext(null) and all sorts of things but I just can't figure this out.
All I'm wanting to be able to do is to load/unload the extra textures from this simple thread. What am I doing wrong?