Jump to content

  • Log In with Google      Sign In   
  • Create Account

Ubuntu SDL_GL_CreateContext failing


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 polyfrag   Crossbones+   -  Reputation: 1841

Like
0Likes
Like

Posted 20 June 2014 - 03:30 PM

Somebody ported my code to linux using cmake. They got it to run, but when I tried to compile it with cmake it complained that libGL.so was missing DSO or something.

I fixed it (correctly or not) like this:

CMakeLists.txt

...

ADD_DEFINITIONS("-std=c++0x"
    -lGL
    -lGLU
    -lGLEW)

...

FIND_PACKAGE(OpenGL REQUIRED)
FIND_PACKAGE(GLEW REQUIRED)

...

TARGET_LINK_LIBRARIES(
...
        ${GL_LIBRARIES}
        ${GLU_LIBRARIES}
...
  ${OPENGL_LIBRARIES}
        )

That was enough to compile the program. But it complained about "Couldn't create GL context" at the end here:

g_log<<"samw0"<<endl;
  g_log.flush();

  g_log<<"GL_VERSION: "<<(char*)glGetString(GL_VERSION)<<endl;
  g_log.flush();

  g_log<<"sa"<<endl;
  g_log.flush();

  // Request compatibility because GLEW doesn't play well with core contexts.
#if 1
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); 
  SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); 
  SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
  SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
  SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); 
#endif

  unsigned int flags;
  int startx;
  int starty;

  if(g_fullscreen)
  {
    startx = SDL_WINDOWPOS_UNDEFINED;
    starty = SDL_WINDOWPOS_UNDEFINED;
    flags = SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN;
  }
  else
  {
    startx = SDL_WINDOWPOS_UNDEFINED;
    starty = SDL_WINDOWPOS_UNDEFINED;

    flags = SDL_WINDOW_OPENGL;
  }

  // Create an application window with the following settings:
    g_window = SDL_CreateWindow(
        title,                  // window title
        startx,           // initial x position
        starty,           // initial y position
        g_selectedRes.width,                               // width, in pixels
        g_selectedRes.height,                               // height, in pixels
        flags                  // flags - see below
    );
   ...
  g_glcontext = SDL_GL_CreateContext(g_window);
  //SDL_GL_SetSwapInterval(1);

  g_log<<"GL_VERSION: "<<glGetString(GL_VERSION)<<endl;

  if(!g_glcontext)
  {
    DestroyWindow(title);
    ErrorMessage("Error", "Couldn't create GL context");
    return false;
  }

You can see at the very beginning there I try to check GL version:

 g_log<<"GL_VERSION: "<<(char*)glGetString(GL_VERSION)<<endl;

But there's some kind of problem because all I see in the log is:

 

 

samw0
GL_VERSION:

 

 

And after that there's nothing, even though the program doesn't stop there. So it seems like I'm linking to GL wrong or something.

How do I diagnose the problem? Do I walk through the dependencies or something (how)?

Should it be red when make says:

 

 

Linking CXX executable corpstatesc

 

?

Attached Thumbnails

  • 1403285019287.png


Sponsor:

#2 polyfrag   Crossbones+   -  Reputation: 1841

Like
0Likes
Like

Posted 20 June 2014 - 04:37 PM

Seems the problem is it can't get an OpenGL 3.2 context, but returns a 3.0 fine if I don't specify which one to get.

 

glxinfo says I have 3.3 core and 3.0

 

 

name of display: :0
display: :0 screen: 0
direct rendering: Yes
server glx vendor string: SGI
server glx version string: 1.4

OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) Ivybridge Mobile
OpenGL core profile version string: 3.3 (Core Profile) Mesa 10.3.0-devel (git-96a95f4 saucy-oibaf-ppa)
OpenGL core profile shading language version string: 3.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile


OpenGL version string: 3.0 Mesa 10.3.0-devel (git-96a95f4 saucy-oibaf-ppa)
OpenGL shading language version string: 1.30
OpenGL context flags: (none)

 

I can get a 3.3 core context but not a 3.2 one, compatibility or core.

 

 

