A Better XNA Gradient Texture2D Generator

So I accidentally deleted my blog the other week, and after restoring to the current revision found that the backup was from months ago. Brill.

So starting again, with a better gradient Texture2D generator built for use with the XNA Framework. This one does what the previous one did (still published on this blog here, actually) but to a lower level, and dumped a lot of stuff that wasn’t required last time such as rendering the texture for h*w times, when 1*h was required and now handles the alpha itself to gradient down.

public Texture2D createGradientTexture2D(GraphicsDevice g, int height, Color color)
{
Texture2D backgroundTex = new Texture2D(g, 1, height);
Color[] bgc = new Color[height];
 
Color f = color; //Foreground Color
Color b = Color.White; //Background Color
 
float ratio = height / 255;
float rc = 0;
 
for (int i = 0; i < bgc.Length; i++)
{
bgc[i] = f;
if (rc >= ratio) { f.A--; rc = 0; }
else rc += ratio;
}
 
rc = 0; //Reset the ratio count
 
for (int i = bgc.Length-1; i >= 0; i--)
{
//Explode the background and array color into its RGBA bytes
byte[] ba = { bgc[i].R, bgc[i].G, bgc[i].B, bgc[i].A };
byte[] bc = { b.R, b.G, b.B, b.A };
 
//for each of the bytes...
for (int j = 0; j < ba.Length; j++)
{
//...Bitwise AND them to slowly gradient:
ba[j] &= bc[j];
}
 
//Stick it back in the Color array:
bgc[i] = new Color(ba[0], ba[1], ba[2], ba[3]);
}
 
//And finally build the Texture2D from the data, and return it.
backgroundTex.SetData(bgc);
return backgroundTex;
}

It can currently be found being used here, and if screenshots are your thing, here’s a screenshot of this code currently being used in my video game, “Crunk”.

Screenshot from Crunk

Screenshot from Crunk

 

That’s all for now, a very merry Xmas to all that chance upon my blog, see you in 2012! :)

XNA – Creating a Gradient-Styled Texture2D

After a quick tinker with XNA, I decided to try and make Tetris.

So, to manage the Texture sizes between my Macbook’s 1280×800 screen, and my TV’s 1900×1080, I came to dynamically rendering the background’s Texture2D instead of importing PNGs (fair cop, they’d upscale, but that’s added binary size) which could then be reused for buttons, status icons, or even implemented into a factory for Game Screens.

To Google I go, how can I define a gradient at runtime?

And the result wasn’t what I needed.

So I got to messing about, created a Texture 2D using the usual ways in LoadContent(), and made this method.

Pretty standard for most programmers, so I shall skip a length explaination, the comments should cut any explaination.

[sourcecode language="csharp"]

/// <summary>
/// Creates a pretty cool gradient texture!
/// Used for a background Texture!
/// </summary>
/// <param name="width">The width of the current viewport</param>
/// <param name="height">The height of the current viewport</param>
/// A Texture2D with a gradient applied.
private Texture2D CreateBG(int width, int height)
{
backgroundTex = new Texture2D(graphics.GraphicsDevice, width, height);
Color[] bgc = new Color[height * width];
int texColour = 0;          // Defines the colour of the gradient.
int gradientThickness = 2;  // Defines how "diluted" the gradient gets. I’ve found 2 works great, and 16 is a very fine gradient.

for (int i = 0; i < bgc.Length; i++)
{
texColour = (i / (screenHeight * gradientThickness));
bgc[i] = new Color(texColour, texColour, texColour, 0);
}
backgroundTex.SetData(bgc);
return backgroundTex;
}
[/sourcecode]

Here’s a screenshot of the result!

See any improvements? Please do post in the comments, always looking for cool efficiencies! :D

 

EDIT: I blitted each pixel into the array “screenheight” of times. A whole “screenheight -1″ times more than required!

Source updated!

melodyMe v1.7 Xmas Update – Lyrics & Portable Playlists!

 

Lyrics - featuring Foo Fighters

Lyrics - featuring Foo Fighters

 

 

This update brings a Lyrics feature to melodyMe, as well as an Import/Export Playlist feature for you to send friends and family your playlists, without dragging your 15GB iTunes Library with your to their house!

The Lyrics feature will present a window with the current playing song’s lyrics in, if they are found. As far as I am aware, this is a digital media player first, and I am sure you’re going to use it as much as I have! :)

The Import/Export feature, found in the Playlist DJ, will create a copy of your playlist on your Desktop, USB device or networked drive so you can share it with your friends without them requiring to download multiple gigabytes of music. You can also import a playlists here, and I have included some playlists on the Codeplex project page. These are for most people; with Lady Gaga, Foo Fighters, Feeder and Guns ‘n’ Roses.

To get the updated melodyMe client, either run the program from your computer or get it from the Codeplex project hosting here:

Download: http://melodyme.codeplex.com/releases

 

Also pushed is the v1.7 source code for this project, if you feel like tinkering with the project or arguing at my shoddy programming practices. :D

Any features you want to see, leave a comment below or on the Discussions page!

melodyMe Updated to v1.6.0.0 – My Infinite Playlist

Just pushed yet another build of melodyMe onto Codeplex, this one brings Multi-Playlist Listening!
You can have as many playlists as you like, with as many tracks as you like on them playlists, which in theory is every track ever composed. Eat your heart out, iTunes. :)

Another new feature is the Playlist DJ, the ability to become the perfect DJ by mixing the tracks to compose the greatest impact, rather than the order in which you add them to the playlist. You can also clear old playlists, remove tracks that don’t work and rename tracks that have very long or inappropriate file names.

