Segmentation fault

I understand what you means already…Because my code was combine of CPU and GPU process.I use int main() initially. I thought no ned to initialize glut even though I want to use GPU to process. Here is the changes:


void glutInit(int *argcp, char **argv){
		glewInit();
		glGenBuffersARB(1, &pattern_buffer);	
		glBindBufferARB(GL_ARRAY_BUFFER_ARB, pattern_buffer);	
		glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(pattern), pattern, GL_READ_WRITE_ARB);
}

I add glutInit inside the main(). No more segmentation fault error message. Is this correct? If it is I am going to continue the next part.

Since you didn’t init glut, you’ve had no context when glew initialized, hence the crash.

While you move to the next part, try to delete the ARB suffixes and compile again and see if your app still works (it is better to leave them, for Windows compiles, I’m just suggesting an experiment, it should work).

No this is wrong.
Usually its like this.


void main(int argc, char** argv) {
  glutInit(&argc, argv);
  glutInitWindowSize(800, 600);
  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
  glutCreateWindow("Some title here");

  GLenum err = glewInit();
  if (GLEW_OK != err)
  {
     fprintf(stderr, "Error: %s
", glewGetErrorString(err));
     exit(EXIT_FAILURE);
  }

  ... rest of stuff like attaching callbacks and setup stuff for opengl.

 glutMainLoop();
}

NOTE: I told u earlier but u never heeded to it (see the first page of this thread

Have u initialized the glew library by calling
glewInit() after initializing glut library?

Since you didn’t init glut, you’ve had no context when glew initialized, hence the crash.

While you move to the next part, try to delete the ARB suffixes and compile again and see if your app still works (it is better to leave them, for Windows compiles, I’m just suggesting an experiment, it should work).

What is that ARB suffixes for actually?I compile using linux not windows.

NOTE: I told u earlier but u never heeded to it (see the first page of this thread
Quote:

Have u initialized the glew library by calling
glewInit() after initializing glut library?

Lol…Sorry about that…I miss that part. But very strange…If i follow your code, the problem happens again. I am not going to create a new window for display the drawing. As what I am trying to do is simple calculation. But not drawing.

You need a window to have an OpenGL context. There are tricks you can do (like creating a hidden window) but GLUT isn’t going to be flexible enough. It’s easier to just create a Window.

The -ARB suffixes were used by earlier versions of OpenGL where VBOs were an extension rather than part of the core. The reason why you’d use them is if you need compatibility with older hardware (no, Windows doesn’t need them and can use the versions of the functions without them so long as the driver exports the entry points; this is nothing to do with Windows, it’s the driver). Otherwise you don’t need to use them.

I suddenly found that I need to create a window to check my result. By the way, I follow exactly your code. Why the terminal just like waiting for something but no display comes out?


	glutInit(&argc, argv);
  	glutInitWindowSize(800, 600);
  	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
  	glutCreateWindow("GPU display");

	GLenum err = glewInit();
  	if (GLEW_OK != err)
  	{
    	 	fprintf(stderr, "Error: %s
", glewGetErrorString(err));
    		exit(EXIT_FAILURE);
  	}

	glGenBuffersARB(1, &pattern_buffer);	
	glBindBufferARB(GL_ARRAY_BUFFER_ARB, pattern_buffer);	
	glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(pattern), pattern, GL_READ_WRITE_ARB);

	int *ptr;
	ptr = glMapBufferRange(pattern_buffer, pattern[0], 1, GL_MAP_READ_BIT);
	printf("Ptr: ",ptr);

Is it necessary that I need glutMainLoop()? I found that if I include this, my program hang there when running. But if not include that, seems like no window pop out also even though the program run smoothly.

Where’s your rendering function? Anyway, you are all set, go over to NeHe and do some tuts and yes you need to call glutMainLoop(), if you want to render something.

You need to glutMainLoop to handle events such as display, resize, input, …

You can do the initialisation of GL stuff before calling it, as hinted by mobeen.

Ok…Have to study deeper…Thanks for the help… :smiley: