Thursday, January 5, 2012

C# : Change Windows Wallpaper

Hi,

I like to change everyday my desktop wallpaper, so i've made a little soft which change it by downloading some pictures on internet.

Here my C# class to apply my wallpaper ( bmp file ) :

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
using Microsoft.Win32;

namespace WallPaperChanger
{


    public class WinAPI
    {
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int SystemParametersInfo
            (int uAction, int uParam, string lpvParam, int fuWinIni);
        public const int SPI_SETDESKWALLPAPER = 20;
        public const int SPIF_SENDCHANGE = 0x2;
    }

     [Serializable]
    public class WallPaperEntry
    {
 
        public enum Style : int
        {
            Tiled, Centered, Stretched
        }
 
        public static Style ImageStyle = Style.Stretched;
  
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        static extern int SystemParametersInfo(
            int uAction, int uParam, string lpvParam, int fuWinIni);
 
        const int SPI_SETDESKWALLPAPER = 20;
        const int SPIF_UPDATEINIFILE = 0x1;
        const int SPIF_SENDWININICHANGE = 0x2;
 
 
        public static void ApplyWallpaper(String bPath)
        {    
            RegistryKey key = Registry.CurrentUser.OpenSubKey("Control Panel\\Desktop", true);
 
            switch( ImageStyle )
            {
                case Style.Stretched : 
                    key.SetValue(@"WallpaperStyle", "2") ;
                     key.SetValue(@"TileWallpaper", "0") ; 
                    break; 
                case Style.Centered : 
                    key.SetValue(@"WallpaperStyle", "1") ; 
                    key.SetValue(@"TileWallpaper", "0") ; 
                    break; 
                case Style.Tiled : 
                    key.SetValue(@"WallpaperStyle", "1") ; 
                    key.SetValue(@"TileWallpaper", "1") ; 
                    break; 
            }
             key.Close();
            WinAPI.SystemParametersInfo(WinAPI.SPI_SETDESKWALLPAPER, 1,
          bPath, WinAPI.SPIF_SENDCHANGE); 
        }
    }
}

To use this class, just select the ImageStyle from Style enum and call ApplyWallpaper method :
     WallPaperEntry.ImageStyle = Style.Stretched;
     WallPaperEntry.ApplyWallpaper("C:/mywallpaper.bmp");

That's all :)

Wednesday, January 4, 2012

XNA : Ambient 2D Light

Hi,

To apply an ambient light in your game,a very simple way without using shaders.
To do this, simply edit color when Draw each sprite.


Add a the top of your game class :

float ambient = 1f;
Color ambientColor = Color.White;

 In the Update method :

 KeyboardState c = Keyboard.GetState();
 if (c.IsKeyDown(Keys.Space))
 {
    ambient -= 0.01f;
    if (ambient <= 0)
       ambient = 1f;
 }

And finally , to apply ambient on sprites :

Color drawColor = new Color(ambientColor.R / 255f * ambient, ambientColor.G / 255f * ambient, ambientColor.B / 255f * ambient);
spriteBatch.Begin();
spriteBatch.Draw(mySprite, new Vector2(0,0), drawColor);
spriteBatch.End();

As you see, it's very easy :) With this, you could simulate for example day cycle.

XNA : Little 2D Tile Lighting test

For a new project, i test have rewrite my light engine from C++ and 3D, to XNA in 2D.
 

Here a first preview :

I will explain my technique in few times

Tuesday, January 3, 2012

XNA : How to convert in code image to texture2D

Hi,

For a project, i have to load dynamic picture and use them into my game.

To do this i have simply create this little code :

public class ImageToTexture
{
     public static Texture2D loadPictureFromFile(GraphicsDevice graph, String file)
     {
          Stream ss = new FileStream(file, FileMode.Open);
          Texture2D load = Texture2D.FromStream(graph, ss);
          return load;
     }
}

3D Cylinder Revolution Models Creator with UV Mapping

For one of my project, i have to create some models quickly.
I haven't 3DS max ,Blender or something like that and i don't have the time to learn them ...
So, i create a tool to make those models like i want !
Before this project, I did not have much idea on how a model was built.
So I learned a lot through this project.
I advanced in C + + and especially in QT.
I learned OpenGL and UVMaps!
And I did a lot a lot of math! (Rotation, Scaling  ... LOve Atan2 and Pythagor :) )
All control was made by me, dots, lines, coloration, ect ... everything , just with the usage of QPainter on a QWidget :)

My project :
To achieve cylindrical objects, simply create points of an edge of the object and apply a rotation on the central axis by 360 degree.
Personally I did not actually use 360 degrees rotation, but I have defined a number of face for the final object.
After this, i can apply a texture on my model.
For this, i use the UV Mapping technique which is use by a lot of 3D format ( like .obj or .dae , my wanted format )
This technique allows you to place precisely the desired texture on one side of the object.
I realize an unfolding of my 3D object (the first thing seen is complex, but it's finally relatively easy)
After unfolding my model, I put those unfolding faces on my texture like i want :)
To finish, i can export my new 3D Object into my desired format ( obj | dae )

Here a preview of my tool :


ClimBro : WP7 on MarketPlace

Hi all,

The number of application of the marketplace (WP7) that I find completely boring is very important, so I had to try to publishing a game too.

So ClimBro was born in a 4 hours.

It's a platform game / jump with the aim of achieving the highest score by rebound on platforms and making combos.

Here a video of my express challenge game :


Simple minecraft clone in C++

A few weeks ago I was bored on my server Minecraft, suddenly I was motivated to understand how it could be done and then make a prototype Minecraft engine.

For this, I wanted to try new things. So, I went on the C + + with the engine Ogre3D.

Here are some previews of my work :
There is 2 differents light mode , procedural and Ogre3D Lighning



New blogs

Hello every one !

For this new year, new blog !! And for this occasion, i will now publish in english :) Hello International !

So, why this new blog ?

To speak about some code that i will write, test, and publish with you.