Tuesday, December 22, 2009

built cairo

Wow, this seems to be my blog-month. Or maybe it's the holidays. Or my short hair. Or something else, that makes me more productive.

Note: the following-stuff is quite programming-related and might confuse you if you are not a programmer yourself

Whatever it is, I got cairo to compile and link, finally. Thanks to Stack Overflow I opened the MSYS-enviroment in the Microsoft Visual Studio Commandline Enviroment and thus got the UNIX-tools with the MSVC-tools.
Well, it wasn't as easy as just typing 'make' into it, I had to fiddle around with the makefiles, got some nasty errors, but now I've build all the required libs and cairo itself.

I was already thinking about just using pre-built libraries, but now I can sleep better :P

cairo doesn't have convenience-functions like SDL or OpenGL (though [{free, open}]GLUT) or something to open a window. I could use some GUI-library, but since I'll be using cairo to draw everything that seems to be a little bloat. I'll just have to write the platform-specific stuff for Windows and UNIX with XServer, maybe also MacOS stuff, myself.

As I can only boot Windows atm (install had overridden the boot-sector; didn't care to fix it yet) I started working on the Windows-port. I seem to have to use GDI for cairo, though I am wondering whether or not I am still getting the hardware-accelerated goodness.

I got a Window open pretty fast and used tutorial-code to draw on it, but I wanted debug-output. So I used AllocConsole, but std::cout can't print on that without rerouting.. and that code I saw for that seemed weird, so I wrote a small templated function to use WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), ... instead.

Windows seems to think that my Application does not respond very well and draws that loading-cursor when you hover over it. I also can't click the close-button; probably the same reason. I'm not really sure how to fix it, but I'll care about that later.

I initially had problems redrawing the graphic, which is needed since the scene is going to have moving stuff. I was thinking that RedrawWindow(wnd, NULL, NULL, RDW_INTERNALPAINT) would work, but the message/event WM_PAINT didn't go through. I then tried obtaining the rect via GetBoundsRect(GetDC(wnd), &rect, 0), but it is empty. I simply hard-coded it to have the same height and width as the window itself, and using this I can redraw fine.
Of course I won't be drawing the whole window over and over again in the final version if it doesn't need to be.

Well, right now I am on packing the test-stuff I had into a Window-class. It seems like I can't get a std::tr1::function with __stdcall. Really sucks, because I need to call a member-function for the MessagePump and the Windows SDK uses the __stdcall calling convention.
I tried around with casts 'n stuff, but I can't seem to get it to work :'(

I'll fiddle around a bit more, and if it doesn't work I'll hack it by having a static function in the Window-class returning an instance of itself. Kinda like a singleton, only that Window is no singleton...

No comments: