Simple OpenGL code always causes a segmentation error (C ++ on Ubuntu, virtual machine)

I just started trying to use OpenGL in C ++ for a class (I used it enough in Java before). And I started by trying to write something substantial, I could not get it to stop Seg, so I wrote this little piece of code, which is almost a line to translate the line from the example in the first chapter of the red book. This is also Seg. My question is why. I tried both eclipse and netbeans, I have a glut.h library linked in my projects in both, I run 64-bit ubuntu 10.4, in a virtual machine using VMWare, gcc and freeglut are both installed, Both netbeans and eclipse will be run regular (non-OpenGL) C ++ code, which I write without seg crashes.

Anyway, here is the code:

#include <stdlib.h>
#include <GL/freeglut.h>
#include <stdio.h>

void init(){
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);

}
void display(){
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0,1.0,1.0);
    glBegin(GL_POLYGON);
        glVertex3f(0.25, 0.25, 0.0);
        glVertex3f(0.75,0.25,0.0);
        glVertex3f(0.75,0.75, 0.0);
        glVertex3f(0.25, 0.75, 0.0);
        glEnd();
    glFlush();
}
int main(int argc, char** argv) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(250,250);    //if I comment out this line,
    glutInitWindowPosition(100,100);
    glutCreateWindow(argv[0]);  //this line,
    init();  //this line and the glut main loop line it runs without any errors, but why wouldn't it? It not doing anything now!
    glutDisplayFunc(display);
    glutMainLoop();    //if I comment out just this line I get illegal instruction instead of segfault but I need this line
    return 0;
}

Thread [1] 28944 (Suspended: Signal: SIGSEGV: segfault)
  XF86DRIQueryVersion () in 0x7ffff7e7412e XF86DRIQueryExtension () in 0x7ffff7e742c9 0x7ffff7e73c70 0x7ffff7e53ff8 glXGetFBConfigs () on 0x7ffff7e4c71e glXChooseFBConfigSGIX () on 0x7ffff7e4cd97
  fgChooseFBConfig () on freeglut_window.c: 205 0x7ffff794a8c7
  fgOpenWindow () on freeglut_window.c: 768 0x7ffff794aac8
  fgCreateWindow () in freeglut_structure.c: 106 0x7ffff7948f62 glutCreateWindow () on freeglut_window.c: 1,183 0x7ffff794a2a2 main () on the thread [When I got an error in the IEEE erservice error code 0x7ffff7e7412e XF86DRIQueryExtension () at 0x7ffff7e742c9 0x7ffff7e73c70 0x7ffff7e53ff8 glXGetFBConfigs () at 0x7ffff7e4c71e glXChooseFBConfigSGIX () on 0xd
  fgChooseFBConfig() freeglut_window.c: 205 0x7ffff794a8c7
  fgOpenWindow() freeglut_window.c: 768 0x7ffff794aac8
  fgCreateWindow() freeglut_structure.c: 106 0x7ffff7948f62   glutCreateWindow() freeglut_window.c: 1,183 0x7ffff794a2a2 main() at ( ): 54 0x40100b

+3
4

: GLUT_DEPTH glutInitDisplayMode , (segfault at glutCreateWindow)

+3

? glxinfo. DRI , .

+2

Debian 6.0 Mac OS X 10.6. Radeon HD 5670 ( ).

, - OpenGL , , .

, , :

  • , OpenGL SIGSEGV XF86DRIQueryVersion()
  • glxinfo/glxgears SIGSEGV

, Radeon fglrx ( aptitude) "radeon". 'sudo Xorg -configure', , sudo X -config/root/xorg.conf.new xorg.conf.

SIGSEGV, :

  • glxinfo : Got Error: RGB GLX visual fbconfig
  • glxgears : : RGB, Double-buffed visual

, , , (DRI), . , 'export LIBGL_ALWAYS_INDIRECT = yes'. , DRI ( libgl1-mesa-dri).

, , fglxr glxinfo glxgears . , fglxr radeon - - .

, , :

+2

, , :

#include <stdlib.h>
#include <GL/freeglut.h>
#include <stdio.h>

int main(int argc, char** argv) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(250,250);
    glutInitWindowPosition(100,100);
    glutCreateWindow("test window");
    return 0;
}

:

fgCreateWindow() at freeglut_structure.c:106 0x7ffff7948f62 glutCreateWindow()

, (, ). , , @Matias, , 3D- ? , 32 64 - , freeglut OpenGl - . ?

+1

Source: https://habr.com/ru/post/1765731/


All Articles