C++ PImpl Template

If you’re not familiar with the PImpl (private implementation) idiom, read this Wikipedia article first. While this is more or less “syntactic sugar” since the templates are expanded during compilation, but I think it makes for cleaner looking code.

Read the rest of this entry »

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.

Read the rest of this entry »

OpenGLBook.com Launch

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 JavaScript object:


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:


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:

<WebMethod(Description:="Does something.")> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Function MyMethod(ByVal Something as String) As String ...


[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:

<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 ...


[WebService(Namespace = "http://www.tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
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:


	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:
	success: function (msg) {
		// do something with msg.d, eval() to
		// to retrieve the data.

Carmack on OpenGL & Direct3D

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.

WebGL 1.0 Specification Released

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 »

« Previous Entries