Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Offline CARUFO  
#1 Posted : Tuesday, August 30, 2011 10:17:54 PM(UTC)
CARUFO

Joined: 8/21/2011(UTC)
Posts: 37

Was thanked: 1 time(s) in 1 post(s)
If you want load a texture without the ContentSytem you must:
Add:
Code:
using dr = System.Drawing;

And:
Code:
public  Material2D(string path , string filename)
            	: base(LoadTexture(path + filename) , 
			Shader.Create(ShaderFeatureFlags.Basic | ShaderFeatureFlags.UI2D))
        {
        
        }
      
        private static  Texture LoadTexture(string file)
			
        {
            var  Source =  new dr.Bitmap(file); // Load the Bitmap
            Color[] col = new Color[(Source.Width) * (Source.Height)]; // Colors
          dr.Rectangle rect = new dr.Rectangle(0, 0, Source.Width, Source.Height);
           dr.Imaging.BitmapData bmpData = Source.LockBits(rect,dr.Imaging.ImageLockMode.ReadWrite,Source.PixelFormat);
            // Get the address of the first line.
           System.IntPtr ptr = bmpData.Scan0;
            // Declare an array to hold the bytes of the bitmap.
            int bytes  = System.Math.Abs(bmpData.Stride) * Source.Height;
         byte[] rgbValues = new byte[bytes];

            // Copy the RGB values into the array.
            System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);
  
            //Create Colors 
            for (int counter = 2; counter < rgbValues.Length; counter += 3)
            {
                col[counter / 3] = Color.FromRGB( rgbValues [ counter], rgbValues [ counter - 1],   rgbValues [ counter -2]);
              
            }
            // Unlock the bits.
            Source.UnlockBits(bmpData);
            // Create a Texture
            return Texture.Create(Texture.ConvertColorToRgb(col), new Delta.Utilities.Datatypes.Size(Source.Width,Source.Height) ,Utilities.Graphics.BlendMode.Opaque ,  true);
        }

into Material2D.cs.
How it works:
Code:
 Material2D background = new Material2D("C:/Users/*/Samples/Breakout/bin/Debug/Content/Breakout/","SpaceBackground.png");


Its not the best Code, but it works.

Edited by user Tuesday, August 30, 2011 10:50:44 PM(UTC)  | Reason: Not specified

Wanna join the discussion?! Login to your forum accountregister a new account. Or Connect via Facebook Twitter Google

Offline Benjamin  
#2 Posted : Wednesday, August 31, 2011 7:22:03 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Yes, the key point here is the Texture.Create RGB overload, for another example see MaterialTests.CreateTextureDynamically. You just use new Bitmap(pngFile) and then pass the rgb data to a texture (and then pass that to a material for rendering).

A bit easier than your method is to use the BitmapHelper functionality (all this code is stolen from the OpenTKTexture class).

Code:

			Size totalImageSize;
			bool totalImageHasAlpha;
			byte[] data = BitmapHelper.GetRGBAImageData(filename,
				out totalImageSize, out totalImageHasAlpha);
			Material2D dynamicMaterial = new Material2D(Texture.Create(
				data, totalImageSize, BlendMode.Opaque, false));


Or you could just use the ContentManager tool in v0.8.7, which makes your life much easier ^^

Edited by user Wednesday, August 31, 2011 7:25:26 PM(UTC)  | Reason: Not specified

Offline Cr3dos  
#3 Posted : Thursday, September 1, 2011 10:04:47 PM(UTC)
Cr3dos

Joined: 8/22/2011(UTC)
Posts: 61
Location: Switzerland

Was thanked: 4 time(s) in 4 post(s)
Carufo thank you for showing us how to do this.
Benjamin will you implement this feature into the engine?

Because I think the ContentSystem on a server has some disadvantages like the user need internet-connection and have to download the textures.
Offline zato_1one  
#4 Posted : Friday, September 2, 2011 5:41:27 AM(UTC)
zato_1one

Joined: 8/21/2011(UTC)
Posts: 61

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Originally Posted by: Dominik Go to Quoted Post
Carufo thank you for showing us how to do this.
Benjamin will you implement this feature into the engine?

Because I think the ContentSystem on a server has some disadvantages like the user need internet-connection and have to download the textures.

This is my concern too. From http://deltaengine.net/Wiki.Projects.ashx , I'd like to know when we can use our own server/PC to work with content. One of my friend is an over-paranoid person. He probably won't be able to sleep if he knows that our content is copied to your server. Wink

Edited by user Friday, September 2, 2011 5:50:05 AM(UTC)  | Reason: Not specified

Offline Benjamin  
#5 Posted : Saturday, September 3, 2011 12:07:06 PM(UTC)
Benjamin

Medals: Admin

Joined: 8/20/2011(UTC)
Posts: 1,421
Location: Hannover

Thanks: 18 times
Was thanked: 97 time(s) in 92 post(s)
Well, you don't have to use the content system. You can either wait until we provide the local content server (then all your content is hosted locally) or you can roll your own stuff, but we won't provide an alternative in the near future (maybe later in v0.9 we might support PC only local content, but currently the focus is supporting mobile platforms and there local content makes zero sense in our system). We obviously want people to use our services and once you do a little more advanced stuff than our tutorials or sample games, you will really need the content system to get your stuff even running with decent performance on any device.
Rss Feed  Atom Feed
Users browsing this topic
OceanSpiders 2.0
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF.NET | YAF.NET © 2003-2023, Yet Another Forum.NET
This page was generated in 0.065 seconds.