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);
glutInitWindowPosition(100,100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutMainLoop();
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