View Full Version : how to change the control between two glut windows

09-11-2009, 05:25 AM
Hi all,
i have two glut windows in my project and what I want to do now is to redraw the scene in the second window when the mouse move over the first window .
note: I'm using Trackball for rotating the scene in the first window.

any help will be appreciated

09-11-2009, 07:53 AM
I found this valuable resource on many different glut examples at OpenGL API GLUT Sample Code & Tutorials (http://www.opengl.org/code/category/C19). Under one of the headings, there is a set of C examples (http://www.opengl.org/resources/code/samples/glut_examples/examples/examples.html) that are part of the GLUT distribution. The "sphere.c" example shows how to track when you have left one window and entered the other -- it prints info to the console as you move the mouse between the two windows like:

enter/leave 1 = left
enter/leave 4 = entered
enter/leave 4 = left
enter/leave 1 = entered
enter/leave 1 = left
enter/leave 4 = entered
enter/leave 4 = left
enter/leave 1 = entered

This doesn't solve your problem but may give some hints by looking at the code source "sphere.c". The use of glutEntryFunc and glutGetWindowglutSetWindow(int win) along with setting a new callback to rotate the image might be the place to start.

Another example probably closer to what you are trying to accomplish is found at Lighthouse tutorials (http:///www.lighthouse3d.com/opengl/glut/index.php?subwinrender). As you press the arrow keys, each of the three views responds and dynamically traverses the scene. The GLUT source code can be downloaded at the bottom of its page, just look for the "download" link. They are using subwindows rather than two separate windows but I think still applies to your problem.

ps I found that my GPU was too fast and when I pressed the arrow keys things moved beyond what I could see. A easy fix was to replace glutIdleFunc with a glutTimerFun as follows

// replaced with

// and
void renderSceneAll() {
//replaced with
void renderSceneAll(int value) {

//and for ANSI-C you can't use \ in includes
#include <GL\glut.h>
#include <GL\gl.h>
#include <GL\glu.h>
// replaced with
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>