Is 3.2 not supported on linux? Maybe not for my integrated Intel videocard? Can I programmatically switch to the NVidia Quadro high-performance card I have?


Edited by polyfrag, 20 June 2014 - 04:40 PM.


#3 monciwoda   Members   -  Reputation: 103

Like
0Likes
Like

Posted 23 June 2014 - 01:14 PM

With mesa drivers, you cannot create compatybility context past version 3.0( according to http://cgit.freedesktop.org/mesa/mesa/tree/docs/GL3.txt at least):

 

 

OpenGL Core and Compatibility context support

OpenGL 3.1 and later versions are only supported with the Core profile.
There are no plans to support GL_ARB_compatibility. The last supported OpenGL
version with all deprecated features is 3.0. Some of the later GL features
are exposed in the 3.0 context as extensions.  

 

That's for radeon, nouveau and intel drivers. But proprietary nvidia(https://developer.nvidia.com/opengl-driver) (and probably catalyst too?)drivers seems to support compatibility profiles up to opengl4.4.

 

So it seams that only options are:

1. use 3.0 context and load >=3.1 features as extensions

2. use core 3.3 context

 

As of switching to nvidia card: http://bumblebee-project.org/



#4 polyfrag   Crossbones+   -  Reputation: 1841

Like
0Likes
Like

Posted 25 June 2014 - 03:22 PM

I'm now optimizing for an older Inspiron 530 with an integrated videocard that only supports OpenGL 1.4. Really annoying. I'll look into bumblebee. If I install nvidia drivers, will that let me use the high-performance card?



#5 polyfrag   Crossbones+   -  Reputation: 1841

Like
0Likes
Like

Posted 26 June 2014 - 03:36 AM

Bumblebee daemon doesn't detect the discrete videocard. I searched around and that might mean I need to update my BIOS. I tried booting FreeDOS from USB and CD but it just freezes at the Dell screen when I try USB. My laptop boots it fine.

 

The exact error messages happens here:

 

https://github.com/Bumblebee-Project/Bumblebee/blob/master/src/bumblebeed.c

int main(int argc, char* argv[]) {

...

pci_bus_id_discrete = pci_find_gfx_by_vendor(PCI_VENDOR_ID_NVIDIA, 0);
  if (!pci_bus_id_discrete) {
    bb_log(LOG_ERR, "No discrete video card found, quitting\n");
    return (EXIT_FAILURE);
  }

That function is defined in:

 

https://github.com/Bumblebee-Project/Bumblebee/blob/master/src/pci.c

struct pci_bus_id *pci_find_gfx_by_vendor(unsigned int vendor_id, unsigned int idx) {
...

fp = fopen("/proc/bus/pci/devices", "r");
  if (!fp) {
    return NULL;
  }

  result = malloc(sizeof (struct pci_bus_id));
  if (!result) {
    return NULL;
  }

  while (fgets(buf, sizeof(buf) - 1, fp)) {
    if (sscanf(buf, "%x %x", &bus_id_numeric, &vendor_device) != 2) {
      continue;
    }
    /* VVVVDDDD becomes VVVV */
    if (vendor_device >> 0x10 == vendor_id) {
      if (pci_parse_bus_id(result, bus_id_numeric)) {
        int pci_class = pci_get_class(result);
        if (pci_class == PCI_CLASS_DISPLAY_VGA ||
                pci_class == PCI_CLASS_DISPLAY_3D) {
          /* yay, found device. Now get next, or clean up and return */
          if (idx--) {
            /* It's not yet our device */
            continue;
          }
          fclose(fp);
          return result;
        }
      }
    }
  }

https://github.com/Bumblebee-Project/Bumblebee/blob/master/src/pci.h

#define PCI_VENDOR_ID_NVIDIA  0x10de 
#define PCI_VENDOR_ID_INTEL  0x8086 
#define PCI_CLASS_DISPLAY_VGA 0x0300 
#define PCI_CLASS_DISPLAY_3D  0x0302

I checked that file /proc/bus/pci/devices

0000  808629c0  0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0  agpgart-intel
0008  808629c1  28                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0  pcieport
0010  808629c2  2c          fdf00000              ff01          d0000008          fd800000                 0                 0                 2             80000                 8          10000000            100000                 0                 0                 0  i915
00c8  808610c0  2b          fdfc0000          fdfff000              fe01                 0                 0                 0                 0             20000              1000                20                 0                 0                 0                 0  e1000e
00d0  80862937  10                 0                 0                 0                 0              fd01                 0                 0                 0                 0                 0                 0                20                 0                 0  uhci_hcd
00d1  80862938  15                 0                 0                 0                 0              fc01                 0                 0                 0                 0                 0                 0                20                 0                 0  uhci_hcd
00d2  80862939  13                 0                 0                 0                 0              fb01                 0                 0                 0                 0                 0                 0                20                 0                 0  uhci_hcd
00d7  8086293c  12          fdffe000                 0                 0                 0                 0                 0                 0               400                 0                 0                 0                 0                 0                 0  ehci-pci
00d8  8086293e  2d          fdff4004                 0                 0                 0                 0                 0                 0              4000                 0                 0                 0                 0                 0                 0  snd_hda_intel
00e0  80862940  29                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0  pcieport
00e3  80862946  2a                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0  pcieport
00e8  80862934  17                 0                 0                 0                 0              fa01                 0                 0                 0                 0                 0                 0                20                 0                 0  uhci_hcd
00e9  80862935  13                 0                 0                 0                 0              f901                 0                 0                 0                 0                 0                 0                20                 0                 0  uhci_hcd
00ea  80862936  12                 0                 0                 0                 0              f801                 0                 0                 0                 0                 0                 0                20                 0                 0  uhci_hcd
00ef  8086293a  17          fdffd000                 0                 0                 0                 0                 0                 0               400                 0                 0                 0                 0                 0                 0  ehci-pci
00f0  8086244e  0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0  
00f8  80862916  0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0                 0  lpc_ich
00fa  80862920  13              f701              f601              f501              f401              f301              f201                 0                 8                 4                 8                 4                10                10                 0  ata_piix
00fb  80862930  b          fdffc004                 0                 0                 0               501                 0                 0               100                 0                 0                 0                20                 0                 0  
00fd  80862926  13              f001              ef01              ee01              ed01              ec01              eb01                 0                 8                 4                 8                 4                10                10                 0  ata_piix
0300  10024d51  b          fdc00004                 0          fa00000c                 0                 0                 0                 0            100000                 0           2000000                 0                 0                 0                 0  

Like it says in the code, it looks for a line where the second hexadecimal number is less than 2159 (in decimals).

Does sscanf(buf, "%x %x", &bus_id_numeric, &vendor_device) read ints or unsigned ints? bus_id_numeric and vendor_device are unsigned int.

The hex 10024d51 is 268,586,321 decimal. The highest unsigned int is 4,294,967,295 and signed int 2,147,483,647. Hex number 80862926 is 2,156,276,006 decimal, which is 8,792,359 higher than signed int max.

But I am not sure if bumblebee is for my desktop. It says my GL_RENDERER is Intel G33 Express if I don't specify which OpenGL version I need, so I assume I have an integrated videocard in addition to NVidia. 

I tried installing the NVidia driver like so

sudo apt-get install nvidia-current

Following http://www.dedoimedo.com/computers/ubuntu-ringtail-nvidia.html

 

But

sudo /sbin/lsmod | grep nvidia

Didn't show anything. I then followed

sudo depmod -a
sudo modprobe nvidia_current

But it couldn't find nvidia_current. I then rebooted and my GUI wouldn't work so I had to remove the NVidia driver from command line mode by

sudo apt-get remove nvidia-*


#6 polyfrag   Crossbones+   -  Reputation: 1841

Like
0Likes
Like

Posted 26 June 2014 - 04:01 AM

Yes, it shows Intel Bearlake G33 under video driver.

http://www.dell.com/support/home/us/en/19/product-support/product/inspiron-530/drivers

#7 polyfrag   Crossbones+   -  Reputation: 1841

Like
0Likes
Like

Posted 26 June 2014 - 03:07 PM

Found the problem. I don't have a discrete videocard at all.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS