croman102's picture

Problem with texture loading

I decided to move my project to OpenTK from TAO framework (btw, thank you for the great library). My problem is in my loading textures class. It says that the problem is in the 42nd line.

            int openGLId = Ilut.ilutGLBindTexImage();
 
            System.Diagnostics.Debug.Assert(openGLId != 0);   // line 42

---- Assert Long Message ----

at GameLoop.TextureManager.LoadTexture(String textureId, String path) in C:\Users\Korisnik\Documents\Visual Studio 2010\Projects\Idezasada\Idezasad\TextureManager.cs:line 42

Thank you!


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
daniklad's picture

The following snippet will allow you to load any .NET-compatible image as a texture (working code):

		public void LoadTexture(string filename, out int texid){
			if(string.IsNullOrEmpty(filename))
				throw new ArgumentException(filename);
 
			Bitmap bm;
			BitmapData bm_data;
 
			texid = GL.GenTexture();
			GL.BindTexture(TextureTarget.Texture2D, texid);
 
			try{
				bm = new Bitmap(filename);
				bm_data = bm.LockBits(new Rectangle(0,0,bm.Width,bm.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);	
			}catch(Exception ex){
				Console.WriteLine("ERROR: " + ex.Message);
				return;
			}
 
			GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bm_data.Width, bm_data.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, bm_data.Scan0);
			bm.UnlockBits(bm_data);
 
			GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
			GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMinFilter.Linear);
		}

Good luck on your project :)

------------------------------------------------
The best method for accelerating a computer is the one that boosts it by 9.8 m/s^2.