Can't run my own OpenGL 3 programs on Ubuntu
I am experimenting with OpenGL 2.x and 3.x tutorials. The programs compile and link but then segfault on seemingly innocent lines such as
glGenBuffers (1, &m_buffer);
My main()
starts with glewInit
and glutInit
. OpenGL 1 programs compile and run fine, it just seems to be the new functions wrapped by glew.
One tutorial says I should have this test before trying anything else:
if (false == glewIsSupported ("GL_VERSION_2_0"))
This test always fails, even when I change the version string to GL_VERSION_1_0
.
#define GL_VERSION_1_3 1
is the highest such definition in GL/gl.h, and there is no GL/gl3.h or GL/GL3 directory.
apt
says I have freeglut3 and freeglut3-dev installed, also mesa-common-dev, libglew-1.6 and libgl1-mesa-dev, but there doesn't seem to be any libgl3* package available.
Here is some driver info (I have no proprietary drivers, integrated Intel Ivy Bridge graphics with Nvidia extra card, both are I belive OpenGL 1.4 compatible)
#> glxinfo | grep version
server glx version string: 1.4
client glx version string: 1.4
GLX version: 1.4
OpenGL version string: 3.0 Mesa 9.0
OpenGL shading language version string: 1.30
All this has left me quite confused.
Are there specific OpenGL2/3/4 packages I should be installing, or in theory is it the same development package for all (for Ubuntu)?
Why is GL_VERSION_1_3 the highest defined version whereas glGenBuffers wasn't introduced until version 1.5?
Why does glewIsSupported fail even for version 1.0?
The impression I get is that I don't have libraries and/or drivers which actually implement the API, but seems as though I do according to glxinfo, which makes me think there's something wrong with the development libraries, but I don't have a coherent picture of what is going on there.
Basically, what do I have to do to get my program to compile/link/run?
I know Ubuntu isn't a great development environment but please don't suggest that I change distro. There must be a way!
My main()
starts with glewInit
and glutInit
Nope. You don't get a current GL context until glutCreateWindow()
returns. You can call glewInit()
and glewIsSupported()
after that.
Something like this:
#include <GL/glew.h>
#include <GL/glut.h>
...
int main( int argc, char** argv )
{
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );
glutInitWindowSize( 300, 300 );
glutCreateWindow( "OpenGL" );
glewInit();
...
return 0;
}
链接地址: http://www.djcxy.com/p/38504.html