Wednesday
Jun012005

Laszlo!

It's been at least a day since I wrote about how excited I am to be working with Laszlo. Oliver Steele posted a job description which may or may not be the job that I'm filling, but it's close, especially in values and mood. Scott Evans also posted about working at Laszlo. These are cool people, is my point.

I'm going to be in San Francisco/San Mateo from Sunday to Saturday of next week.

Bill Clinton says he weighs just about as much as he did when he graduated from high school.

Wednesday
Jun012005

C++ OpenGL rendering to .NET control

Dana and I worked through some OpenGL setup stuff, and we got C++ OpenGL calls rendering to my .NET control. I get the HDC in C# from the PaintEventArgs, and pass the HDC through to my C++ OpenGL rendering code... and it draws! Mostly.

With my current code, I only see the opengl-painted stuff when I minimize, then maximize the window; my opengl code gets called every paint event, but it only gets drawn visibly after a maximize event. I'm not yet very worried about this, because I'm making a new wglContext every paint event, which is not ideal. My next step is to make one wglContext for a ManagedWindow, and reuse it for subsequent redraws.

Here's the most important nugget of the code


// C#
// Paint handler for my .NET control
private void LeoControl_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
System.IntPtr hdc = e.Graphics.GetHdc();
// Call the C++ internals to render some stuff onto this widget.
CSCppWrapper wrapper = new CSCppWrapper();
// initHDC also draws some test stuff into the HDC
wrapper.initHDC(hdc);
e.Graphics.ReleaseHdc(hdc);
}

// C++
void
CppInternals::initHDC(HDC hdc)
{
_hdc = hdc;

// create and enable the render context (RC)
_hrc = wglCreateContext( _hdc );

PIXELFORMATDESCRIPTOR pfd;
int format;

// set the pixel format for the DC
ZeroMemory( &pfd, sizeof( pfd ) );
pfd.nSize = sizeof( pfd );
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
format = ChoosePixelFormat( _hdc, &pfd );
SetPixelFormat( _hdc, format, &pfd );

renderScene();

// pair with create context call.
wglDeleteContext( _hrc);

}

void
CppInternals::renderScene() {

// Tell it to render to the context we initialized in initHDC
wglMakeCurrent( _hdc, _hrc );

.
.
.
// make some opengl calls here to draw stuff
// ....
.
.
.

// Actually put this opengl stuff on the screen!
// Except, this doesn't seem to actually put the stuff on the screen... I don't think.
SwapBuffers(_hdc);

// Let go of this context
wglMakeCurrent( NULL, NULL);

}

This makes me so very very happy.

Tuesday
May312005

indistinguishable from magic (more on .net/c++ windows development)

Corey Taylor, a helpful developer on the g3d sourceforge forums pointed out some problems with code I posted last night; I think he's saying, essentially, that my C#/.NET app isn't doing what I want because the c++ code I'm calling doesn't do what I want. Makes sense. I need to make the c++ work, which means
create a valid G3D::RenderDevice, with an OpenGL context, and then access the image drawn by the RenderDevice. Arrg... There's some magical switchover between HDC (handle to a device context, I think -- a very very windows concept) and OpenGL context and System.Windows.Forms.PaintEventArgs...
Arthur C. Clarke said that any sufficiently advanced technology is indistinguishable from magic. How about any sufficiently obscure technology? Obscure, occult, obfuscated...

Aha. System.Windows.Forms.PaintEventArgs.Graphics.GetHDC() lets me access the HDC associated with my very own .NET component, in its Paint handler.

Now I need to go from an HDC to a G3D::RenderDevice, or maybe a G3D::Win32Window. I don't understand the relationship between a "window" and a "render device" in G3D. I can go read the code, though.

Meanwhile, Morgan McGuire (the uber-knowledgeable creator of G3D) is suggesting I create an ActiveX control, but I'm thinking, "Oh god, do I have to learn another Microsoft GUI component technology?"

Tuesday
May312005

How not to get a job over the internet

I posted in craigslist looking for someone to clean my apartment after I move all my stuff out. I liked a message from this one student; he seemed pretty clueful, and was a student. I wrote back to him with the intelligence screening (in the previous blog post) but I haven't heard back. I just noticed the subject line in his email to me:
"responce to your job add."

Sorry, no. Misspelling two words in the five-line subject of a response to a job ad is not the way to demonstrate your acumen.

Mistakes of previous professional cleaners:


  • Leaving the windows of my seventh-floor apartment wide open. I have two cats, and the windows don't have screens.

  • Sweeping the floor near the cat food, then putting the dirt from the floor into the cats' dish.

  • Using windex on a brand new (two days old!) 19" CRT monitor with an antiglare finish. Goodbye, antiglare finish.

  • Getting trapped in the bedroom by closing the door and pulling the doorknob off, then not being able to put it back in.

  • Putting my eyeglasses into a mug along with a dozen pens.

Now, is there anyone who can spell who'd like to clean my apartment for a few extra bucks?

Tuesday
May312005

george w. bush is stupid

George W. Bush is stupid... or at least, he has some serious problems with verbal communication. I'm watching him give a live news conference -- I don't have a transcript yet, but if I do misquote him, the misquoting still accurately represents his errors.

Re Guantanamo and Abu Ghraib prisoner abuse scandal: "We've investigated each of the detainees..." How about investigating each of the claims of abuse? And, "[the detainees are] men who've been trained to dissassemble. That means to lie." Sorry, George, "to dissemble" is to deceive, and "to disassemble" is to take something apart. You're almost right.

I love this one: "For almost a decade, the United States hasn't had an energy policy." Wait, George, weren't you president for five of those years? And wasn't your party in the majority in congress? So whose fault is it that there's been no sensible energy policy? Really hard to blame the radical left for that one. Oh, I see, the point of this speech is to wave his fist at congress because they're not completely bending over to do absolutely everything he wants.

There were more, and I'm sure we'll be seeing them on the blogs soon enough. For a comparison of intelligence requirements, I'm trying to find someone to clean my house for money, a professional move-out cleaning. I'm asking candidates to answer a quick intelligence screening, because in the past some cleaners have made some really stupid mistakes, like using windex on a brand new monitor with an antiglare coating. So here's the questions I ask:

You can tell whether it's safe to unplug something plug by...

Clean computers and electronics with...

If we're not careful, cats might...
a) run out open doors
b) fall out open windows
c) start a fire
d) exert mind control on their owners

Business cards and receipts piled on the floor in a corner are probably...
a) garbage
b) recycling
c) precious
d) no idea, so i'd better save them

Pick the right word... "Gee, this diet must be working, because my
pants are really (a) loose. (b) lose."

I ask you -- could George W. Bush have answered each of those questions correctly? If he can, please send him to Providence; I need to hire some unskilled labor.