Jump to content
  • Advertisement
Sign in to follow this  
Riddle

Texture loading problem. C# + Tao.Sdl_Image

This topic is 5046 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 )
	return;
   
   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 );

   Gl.glTexParameteri( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR );
  
  Gl.glTexParameteri( Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR );

  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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!