views:

189

answers:

2

When compiling and running my GLFW-based C program under Ubuntu (9.04), it fails when trying to open the window (it compiles fine, having installed the latest GLFW). I've tried varying resolutions, going as low as 300x300, and left the bit depths to zeros, hoping a default will catch on.

The relevant piece of code reads (directly snipped from the top of my main file, based on the example file gears.c):

// File: main.c
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include <GL/glfw.h>

#ifndef PI
#define PI 3.141592654
#endif

int main(int argc, char* argv[])
{
    // Initialize GLFW:
    glfwInit();

    if (!glfwOpenWindow(300, 300, 0, 0, 0, 0, 0, 0, GLFW_WINDOW)) // Yo failure!
    {
        printf("Window open failed.\n");
        glfwTerminate();
        return 0;
    }

    glfwSetWindowTitle("...");

    ...

    // Clean up:
    glfwTerminate();

    return 0;
}

Other noteworthy facts are:

  • Running Ubuntu inside VirtualBox 3.0.2, config'd w/ 512 MB RAM, 3D acceleration enabled, 64 MB VRAM, Guest Additions successfully installed
  • glxgears works fine, even > 300 FPS
  • built GLFW using make-x11
  • makefile command line:

    gcc 'pkg-config --cflags libglfw' main.c -o program 'pkg-config --libs libglfw' -lglfw -lGLU -lGL -lm

(where the 's should be replaced with single backwards apostrophes, problems formatting)

I'm almost tearing my hair out on this, as it's my first GLFW program on Linux (being happy with Tao and C# on Windows) I've barely got started on it and I'm not able to get the most basic things working.

Edit:

Are there any way to extract a more fancy error message? Any getLastErrorDesc() or debug log files?

A: 

You are trying to open a window with 0bpp, of course it's going to fail :)

Try this:

    glfwOpenWindow(
                   800, 600,   // Window size
                   8, 8, 8, 8, // bitdepth per channel (RGBA)
                   24,         // Z buffer bitdepth
                   0,          // Aux buffer bitdepth
                   GLFW_WINDOW // Window
                  );

Also, on latest Ubuntu, there's actually a package called libglfw-dev you can install, just in case you forgot to link any extra libraries (like librandr).

LiraNuna
Have you checked the documentation to back up your facts on the bit depth? Because it clearly states that 0 => default depth. I used 8 bits per channel initially, then switched to 0 to see if GLFW could determine a better setting. I'll look into libglfw-dev and librandr, though.
Cecil Has a Name
That's weird, I was sure 0 was an invalid value. I'll leave it here for your comment to make sense. You are indeed right.
LiraNuna
I've tried 16-bits (5, 6, 5) and other combinations. I'm thinking it might be an issue with the virtualization, so I'll take a look at Mesa.
Cecil Has a Name
A: 

Are you using the version packaged in Ubuntu or some version from the GLFW Subversion repository? The GLXFBConfig selection in the Subversion repo was broken for quite a while, due to the removal of the custom Visual selection, so you may have received bad code.

If that's the case, you should either revert to the version bundled with Ubuntu or pull a fresh tree from Subversion.

elmindreda
Thank you for taking your time to post a suggestion. I downloaded it from http://glfw.sourceforge.net/download.html, being oblivious to Ubuntu already having packages for it (albeit uninstalled at the time). Currently I have solved the problem with a "physical" installation of Ubuntu. I will, however, and try to remove the stuff that the GLFW install script copied onto the virtual hard drive, and use Ubuntu's built in package support for GLFW, to see if that works.
Cecil Has a Name
I think what you downloaded from the site is identical to the package in Ubuntu, though.
elmindreda