Double Buffer Graphics in C# + GDI (II)
This happens sometimes to me.
As a C++ programmer, when I moved to .net I was not used to have things done there for me, so I tended to do everything on my own (I found myself once programming a method to search a substring inside a string... ;), and today it happened again.
Augusto Ruiz has left a comment in my last post about GDI DoubleBuffering that is worth to mention, because all the DoubleBuffer implementation I showed in the last post, can be overriden by a simple property of the control you are going to render in:
This property is inherited from Control, so any windows control has it, but is protected. Thats why you need to create a custom Panel, Button, or whatever you want to use as rendering target. Just change its value in the constructor and that´s it!
The previous implementation still has it´s advantages, like a full control on the rendering and presentation process, but for simple cases this way is muuuuuch simpler.
Can´t understand why a google on this topic shows CodeProject entries talking about a custom implementation like the previous one, and no one talks about this way. Probably because it´s too simple and everybody knows it... je je...
Great!
As a C++ programmer, when I moved to .net I was not used to have things done there for me, so I tended to do everything on my own (I found myself once programming a method to search a substring inside a string... ;), and today it happened again.
Augusto Ruiz has left a comment in my last post about GDI DoubleBuffering that is worth to mention, because all the DoubleBuffer implementation I showed in the last post, can be overriden by a simple property of the control you are going to render in:
public class DoubleBufferedPanel : Panel
{
public DoubleBufferredPanel()
{
this.DoubleBuffered = true;
}
}
This property is inherited from Control, so any windows control has it, but is protected. Thats why you need to create a custom Panel, Button, or whatever you want to use as rendering target. Just change its value in the constructor and that´s it!
The previous implementation still has it´s advantages, like a full control on the rendering and presentation process, but for simple cases this way is muuuuuch simpler.
Can´t understand why a google on this topic shows CodeProject entries talking about a custom implementation like the previous one, and no one talks about this way. Probably because it´s too simple and everybody knows it... je je...
Great!
TheCodeProject article: easy integration between XNA and Windows Forms
I have just posted this article to TheCodeProject, it talks about how to render XNA graphics inside a Windows form.


Better graphics in XBox360 than in PlayStation3 ?
Today, watching some videos in one of my favourite sites, I´ve found a comparison between Assassin´s Creed for XBox360 and PlayStation3.
Link: http://www.gametrailers.com/game/2581.html

It´s quite impressive to see that XBox360 beats the PS3 up in this game. Some people say it´s just a contrast or gamma adjustment issue, but I don´t think so. We must trust the GameTrailers people to be professional and to have made the comparison with the same adjustments.

In the XBox360 version there´s more detail and, to my eyes, there´s some cool HDR which doesn´t appear in the PS3 version (see picture above).
It´s true that consoles need some time to do their best, and the PS3 is much younger than the XBox, but for the same reason, it also has better hardware (in theory).
Who knows...
Link: http://www.gametrailers.com/game/2581.html

It´s quite impressive to see that XBox360 beats the PS3 up in this game. Some people say it´s just a contrast or gamma adjustment issue, but I don´t think so. We must trust the GameTrailers people to be professional and to have made the comparison with the same adjustments.

In the XBox360 version there´s more detail and, to my eyes, there´s some cool HDR which doesn´t appear in the PS3 version (see picture above).
It´s true that consoles need some time to do their best, and the PS3 is much younger than the XBox, but for the same reason, it also has better hardware (in theory).
Who knows...
XNA Image Reflector. Easily create web 2.0 reflected images
In the last months or years, every single power point I see, with a decent design and look, includes pictures that have been "reflected" vertically, as if they where in the top of a reflecting table or so... it´s the so-called "web 2.0 reflection". Just like this one:

This kind of effect can be easily done with Photoshop or whatever, just reflecting the image and aplying a distort and a gradient mask, but hey! those 5 minutes per image are priceless! So I decided to make a small app that allows you to create this kind of effect in 5 seconds.
Probably there´s already something similar out there (see below), but I do it just for fun and to practice some new things I´m explaining below. I will upload the source code here or at TheCodeProject, so you all can check how it´s done.
Specs:


This kind of effect can be easily done with Photoshop or whatever, just reflecting the image and aplying a distort and a gradient mask, but hey! those 5 minutes per image are priceless! So I decided to make a small app that allows you to create this kind of effect in 5 seconds.
Probably there´s already something similar out there (see below), but I do it just for fun and to practice some new things I´m explaining below. I will upload the source code here or at TheCodeProject, so you all can check how it´s done.
Specs:
- Automatic reflection using a reflection polygon to specify the shape of the form to reflect
- Automatic reflection distortion
- Automatic alpha gradient with different gradient modes
- Image resizing and re-locating
- Post-processing effects for reflection: Blur, Alpha Texture, ...
- Supports following formats: BMP, JPEG, TGA, PNG, DDS, DIB, HDR, PPM, PFM
Technical info:
- Developed in Visual C# Express
- All the maths and graphics done with XNA
- Shows integration between XNA and Windows Forms
An example:
1.- Take the original picture:

