Jump to content
  • Advertisement
Sign in to follow this  

Texture loading problem. C# + Tao.Sdl_Image

This topic is 5131 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello guys! I have a little problem with my textures in C#. Im using Tao.SDL_Image to load the images. The prolbem is that the texture is messed up ingame. The texture is distorted and looks ugly. ( Im texturing a simple quad. ) Any ideas what I do wrong? Thank you!

#region LoadImage

/// <summary> Loads the texture from the file.</summary>
/// <param name="name"></param>
/// <returns></returns>
public override bool LoadImage( string name ) 
   if( resIsLoaded == true )
   System.IntPtr intPtrImage = SdlImage.IMG_Load( name );
   Sdl.SDL_Surface image = 
                   sgMisc.SurfaceFromPointer( intPtrImage );

   Gl.glGenTextures( 1, out glTextureID );
   Gl.glBindTexture( Gl.GL_TEXTURE_2D, glTextureID );


  Sdl.SDL_PixelFormat pf = 
  sgMisc.PixelFormatFromPointer( image.format );

  Gl.glPixelStorei( Gl.GL_UNPACK_ROW_LENGTH, image.pitch / pf.BitsPerPixel );
  Gl.glTexImage2D( Gl.GL_TEXTURE_2D, 0, 3, image.w, image.h, 0, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, image.pixels );

  Gl.glPixelStorei( Gl.GL_UNPACK_ROW_LENGTH, 0 );

  Sdl.SDL_FreeSurface( ref intPtrImage );
  resIsLoaded = true;


#endregion LoadImage

		/// <summary> Creates a SDL_Surface out of an IntPtr </summary>
		/// <param name="ptr"> IntPtr pointing to a surface. </param>
		/// <returns> The surface. </returns>
		public static Tao.Sdl.Sdl.SDL_Surface SurfaceFromPointer( IntPtr ptr )
			return (Tao.Sdl.Sdl.SDL_Surface)System.Runtime.InteropServices.Marshal.PtrToStructure
				     ( ptr, typeof( Tao.Sdl.Sdl.SDL_Surface ) );

/// <summary> Creates a SDL_PixelFormat out of an IntPtr </summary>
/// <param name="ptr"> IntPtr pointing to the PixelFormat surface. </param>
/// <returns> The pixelFormat. </returns>
public static Tao.Sdl.Sdl.SDL_PixelFormat PixelFormatFromPointer( IntPtr ptr )
 return (Tao.Sdl.Sdl.SDL_PixelFormat)System.Runtime.InteropServices.Marshal.PtrToStructure
				( ptr, typeof( Tao.Sdl.Sdl.SDL_PixelFormat ) );

Ive deleted the error handling code to reduce the size for you guys.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!