One of the things that C++ doesn’t have out-of-the-box is events, which is not necessarily a bad thing. However, with the additions to the C++0x/C++11 specification, we can implement something like an event system found in higher level languages such as C# using relatively easy to use code.
Just launched OpenGLBook.com, a website on learning OpenGL 4.0 programming in online book format. The first two chapters are online, new chapters to be released periodically.
If you’re having trouble with getting jQuery to talk to your ASP.NET web service, I may have some tips to ease your pain.
#1: It’s not JSON!
That’s right, even though your WebMethod consumes and returns JSON, you actually have to send a formatted string instead of a pure JSON object:
JavaScript:
var BadArguments = { FirstName: "John", LastName: "Doe" }; // BAD
var GoodArguments = '{ "FirstName": "John", "LastName": "Doe" }'; // GOOD
This means that the JSON used by ASP.NET web services is not portable. To get around this, I created a little JavaScript function that handles one-dimensional associative arrays and converts them to “MS-JSON.” You may want to adapt this function to your needs since it explicitly doesn’t handle “objects” such as arrays or dates:
JavaScript:
function GenerateAspNetJsonString(MyArray) {
var StrOut = '{';
for (var key in MyArray) {
if ('object' != typeof MyArray[key]) {
// The type is not an object, so we can write it down as a string:
StrOut += '"' + key + '":"' + escape(MyArray[key]) + '",'
}
}
// Strip the trailing comma and return:
return StrOut.substr(0, StrOut.length - 1) + '}';
}
#2: Check your Attributes
Chances have that you already marked your web method with the following code:
VB.NET:
<WebMethod(Description:="Does something.")> _ <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _ Public Function MyMethod(ByVal Something as String) As String ...
C#:
[WebMethod(Description = "Does something.")] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public string MyMethod(string Something) ...
But make sure that you have also marked the Web Service’s class with the ScriptService (short for ScriptServiceAttribute) attribute as well. This is not automatically done by Visual Studio when the code is generated, so you’ll have to do it manually:
VB.NET:
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _ <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ <ScriptService()> _ Public Class MyWebService Inherits System.Web.Services.WebService ...
C#:
[WebService(Namespace = "http://www.tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class MyWebService : System.Web.Services.WebService { ...
#3: When all else fails
Check your XmlHttpRequest’s errors, since ASP.NET actually returns quite a bit of useful information in debug mode. Using jQuery, you can add an error handler to your $.ajax function call:
JavaScript:
$.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
url: '/MyWebService.asmx/MyWebMethod',
// notice the usage of the function provided in #1:
data: GenerateAspNetJsonString({
FirstName: 'John',
LastName: 'Doe'
}),
dataType: 'json',
error: function (jqXHR, textStatus, errorThrown) {
// responseText contains all of the interesting
// bits and pieces:
alert(jqXHR.responseText);
},
success: function (msg) {
// do something with msg.d, eval() to
// to retrieve the data.
}
});
John Carmack, of DOOM, Wolfenstein, and Quake fame, has spoken out on the issue of Direct3D vs OpenGL in an interview with the folks at bit-tech. Check out the article here. Note that Carmack is still using OpenGL in his game engines because of cross-platform compatibility reasons, but prefers Direct3D’s more modern API.
It’s sad to see OpenGL in such a state of disrepair that even a contributor (id Software) to the specification denounces the standard.
P.S. Happy π day.
More news from this year’s Game Developers Conference shows some amazing next-gen graphics from Epic Games through their Unreal Engine. It’s certainly worth checking out the article at Tom’s Hardware right here.
The Khronos group has released the final WebGL 1.0 specification today at the Game Developers Conference, here are the relevant links to check out:
As of March 3, 2011 2:45PM, the online specification has not yet been updated to reflect the final changes (still says “draft”).
It’s almost weekend, and time for a lighthearted post on the two realtime 3D computer graphics libraries that are available on Windows in 2011: OpenGL and Direct3D. The reason I mention the year is simply because of the fact that two years from now, this information will be as untrue as the Wikipedia article* on this matter due to rapid hardware and software developments. But for now, let’s bash it out.
Read the rest of this entry »
You’ve heard of Intel’s recent “Cougar Point” chipset screwup causing all motherboards for Sandy Bridge-based Core i7 processors to be pulled from the market until next month when new parts will appear. We’ve also all read the reviews that show the new i7 processors to be very fast and beating AMD’s current lineup in terms of performance. So where does AMD stand?
Well, AMD still has a nice selection of processors in the $100 – $150 range, but they can’t compete with the higher performing Intel processors priced higher. At that $150+ point it just makes more sense to load up your new rig with an i5-2400 or an i7-2600K if you have the cash.
But since you can’t purchase a Sandy Bridge based machine at the moment, doesn’t that leave a market gap for AMD to fill up? Oh, and isn’t it tax return season in the USA? Well, yes to both questions.
People can’t wait to splurge their tax return money on stuff, and many will spend it on a new computer. If you’ve filed your taxes in January or early this month, you should be getting that money pretty soon, and not in time for Sandy Bridge to return if Intel’s statements are correct.
In this spirit, AMD launched its “Ready. Willing. And Stable” ad campaign to take away Intel’s customers. But if you really think about it, why on earth would you buy an old AMD processor when: 1.) Sandy Bridge will be back soon if you can just keep that burning cash in your pocket for a little bit longer, 2.) the current AMD lineup is less than impressive when it comes to performance, and 3.) AMD is poised to release its new “Bulldozer” processor later this year?
I see no reason whatsoever. Bulldozer based chips will be able to compete with Sandy Bridge if we’re to believe AMD’s preliminary reports of a 50% performance increase over Core i7 950, so AMD should put its focus on that instead of launching a FUD campaign.
So, come on AMD, show us what you’re made of. Show us the AMD of the late 1990s and early 2000s that delivered competing products at a lower cost point, not this finger-pointing toothless shell of past achievements.
Scriptionary 