2.- Apply my XNAImageReflector: with blur post processing turned on
As you can see, the cool thing of all this stuff (appart from the post-proc effects) is that you can build a path that will define the shape of the reflection. Not just vertical or horizontal reflections, which are Ok for non-perspective objects, but that doesn´t work well on logos like this one.
3.- Save the final image:
Other examples created with XNAImageReflector:

This one shows the Alpha Texture post processing effect too:
Similar projects and tutorials I´ve found:
- A web based reflector.
- A tutorial on making reflections with WPF.
- A tutorial about making the same thing with Photoshop.
- Some tips about making it with ImageMagick
- Something similar in C#
- Another tutorial about doing it with Adobe Illustrator
Cheers!
XNA easy and efficient primitive rendering (PrimitiveBatch)
Recently, I got into the situation where I had to render a simple line in a 2D view, in XNA. As the fixed func. pipeline is no longer available, in order to do so you would have to deal with a shader. Probably a BasicEffect or another one created to render 2D lines.
I just googled up for "xna 2d rendering" and I´ve found this article in ZiggyWare (a must for any XNA developer). It shows how to do some basic collision detection between polygons, but as far as it also renders those polygons with lines, I was interested on it.
To draw all the lines there, he uses the PrimitiveBatch class, a very helpful class developed in one of the XNA samples available here, that I honestly didn´t take the time to look at. It behaves in a similar way as the SpriteBatch, basically:
batch.Begin( primitiveType );
batch.AddVertex( Vector2D);
...
batch.AddVertex( Vector2D);
batch.End();
And that´s it. Easy, ain´t it?
Cheers!
I just googled up for "xna 2d rendering" and I´ve found this article in ZiggyWare (a must for any XNA developer). It shows how to do some basic collision detection between polygons, but as far as it also renders those polygons with lines, I was interested on it.
To draw all the lines there, he uses the PrimitiveBatch class, a very helpful class developed in one of the XNA samples available here, that I honestly didn´t take the time to look at. It behaves in a similar way as the SpriteBatch, basically:
batch.Begin( primitiveType );
batch.AddVertex( Vector2D);
...
batch.AddVertex( Vector2D);
batch.End();
And that´s it. Easy, ain´t it?
Cheers!
The real Cooperative Gaming
I´ve found a picture of what should be the so-called "cooperative gaming":

This is friendship, isn´t it?
Juas !...
This is friendship, isn´t it?
Juas !...
Tetris a.k.a "Cuadrados de Rusia"
Y es que así es como parece que conocen en China al Tetris.
Yo ya sabía que era un juego adictivo, porque me dejaba casi todas las monedas de 25 pelas que componían mi paga en la jodía maquinilla, pero es que esta noticia me ha dejado "pa'llá":
Una anciana china de 72 años, adicta a los vídeojuegos desde hace dos décadas

La colega (se llama Liu Zhi), que se inició en este aciago mundo con el Tetris, empieza a jugar a las 9 de la mañana y termina a las 10 de la noche, y si no la vigilan, se olvida hasta de comer.
No me quiero imaginar qué nivel de experiencia tendrá en el WOW ! Debe ser la portadora de la "espada de las mil verdades".
Juas !....
Yo ya sabía que era un juego adictivo, porque me dejaba casi todas las monedas de 25 pelas que componían mi paga en la jodía maquinilla, pero es que esta noticia me ha dejado "pa'llá":
Una anciana china de 72 años, adicta a los vídeojuegos desde hace dos décadas

