Segmentation fault

Hello all.

I’ve got a new problem now. Finally I got my first OpenGL rendered white square to work, but now I’m further in the book and more difficulties come to me. I wrote the next piece of code :


#include <GL/glut.h>

void display()

{

glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_POLYGON);

glVertex2f(-0.5,-0.5);

glColor3f(0.0,0.0,0.0);

glVertex2f(-0.5,0.5);

glVertex2f(0.5,0.5);

glVertex2f(0.5,-0.5);

glEnd();

glFlush();

}

/* void init()

{

glClearColor(0.0,0.0,0.0,0.0);

glColor3f(1.0,1.0,1.0);

// glMatrixMode(GL_PROJECTION);

// glLoadIdentity();

gluOrtho2D(-1.0,1.0,-1.0,1.0);
}
*/

GLsizei w,h;

void myreshape(GLsizei w,GLsizei h)
{

/* ajust clipping box */

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

if (w <= h)

gluOrtho2D(-2.0, 2.0, -2.0 * (GLfloat) h / (GLfloat) w,2.0 * (GLfloat) h / (GLfloat) w);

else

gluOrtho2D(-2.0, 2.0, -2.0 * (GLfloat) w / (GLfloat) h,2.0 * (GLfloat) w / (GLfloat) h);

glMatrixMode(GL_MODELVIEW);

/* ajust viewport */

glViewport(0,0,w,h);

/* set global size for use by drawing routine */

// ww =w;
//

wh =h;

}

int main(int argc, char** argv)

{

glutInit(&argc,argv);

glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

glutInitWindowSize(500,500);

glutReshapeFunc(myreshape);

glutCreateWindow(“D1G1T4LL 2003”);

glutDisplayFunc(display);

glutMainLoop();

// init();

}


finally after a lot of errormessage’s and corrections, I got it to compile, without errormessages anymore. Realy happy with the new binary I just made, started X server, tried to run, But nothing happend, exept for the message : ‘Segmentation fault’
I’m trying to find out what that could mean.

It cant be a big thing if it has happened before to you, so if U know how to solve this problem, please help.

Thanks allready.

try moving the glutCreateWindow call before the glutInitWindowSize.

you should try looking at a debugger called gdb. You can use it to debug programs when they crash. To get programs to generate a core file when the crash you can type ulimit -c unlimited at the shell. You will also want to add -g to your gcc line when compiling the program. just google for gdb manual and read up on it if you have time. It’s very useful.

Thanks for the advise, Now I just found out that I should use GlutReshapeFunc after GlutDisplay func has initialized. It works now.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.