GluUnproject and two Windows

Hi, i have the following setup:

i create two windows (glCreateWindow), each with its own mouse and keyboard handler.

Window A shows a 3D room in first person perspective.
Window B shows a topview of the 3D room.

What i want to do: Click on Window B on a position and the perspective in Window A ‘teleports’ to this new position.

I already managed to get the coordinates from Window B, using gluUnproject, it returns me x, y and height of the position i clicked.

Now i am stuck here: what to do with these x,y, and height values? I read something about translation and rotation etc. but do not know how to do it. I thought that i just need to position the camera in window A to the new position which was returned by gluUnproject in Window B.

Am i missing something? Anyone can give me a hint?


That sounds right assuming everything is setup correctly. gluUnproject should give you the world coordinate and just move your camera to that position.

How are you stuck now? Is the camera not moving? Does it take you to some other place that where you clicked?

Thanks for the quick answer, i was unsure wether my idea is right. I thought maybe there is some other way. I’ll try it out.

hi, now i am stuck with my problem.

i have the following in the mouse handler for the window B:

void mouse_handler_topview(int button, int s, int x, int y)
GLint viewport[4];
GLdouble modelview[16],projection[16];
GLfloat wx=x,wy,wz;


fprintf(stdout,"X:%.2f Y:%.2f H:%.2f

//position camera in window A to new position ox,oz,oy


now ox, oz and oy give me for my case the world coordinates.
now i am stuck with the problem of positioning the camera in window A to the new position ox,oz and oy. i tried using
gluSetWindow and glutDisplayFunc(display_window_A) but it does not work. glutDisplayFunc only gives me the perspective of window A in window B.

What functions do i have to use in order to position the camera in window A?

Anyone can give me hint?


After testing different ways, i found a pretty simple one which is quite convenient for solving my problem.

Solution in short:

  1. When getting the real world values i just write them into a txt file.
  2. I check for the first window whether the txt file exists, if it exists place the camera position to the new position read from the txt file and then delete the file afterwards. If the txt file is not found, then nothing happens and the normal behavior is being used.

Simple solution and for now it fits the requirements.