La colega (se llama Liu Zhi), que se inició en este aciago mundo con el Tetris, empieza a jugar a las 9 de la mañana y termina a las 10 de la noche, y si no la vigilan, se olvida hasta de comer.
No me quiero imaginar qué nivel de experiencia tendrá en el WOW ! Debe ser la portadora de la "espada de las mil verdades".
Juas !....
TechEd 2007. More C# 3 features. Object and collection initializers
Another great feature of C# version 3, shown in the TechEd today and yesterday is Object Initializers.
Working as expressions, we can create and initialize objects in a single statement. Imagine we have a class Provider, with properties Name and email. We can do the following:
Provider prv = new Provider() { Name="Microsoft", email = "microsoft@microsoft.com" }
That will create the object and initialize every property we include between the brackets.
In a very similar way work the Collection Initializers, where we can add new items to a collection in the same statement we create it:
List list = new List()
{
new Provider(),
new Provider(),
....
}
And those two features can be nested in the following way:
List list = new List()
{
new Provider() { Name="Microsoft", email = "microsoft@microsoft.com" },
new Provider() { Name="AMD", email = "amd@amd.com" },
....
}
Cheers!
Working as expressions, we can create and initialize objects in a single statement. Imagine we have a class Provider, with properties Name and email. We can do the following:
Provider prv = new Provider() { Name="Microsoft", email = "microsoft@microsoft.com" }
That will create the object and initialize every property we include between the brackets.
In a very similar way work the Collection Initializers, where we can add new items to a collection in the same statement we create it:
List
{
new Provider(),
new Provider(),
....
}
And those two features can be nested in the following way:
List
{
new Provider() { Name="Microsoft", email = "microsoft@microsoft.com" },
new Provider() { Name="AMD", email = "amd@amd.com" },
....
}
Cheers!
TechEd 2007. .NET Language Integrated Query (LINQ)
The last session I attended on monday was:
The .NET Language Integrated Query (LINQ) Framework
by Luca Bolognese (Senior Program Manager, Microsoft).
For anyone thas has worked in data access components, software, or have struggled at anytime with databases, this represents a huge step forward in terms of productivity, robustness, understandability, and efficiency.
I´m no expert in such issues but, to my eyes, it´s just as if you could write SQL sentences right in the middle of your C# code, combined with the power of .net of course. In addition to that, LINQ can work against almost any kind of data source (SQL data bases, xml, arrays, collections, etc), and serve as well as a datasource for dataBinding.
An example:
[Assume "names" is a collection of strings, an array or whatever]
List<string> query = from s in names
where s.Length == 5
orderby s
select s.ToUpper();
The full LINQ sentence is evaluated as a single expression, but is executed in steps. First, every string in "names" is selected and returned to the second sentence. This one applies a filter selecting those with length == 5 and returns another collection, which is ordered in the third sentence. And so on... as complex as you may need.
I asked Luka how the debugger behaves in this sentences, and he said that LINQ sentences are watched in a special window which allows to see each step of the execution. This is something I´m definately waiting to try.
Just as a last note, LINQ doesn´t always behave this way, as this would be very inefficient. If the collection it´s parsing is just that, something that implements iEnumerable, it behaves so, parsing each element in the collection, iterating through the full array.
BUT, the interesting thing is: if the collection being parsed also implements iQueryable, it behaves differently, building a full query from the LINQ sentences and executing it, as once, at the end. This obviously would make debuggin more difficult, but is the efficient way to execute certain types of queries.
Cheers!
The .NET Language Integrated Query (LINQ) Framework
by Luca Bolognese (Senior Program Manager, Microsoft).
For anyone thas has worked in data access components, software, or have struggled at anytime with databases, this represents a huge step forward in terms of productivity, robustness, understandability, and efficiency.
I´m no expert in such issues but, to my eyes, it´s just as if you could write SQL sentences right in the middle of your C# code, combined with the power of .net of course. In addition to that, LINQ can work against almost any kind of data source (SQL data bases, xml, arrays, collections, etc), and serve as well as a datasource for dataBinding.
An example:
[Assume "names" is a collection of strings, an array or whatever]
List<string> query = from s in names
where s.Length == 5
orderby s
select s.ToUpper();
The full LINQ sentence is evaluated as a single expression, but is executed in steps. First, every string in "names" is selected and returned to the second sentence. This one applies a filter selecting those with length == 5 and returns another collection, which is ordered in the third sentence. And so on... as complex as you may need.
I asked Luka how the debugger behaves in this sentences, and he said that LINQ sentences are watched in a special window which allows to see each step of the execution. This is something I´m definately waiting to try.
Just as a last note, LINQ doesn´t always behave this way, as this would be very inefficient. If the collection it´s parsing is just that, something that implements iEnumerable, it behaves so, parsing each element in the collection, iterating through the full array.
BUT, the interesting thing is: if the collection being parsed also implements iQueryable, it behaves differently, building a full query from the LINQ sentences and executing it, as once, at the end. This obviously would make debuggin more difficult, but is the efficient way to execute certain types of queries.
Cheers!
TechEd 2007. VStudio 2008, C# 3, Automatic Properties
Just following the previous post, I keep talking about the session by Daniel Moth (http://www.danielmoth.com/Blog ), yesterday in the TechEd.
He showed another C# 3 new feature that is extremely useful: Automatic Properties.
You not tired about writing something like this?
private int mNumCustomers;
public int NumCustomers
{
get{return mNumCustomers;}
set{mNumCustomers = value;}
}
This is a pain in the ass... You are supposed to use properties, to be clear, clean, robust, elegant, and a good christian, but writing them is painful. Yes, refactoring helped quite a bit, but it´s still something... don´t know... slow and uncomfortable.
Well, Microsoft says that is there to make us more productive, as there it is:
Automatic Properties a.k.a JustWriteThis:
public int NumCustomers{get; set;}
The language will take care of creating the private equivalent variable, just for us. We don´t need to write it. Just specify if you want the get and set, the get only, etc, and there it is!
Again, more productivity...
He showed another C# 3 new feature that is extremely useful: Automatic Properties.
You not tired about writing something like this?
private int mNumCustomers;
public int NumCustomers
{
get{return mNumCustomers;}
set{mNumCustomers = value;}
}
This is a pain in the ass... You are supposed to use properties, to be clear, clean, robust, elegant, and a good christian, but writing them is painful. Yes, refactoring helped quite a bit, but it´s still something... don´t know... slow and uncomfortable.
Well, Microsoft says that is there to make us more productive, as there it is:
Automatic Properties a.k.a JustWriteThis:
public int NumCustomers{get; set;}
The language will take care of creating the private equivalent variable, just for us. We don´t need to write it. Just specify if you want the get and set, the get only, etc, and there it is!
Again, more productivity...
TechEd 2007. VisualStudio 2008, C# 3, MultiTargeting and Anonymous Types
Yesterday, from 16 to 17:15, Daniel Moth (http://www.danielmoth.com/Blog ) introduced the new features of VStudio 2008 and .Net Framework 3.5. It was a very impressive session, fun and interesting.
Specially exciting the new multi-targeting feature of VStudio 2008. It´s a way to tell the environment which .Net Framework version your project will target, through the project´s properties window. Just selecting in a comboBox if it targets version 2.0, 3.0, or 3.5. By selecting one of them, all of the version features are enabled or disabled for your project, and it´s possible to switch between them without loosing work. Your project will just adapt to that perfectly.
Just as a tip, VStudio 2008 finally has the option "Open folder in windows explorer" in the context menu of the solution explorer... Yeeeeeaaahhhh ! Cannot imagine why something that simple didn´t appear before. No more navigating to bin\debug folder....
Also found quite interesting some of the new C# 3 features, like anonymous types. Didn´t you find redundant something like this before?
Form f = new Form();
Why do I have to say that "f" is a windows form twice? No more, just write something like this:
var f = new Form();
And the compiler will infer that "f" is a windows form just reading the code on the right part of the sentence. It´s important to mark that this has no performance impact, as it´s just a compiler feature. Each time you compile, the MSIL code generated will definately contain the declaration in the old way. It´s just a helper right there for you, just to be more productive. And of course it works with anything:
var a = 5;
var a = 5f;
var a = new Class1();
var a = "";
Great!
Specially exciting the new multi-targeting feature of VStudio 2008. It´s a way to tell the environment which .Net Framework version your project will target, through the project´s properties window. Just selecting in a comboBox if it targets version 2.0, 3.0, or 3.5. By selecting one of them, all of the version features are enabled or disabled for your project, and it´s possible to switch between them without loosing work. Your project will just adapt to that perfectly.
Just as a tip, VStudio 2008 finally has the option "Open folder in windows explorer" in the context menu of the solution explorer... Yeeeeeaaahhhh ! Cannot imagine why something that simple didn´t appear before. No more navigating to bin\debug folder....
Also found quite interesting some of the new C# 3 features, like anonymous types. Didn´t you find redundant something like this before?
Form f = new Form();
Why do I have to say that "f" is a windows form twice? No more, just write something like this:
var f = new Form();
And the compiler will infer that "f" is a windows form just reading the code on the right part of the sentence. It´s important to mark that this has no performance impact, as it´s just a compiler feature. Each time you compile, the MSIL code generated will definately contain the declaration in the old way. It´s just a helper right there for you, just to be more productive. And of course it works with anything:
var a = 5;
var a = 5f;
var a = new Class1();
var a = "";
Great!
TechEd 2007. KeyNote by S. Somasegar
Yesterday, at 14:00 we attended the keynote of the TechEd2007, by Microsoft´s developer division corporate vice-president, Mr. S. Somasegar.
He presented the new key features of Microsoft developments plattform: VisualStudio 2008, .Net Framework 3.5, SilverLight, the Expression Studio tools, etc.
To summarize, he presented an important part of what we are going to see in deeper detail through this next days.
More later...
Suscribirse a:
Entradas (Atom)
