glutdisplayfunc() parameters or window reference

I want to display different matrices on screen. Therefore I create one window for each matrix, which works just fine, but now I have the problem that glutDisplayFunc() doesn’t take parameters. Currently I’m using a global variable holding the id of the matrix to use, but this works just at the first drawing, when resizeing the window the id is incorrect.

So how can I distinguish between different windows within one DisplayFunc?

I mean is there a possibilty to query the window name or id?

Can you show us your code? You’re using sub windows in GLUT?

I’m not using sub-windows. See code below.


void init_opengl_mat(int argc, char **argv)
{
	glutInit(&argc, argv); 
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); 

	
	int start_pos = 10;

	for(int i = 0; i < num_kernels+1; i++)
	{
	   glutInitWindowPosition(start_pos,start_pos); 	
		glutInitWindowSize(dim,dim);
		glutCreateWindow(kernel_names[i]); 
		glutDisplayFunc(display_mat_points);
		glClearColor(0.0, 0.0, 0.0, 0.0); 	
		glMatrixMode(GL_PROJECTION); 
		glLoadIdentity(); 
		glOrtho(0.0, dim, 0.0, dim, -10.0, 10.0); 
		start_pos+=50;
	}
	glutMainLoop(); 
}


void display_mat_points(void)
{ 
	float * mat = (float *) malloc(dim * dim * sizeof(float));

//here i need to find out in which window i'm drawing
//because window 1 shoult contain mat0 window 2 should contain mat1 and so on
	memcpy(mat,mat0,dim*dim*sizeof(float));

	GLfloat color;
	glPointSize(2);

	glBegin(GL_POINTS);
	for(int y = 0; y < dim; y++)
	{		
		for(int x = 0; x < dim; x++)
		{		
			color = (float)mat[x + dim*y]/max_val;
			glColor3f(0.0, color, 0.0);		
			glVertex2f(x, y);			
		}
	}
	glEnd(); 
	glFlush(); 
} 

Ah, well, you can start by checking the docs for glutCreateWindow, which returns an identifier int. I’ve never used multiple windows,
but according to the docs, glutGetWindow() is probably what you want.

http://www.opengl.org/documentation/specs/glut/spec3/node18.html

If that doesn’t work, you can always wrap your display function. Have display_mat_points take an integer for the the window idea and instead of passing glutDisplayFunc(display_mat_points), give it a wrapper like glutDisplayFunc(wrapDisplayMatPoints0)

where

void wrapDisplayMapPoints0(void) {
display_mat_points(0); // tells display_mat_points it is rendering is window 0
}

void wrapDisplayMapPoints1(void) {

}

etc.

But try glutGetWindow() first.

thanks a lot, it works!

glutGetWindow() is exactly what i needed.