Thursday, August 26, 2010

compiling opengl-redbook examples on Lucid guest


Rats! Turns out that any video setting or reboot gets confused with the nvidia driver present -- even though it isn't set, it doesn't play nice with the virtualbox driver... convinces it there is no 3D present and runs it in software (dirt slow). I eventually uninstalled it... maybe it's freeglut, but not sure. Needs more research. Later.


I'm starting a class this fall in computer graphics and I thought I'd experiment with trying to compile some of the examples in the redbook. I have to wait for our class copies of VisualStudio (our course is taught targeting Windows), but I wanted to try some things, so I decided to use my Lucid Lynx Ubuntu 10.04 instance to compile examples.

First off, VirtualBox rocks. You have to hand it to the team because their 3D acceleration is strictly super-awesome... it lets me run full compiz settings while running on a i7 920 GTX 260 equipped Windows 7 host. It's fast! Like pretty close to native fast. So fast that I simply use ubuntu in VM mode instead of dual-booting. (Actually, I pretty much like everything about Windows 7 too, except maybe the filesystem changes, but there are more tools available for Linux, so it helps to have the best of both worlds.) Make sure 3D acceleration is enabled in your vm before you start; I also used the max setting of 128 MB VRAM. Anyway, back to the story...

Once in the guest OS, I downloaded the samples via apt-get, installed the usual libs... in this case the ones suggested here. Like the poster I tried the shipped makefile at first and got:

$ make
make: *** No rule to make target `$@.o', needed by `hello'. Stop.

Ug. I suspect some dialect of gnu make doesn't like that variable name or syntax, but gave up trying to understand it too much (yeah, lazy) and switched to the suggested longhand:

$ g++ hello.c -lGL -lGLU -lglut -o hello

Success! Then I ran it:

$ ./hello
OpenGL Warning: XGetVisualInfo returned 0 visuals for 0x24c10a0

Segmentation fault

Ug. Not what I wanted. Did some poking around and found that "nVidia and ATI "driver" installs on linux *replace* -lGL and -lGLU default Mesa installations with their own." So on a lark I tried

$ sudo apt-get install nvidia-glx-185-dev

And it worked like a charm!!

That's kind of obvious (because the VirtualBox 3D is supposed to be as clean a passthru as possible) but also kind of amazing (because the ubuntu guest is setup to use the virtualbox driver, not the nvidia 185 driver for ubuntu) -- it just worked... at least for this sample! :)


1 comment:

Vittorio said...

Correct the Makefile this way:


cc -c -I/usr/include -I$(TOP) $<


$(TARGETS): $$@.o
cc $@.o $(LLDLIBS) -o $@