And a missing component for melodyMe has now been added, the user input to keep your playlist going has been reduced to none. Previously, you had to keep selecting a track to play it. That was too inefficient.
melodyMe will now roll through a playlist, back to back, leaving you enjoy the music than keep playing it.

I’ll leave you with some screenshots, the first being the new quasi-redesign with the new Playlist DJ and Multi-Playlist Selector being shown. The second being the Playlist DJ in action.

melodyMe v1.6.0.0 on Codeplex – Open Source Project Hosting: http://melodyme.codeplex.com/

Screenshots:

Main Window – http://oi52.tinypic.com/25f2hli.jpg

Playlist DJ - http://oi56.tinypic.com/2zxmmmx.jpg

 

Mousepatcher 2.0

Mousepatcher 2.0 Screenshot

Mousepatcher 2.0 makes it even easier to patch ISO images with correct SSv2 data.

No Fuss, No Hassle

With the autopatch function, all you have to do is drag and drop the ISO image into the program.
Then the program will find the required SSv2 files and automatically download and patch them.
You’ll no longer have to track down SSv2 files on the internet beforehand!

Intelligent Patching Controls
But if you have your own SSv2 files, Mousepatcher 2.0 is here to help manually patch.
With its safety mechanisms, you can drop the SS or DMI file in a random order and the program will decide which file it is!

The Windows binaries, and source code is all available, at your disposal over on the Codeplex for the project!

Link for Mousepatcher 2.0: http://mousepatcher.codeplex.com/

Dev Note: I don’t make any money from this, or actually any money being a student, so click the ‘Make a Donation’ button on the sidebar for any amount, if you’re loving the software!

50 pence, 50 cents or even a few pounds. I would really appreciate it!

Identity – MP3 Renamer

Often, ripping CDs into iTunes or Windows Media Player means your songs are stored on your PC as “Track 01″ etc.

Identity solves this problem by probing the ID3 tags of the tracks to get their proper name, and then saves the list of tracks in a folder under a human-understandable name.

No longer will your music have to stand with a common music ripping problem, give your MP3 tunes their Identity back!

The installation files, a brief instruction guide and the source code to Identity is included in the RAR file below. Use WinRAR or 7Zip to extract the files.

Now fully working with multiple fixes and different Save File options!

Identity MP3 – Binaries – http://melodyme.codeplex.com/releases/52168/download/149696

Identity MP3 – Source – http://melodyme.codeplex.com/releases/52168/download/149697

melodyMe v1.5 – Twitter Support is A-Go!

Just published melodyMe over on Codeplex, this build brings in a few bugfixes and a feature i have wanted for some time now.

Twitter is a cool social media tool, it lets you say anything you want, as long as it’s less than 140 characters. melodyMe users will now have the ability to say, or tweet, their favourite tracks or something they may have picked up and want to share with their followers.

I hope to be trying to win around people who have previously used services like Spotify or Grooveshark, to name a few, with features that they may be overlooking or are asking faithful customers to pay for.

I would love to hear some feedback about this new build, either on my blog or on the Codeplex site. Either one will get read, so don’t think I will forget about it.

In other news, I’m doing some work with Liam Logue, so expect some great things, especially if you follow the Xbox 360 JTAG/SMC hack.This guy was the original inspiration for melodyMe, and I’ve finally credited him on the About Form of the above application!

melodyMe v1.5 @ Microsoft’s Codeplex.

musicMe Beta Release – v1.0.1.0

With great pleasure, I am happy to announce the first public beta of musicMe!

musicMe is a piece of software that grabs songs from servers across the internet, based on what you enter in the search box, and returns them in a nice list for your easy listening.

It is a lightweight solution, with the ability to be put on a USB flash drive to use at work, school or at a friend’s computer where the situation means you can’t pick up your entire iTunes library and put it on the flash drive. musicMe jumps in to help with a 500-kilobyte install.

Even at home, musicMe is at your complete disposal. If you find that your favourite artist has just released a track, and you can’t wait for the radio to play it, musicMe will do it’s best to find the track for you and any others if you are looking for the album.

So I leave with you, the Codeplex link for your disposal. There could be bugs, and problems, but they’re known (hopefully) and shall be fixed in later releases.
Link for musicMe: http://musicme.codeplex.com/

MousePatcher Source Code Released!

CodePlex Logo

Mousepatcher burrows a new home!

I’ve had a lot of fun with this project, and seen that many people in many countries and languages have enjoyed it.

Now it’s time for you to take the reins.

The source code has been uploaded to Microsoft’s CodePlex service, as well as a conversion to a ClickOnce application to help me update the application without having to post innumerable updates on the sites I post the tool to.

I’ve used a very basic Microsoft Public Licence to the software, I don’t really ‘agree’ with the GPL. This software gives you everything to do with MousePatcher 360, bar the rights to use the name as your own, and the ability to use my actual name as a trademark.

This does not mean the end of the line for this software, I will forever (I mean like until i’m 100) update this software as long as the customer demands it. Drop me a line at my Email -found on the About… Page- and Iwill update the software. Well, you can do now! :)

Beyond that, get to it, and enjoy it!

CodePlex Link: http://mousepatcher360.codeplex.com

SavePatch – Open Source Gamesave Patcher

Another project, abandoned due to lack of testing.

Features:

  • Creates a patch file with all the needed data to hex edit any gamesave. No previous Hexadecimal knowledge needed!
  • A description is bundled within the patch to tell the user how and what the patch does.
  • Simple two part loading process, open patch, open gamesave. Done!

Included in Zip Archive:

  • All source code for the project. Mostly commented, if I can remember correctly.
  • A, hopefully working, build of the project found in /SavePatch/bin/Debug.

Hopefully you good lot can sort this out, and get it into a proper working application out of this! :)


Download link:

http://www.multiupload.com/TLYBNPSN0N