private static void RenderMaterialTexturesAddToImageList(ImageList imageList, NUD.Material mat) { // Shaders weren't initialized. if (OpenTKSharedResources.SetupStatus != OpenTKSharedResources.SharedResourceStatus.Initialized) { return; } // Generate thumbnails for all textures in case the material's texture IDs are changed. foreach (NUT nut in Runtime.TextureContainers) { foreach (var texture in nut.glTexByHashId) { if (!(nut.glTexByHashId[texture.Key] is SFGraphics.GLObjects.Textures.Texture2D)) { continue; } Bitmap bitmap = TextureToBitmap.RenderBitmapUseExistingContext((SFGraphics.GLObjects.Textures.Texture2D)nut.glTexByHashId[texture.Key], 64, 64); imageList.Images.Add(texture.Key.ToString("X"), bitmap); // StackOverflow makes the bad exceptions go away. var dummy = imageList.Handle; bitmap.Dispose(); } } }
private void InitializeTextureListView(BFRES.MaterialData mat) { // Shaders weren't initialized. if (OpenTkSharedResources.SetupStatus != OpenTkSharedResources.SharedResourceStatus.Initialized) { return; } int curTex = 0; TextureRefListView.Items.Clear(); textureImageList.Images.Clear(); foreach (var texure in mat.textures) { TextureRefListView.Items.Add(texure.Name); } if (BFRES.IsSwitchBFRES == true) { foreach (BNTX bntx in Runtime.bntxList) { foreach (ListViewItem texure in TextureRefListView.Items) { if (bntx.glTexByName.ContainsKey(texure.Text)) { Bitmap bitmap = TextureToBitmap.RenderBitmapUseExistingContext((SFGraphics.GLObjects.Textures.Texture2D)bntx.glTexByName[texure.Text], 64, 64); textureImageList.Images.Add(texure.Text, bitmap); texure.ImageIndex = curTex++; var dummy = textureImageList.Handle; bitmap.Dispose(); } } } } else { foreach (FTEXContainer ftexC in Runtime.ftexContainerList) { foreach (ListViewItem texure in TextureRefListView.Items) { if (ftexC.glTexByName.ContainsKey(texure.Text)) { Bitmap bitmap = TextureToBitmap.RenderBitmapUseExistingContext((SFGraphics.GLObjects.Textures.Texture2D)ftexC.glTexByName[texure.Text], 64, 64); textureImageList.Images.Add(texure.Text, bitmap); texure.ImageIndex = curTex++; var dummy = textureImageList.Handle; bitmap.Dispose(); } } } } }