Exemplo n.º 1
0
//fullscreen GameMode creates a new GL context
//currently requires re-registering event callbacks and re-loading texture maps
//------------------------------------------------------------------------------
void npglFullscreen (void* dataRef)
{
	int deltaX = 0, deltaY = 0;
	int result = 0;		//fullscreen window used only if gamemode fails

	pData data = (pData) dataRef;
	pNPgl gl = &data->io.gl;

	if (gl->fullscreen)
	{
		if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE) != 0)		//stereo 3D
		{
			glutLeaveGameMode();
			glutSetWindow (gl->windowID);
            glutShowWindow ();

			//! register keyboard, mouse and display events with GLUT
			npGlutEventFuncs();
			
			npInitGL (data);
		}
	
		//exit fullscreen and restore previous window position
		gl->fullscreen = false;

		glutReshapeWindow (gl->windowSize.x, gl->windowSize.y);
		glutPositionWindow (gl->position.x, gl->position.y);

		//correct for window border offset, glut workaround
		deltaX = gl->position.x - glutGet((GLenum)GLUT_WINDOW_X);
		deltaY = gl->position.y - glutGet((GLenum)GLUT_WINDOW_Y);
		if (deltaX != 0 || deltaY != 0)
			glutPositionWindow (gl->position.x + deltaX,
								gl->position.y + deltaY);
	
		npPostMsg("Exit FullScreen", kNPmsgGL, data);
	}
	else
	{
/*		glutSetWindow (	gl->windowID);
		glutHideWindow ();

		//Game Mode with stereo 3D
		if (gl->stereo3D)
			glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STEREO); // stereo display mode for glut
		else
			glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);

		//stereo 3D and GameMode
		printf("Attempting Game Mode, please ignore GLUT warnings\n");
		glutGameModeString("1920x1080:32@121");
		if ( glutEnterGameMode() == 0 )
		{
			glutGameModeString("1920x1080:32@120");
			if ( glutEnterGameMode() == 0 )
			{
				glutGameModeString("1920x1080:32@119");
				if ( glutEnterGameMode() == 0 )
				{
					glutGameModeString("1920x1080:32@60"); //does not specify refresh
					result = ( glutEnterGameMode() );
		}}}
*/
		gl->position.x = glutGet((GLenum)GLUT_WINDOW_X);
		gl->position.y = glutGet((GLenum)GLUT_WINDOW_Y);

		gl->windowSize.x = gl->width;
		gl->windowSize.y = gl->height;

		if (result == 0)	//fullscreen window used only if gamemode fails
		{
			printf("FullScreen Window\n");
			glutShowWindow ();
			glutFullScreen ();
		}
		else
		{	//GameMode may be different then what we requested, so get the modes
			glutSetWindowTitle("ANTz - GameMode");

			gl->width = glutGameModeGet( GLUT_GAME_MODE_WIDTH );
			gl->height = glutGameModeGet( GLUT_GAME_MODE_HEIGHT );
			gl->pixelDepth = glutGameModeGet( GLUT_GAME_MODE_PIXEL_DEPTH );
			gl->refreshRate = (float)glutGameModeGet( GLUT_GAME_MODE_REFRESH_RATE );
			printf("FullScreen Game Mode: %dx%d:%d@%d\n", gl->width, gl->height,
							gl->pixelDepth, (int)gl->refreshRate);
		}

		gl->fullscreen = true;
	}
}
Exemplo n.º 2
0
void onKeyboard(unsigned char key, int x, int y) {
	char *name = malloc(20 * sizeof(char));
	int i = 0;
	switch (key) {
		case 27: // Escape
			printf("INFO: exit\n");
			printf("x %d, y %d\n", x, y);
			exit(0);
			break;
		case 'x':
			xx += 1.0;
			printf("INFO: x = %f\n", xx);
			break;
		case 'X':
			xx -= 1.0;
			printf("INFO: x = %f\n", xx);
			break;
		case 'y':
			yy += 1.0;
			printf("INFO: y = %f\n", yy);
			break;
		case 'Y':
			yy -= 1.0;
			printf("INFO: y = %f\n", yy);
			break;
		case 'f':
			fullScreen = !fullScreen;
			if (fullScreen) {
				glutFullScreen();
			} else {
				glutReshapeWindow(winSizeW, winSizeH);
				glutPositionWindow(100,100);
				printf("INFO: fullscreen %d\n", fullScreen);
			}
			break;
		case 'd':
			axe = !axe;
			printf("INFO: axe = %d\n", axe);
			break;
		case 'r':
			rotate = !rotate;
			printf("INFO: rotate %d\n", rotate);
			break;
		case 't':
			trace = !trace;
			printf("INFO: trace = %d\n", trace);
			break;
		case 'a':
			allTraces = !allTraces;
			for (i=0; i<sampleSize; i++) {
				planetsList[i].displayed = !allTraces;
			}
			printf("INFO: all traces = %d\n", allTraces);
			break;
		case 'z':
			zoom -= 5.0;
			if (zoom < 5.0) {
				zoom = 5.0;
			}
			printf("INFO: zoom = %f\n", zoom);
			break;
		case 'Z':
			zoom += 5.0;
			printf("INFO: zoom = %f\n", zoom);
			break;
		case 'p':
			printf("INFO: take a screenshot\n");
			sprintf(name, "capture_%.3d.png", cpt);
			takeScreenshot(name);
			cpt += 1;
			break;
		default:
			break;
	}
	free(name);
	glutPostRedisplay();
}
Exemplo n.º 3
0
//------------------------------------------------------------
void ofAppGlutWindow::display(void){
	static ofEventArgs voidEventArgs;

	//--------------------------------
	// when I had "glutFullScreen()"
	// in the initOpenGl, I was gettings a "heap" allocation error
	// when debugging via visual studio.  putting it here, changes that.
	// maybe it's voodoo, or I am getting rid of the problem
	// by removing something unrelated, but everything seems
	// to work if I put fullscreen on the first frame of display.

	if (windowMode != OF_GAME_MODE){
		if ( bNewScreenMode ){
			if( windowMode == OF_FULLSCREEN){

				//----------------------------------------------------
				// before we go fullscreen, take a snapshot of where we are:
				nonFullScreenX = glutGet(GLUT_WINDOW_X);
				nonFullScreenY = glutGet(GLUT_WINDOW_Y);
				//----------------------------------------------------

				glutFullScreen();

				#ifdef TARGET_OSX
					SetSystemUIMode(kUIModeAllHidden,NULL);
				#endif

			}else if( windowMode == OF_WINDOW ){

				glutReshapeWindow(requestedWidth, requestedHeight);

				//----------------------------------------------------
				// if we have recorded the screen posion, put it there
				// if not, better to let the system do it (and put it where it wants)
				if (nFrameCount > 0){
					glutPositionWindow(nonFullScreenX,nonFullScreenY);
				}
				//----------------------------------------------------

				#ifdef TARGET_OSX
					SetSystemUIMode(kUIModeNormal,NULL);
				#endif
			}
			bNewScreenMode = false;
		}
	}

	int width, height;

	width  = ofGetWidth();
	height = ofGetHeight();

	height = height > 0 ? height : 1;
	// set viewport, clear the screen
	glViewport( 0, 0, width, height );
	float * bgPtr = ofBgColorPtr();
	bool bClearAuto = ofbClearBg();

    // to do non auto clear on PC for now - we do something like "single" buffering --
    // it's not that pretty but it work for the most part

    #ifdef TARGET_WIN32
    if (bClearAuto == false){
        glDrawBuffer (GL_FRONT);
    }
    #endif

	if ( bClearAuto == true || nFrameCount < 3){
		glClearColor(bgPtr[0],bgPtr[1],bgPtr[2], bgPtr[3]);
		glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	}

	if( bEnableSetupScreen )ofSetupScreen();

	ofNotifyDraw();

    #ifdef TARGET_WIN32
    if (bClearAuto == false){
        // on a PC resizing a window with this method of accumulation (essentially single buffering)
        // is BAD, so we clear on resize events.
        if (nFramesSinceWindowResized < 3){
            glClearColor(bgPtr[0],bgPtr[1],bgPtr[2], bgPtr[3]);
            glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        } else {
            if (nFrameCount < 3 || nFramesSinceWindowResized < 3)    glutSwapBuffers();
            else                                                     glFlush();
        }
    } else {
        glutSwapBuffers();
    }
    #else
		if (bClearAuto == false){
			// in accum mode resizing a window is BAD, so we clear on resize events.
			if (nFramesSinceWindowResized < 3){
				glClearColor(bgPtr[0],bgPtr[1],bgPtr[2], bgPtr[3]);
				glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
			}
		}
        glutSwapBuffers();
    #endif

    nFramesSinceWindowResized++;

	//fps calculation moved to idle_cb as we were having fps speedups when heavy drawing was occuring
	//wasn't reflecting on the actual app fps which was in reality slower. 
	//could be caused by some sort of deferred drawing? 

	nFrameCount++;		// increase the overall frame count

	//setFrameNum(nFrameCount); // get this info to ofUtils for people to access

}
Exemplo n.º 4
0
void keyboard(unsigned char key, int x, int y) {
	// Toggle full screen display.
	if ((key == GLUT_KEY_ENTER) && (glutGetModifiers() == GLUT_ACTIVE_ALT)) {
		static int wnd_x, wnd_y, wnd_width, wnd_height;

		if (wnd_full_screen ^= true) {
			wnd_x = glutGet(GLUT_WINDOW_X);
			wnd_y = glutGet(GLUT_WINDOW_Y);
			wnd_width = glutGet(GLUT_WINDOW_WIDTH);
			wnd_height = glutGet(GLUT_WINDOW_HEIGHT);
			glutFullScreen();
		} else {
			glutReshapeWindow(wnd_width, wnd_height);
			glutPositionWindow(wnd_x, wnd_y);
		}
	}

	// Exit the application when "Esc" is pressed.
	if (key == GLUT_KEY_ESCAPE)
		exit(EXIT_SUCCESS);

	// Toggle rendering pause.
	if (key == 'p') {
		render_pause ^= true;
		glutPostRedisplay();
	}

	// Set the buffer to read the pixels from.
	if (key == 'n') {
		format = 0;
		show_buffer = false;
		glutPostRedisplay();
	}

	if (key == 'c') {
		format = GL_LUMINANCE;
		show_buffer = true;
		glutPostRedisplay();
	}

	if (key == 'd') {
		format = GL_DEPTH_COMPONENT;
		show_buffer = true;
		glutPostRedisplay();
	}

	if (key == 's') {
		format = GL_STENCIL_INDEX;
		show_buffer = true;
		glutPostRedisplay();
	}

	// Toggle buffer display.
	if (key == 'b') {
		show_buffer ^= true;
		glutPostRedisplay();
	}

	// Toggle pixel transfer operations.
	if (key == 't') {
		trans_op ^= true;
		glutPostRedisplay();
	}
}
Exemplo n.º 5
0
void glutGUI::setWindowPosition(const int x, const int y)
{
  glutPositionWindow(x, y);
}
Exemplo n.º 6
0
void WindowsManager::setFullScreen(bool enable)
{
	m_fullScreen = enable;

	if(m_fullScreen)
	{
		if(m_subWindow)
		{
			getDesktopResolution();	
			if(m_window2Rect.bottom==-1)//one screen available
			{
				glutFullScreen();
			}
			else
			{
				//Fullscreen in subwindow mode required the same resolution on both screen 
				//and the second screen has to been on the right of the first screen
				glutPositionWindow(m_window1Rect.left-IntialMargin/2,m_window1Rect.top-30); 
				glutReshapeWindow(m_window2Rect.right-m_window1Rect.left,m_window1Rect.bottom - m_window1Rect.top);
			}	
		}
		else
		{
			getDesktopResolution();	

			if(m_window2Rect.bottom==-1)//one screen available
			{
				setCurrentWindow(0);
				glutPositionWindow(m_window1Rect.left,m_window1Rect.top); 
				glutReshapeWindow((m_window1Rect.right- m_window1Rect.left)/2-IntialMargin,m_window1Rect.bottom - m_window1Rect.top-IntialMargin);

				setCurrentWindow(1);
				glutPositionWindow((m_window1Rect.right- m_window1Rect.left)/2,m_window1Rect.top); 
				glutReshapeWindow((m_window1Rect.right - m_window1Rect.left)/2-IntialMargin,m_window1Rect.bottom - m_window1Rect.top-IntialMargin);
			}
			else //two screens
			{
				setCurrentWindow(0);
				glutPositionWindow(m_window1Rect.left,m_window1Rect.top); 
				glutReshapeWindow(m_window1Rect.right - m_window1Rect.left-IntialMargin,m_window1Rect.bottom - m_window1Rect.top-IntialMargin);

				setCurrentWindow(1);
				glutPositionWindow(m_window2Rect.left,m_window2Rect.top); 
				glutReshapeWindow(m_window2Rect.right - m_window2Rect.left-IntialMargin,m_window2Rect.bottom - m_window2Rect.top-IntialMargin);
			}
		}
	}
	else
	{
		if(m_subWindow)
		{
			setCurrentWindow(0);
			glutPositionWindow(IntialPosition,IntialPosition); 
			glutReshapeWindow(IntialSize*2,IntialSize);

		}
		else
		{
			setCurrentWindow(0);
			glutPositionWindow(IntialPosition,IntialPosition); 
			glutReshapeWindow(IntialSize,IntialSize);
			
			setCurrentWindow(1);
			glutPositionWindow(IntialPosition+IntialSize+IntialMargin,IntialPosition); 
			glutReshapeWindow(IntialSize,IntialSize);
		}
	}
}
Exemplo n.º 7
0
/*
 * Private function to check for the current menu/sub menu activity state
 */
static GLboolean fghCheckMenuStatus( SFG_Menu* menu )
{
    SFG_MenuEntry* menuEntry;
    int x, y;

    /* First of all check any of the active sub menus... */
    for( menuEntry = (SFG_MenuEntry *)menu->Entries.First;
            menuEntry;
            menuEntry = (SFG_MenuEntry *)menuEntry->Node.Next )
    {
        if( menuEntry->SubMenu && menuEntry->IsActive )
        {
            /*
             * OK, have the sub-menu checked, too. If it returns GL_TRUE, it
             * will mean that it caught the mouse cursor and we do not need
             * to regenerate the activity list, and so our parents do...
             */
            GLboolean return_status;

            menuEntry->SubMenu->Window->State.MouseX =
                menu->Window->State.MouseX + menu->X - menuEntry->SubMenu->X;
            menuEntry->SubMenu->Window->State.MouseY =
                menu->Window->State.MouseY + menu->Y - menuEntry->SubMenu->Y;
            return_status = fghCheckMenuStatus( menuEntry->SubMenu );

            if ( return_status )
                return GL_TRUE;
        }
    }

    /* That much about our sub menus, let's get to checking the current menu: */
    x = menu->Window->State.MouseX;
    y = menu->Window->State.MouseY;

    /* Check if the mouse cursor is contained within the current menu box */
    if( ( x >= FREEGLUT_MENU_BORDER ) &&
            ( x < menu->Width  - FREEGLUT_MENU_BORDER ) &&
            ( y >= FREEGLUT_MENU_BORDER ) &&
            ( y < menu->Height - FREEGLUT_MENU_BORDER )  )
    {
        int menuID = ( y - FREEGLUT_MENU_BORDER ) / FREEGLUT_MENUENTRY_HEIGHT(menu->Font);

        /* The mouse cursor is somewhere over our box, check it out. */
        menuEntry = fghFindMenuEntry( menu, menuID + 1 );
        FREEGLUT_INTERNAL_ERROR_EXIT( menuEntry, "Cannot find menu entry",
                                      "fghCheckMenuStatus" );

        menuEntry->IsActive = GL_TRUE;
        menuEntry->Ordinal = menuID;

        /*
         * If this is not the same as the last active menu entry, deactivate
         * the previous entry.  Specifically, if the previous active entry
         * was a submenu then deactivate it.
         */
        if( menu->ActiveEntry && ( menuEntry != menu->ActiveEntry ) )
            if( menu->ActiveEntry->SubMenu )
                fghDeactivateSubMenu( menu->ActiveEntry );

        if( menuEntry != menu->ActiveEntry )
        {
            menu->Window->State.WorkMask |= GLUT_DISPLAY_WORK;
            if( menu->ActiveEntry )
                menu->ActiveEntry->IsActive = GL_FALSE;
        }

        menu->ActiveEntry = menuEntry;
        menu->IsActive = GL_TRUE;

        /*
         * OK, we have marked that entry as active, but it would be also
         * nice to have its contents updated, in case it's a sub menu.
         * Also, ignore the return value of the check function:
         */
        if( menuEntry->SubMenu )
        {
            if ( ! menuEntry->SubMenu->IsActive )
            {
                int max_x, max_y;
                SFG_Window *current_window = fgStructure.CurrentWindow;

                /* Set up the initial menu position now... */
                menuEntry->SubMenu->IsActive = GL_TRUE;

                /* Set up the initial submenu position now: */
                fghGetVMaxExtent(menu->ParentWindow, &max_x, &max_y);
                menuEntry->SubMenu->X = menu->X + menu->Width;
                menuEntry->SubMenu->Y = menu->Y +
                                        menuEntry->Ordinal * FREEGLUT_MENUENTRY_HEIGHT(menu->Font);

                if( menuEntry->SubMenu->X + menuEntry->SubMenu->Width > max_x )
                    menuEntry->SubMenu->X = menu->X - menuEntry->SubMenu->Width;

                if( menuEntry->SubMenu->Y + menuEntry->SubMenu->Height > max_y )
                {
                    menuEntry->SubMenu->Y -= ( menuEntry->SubMenu->Height -
                                               FREEGLUT_MENUENTRY_HEIGHT(menu->Font) -
                                               2 * FREEGLUT_MENU_BORDER );
                    if( menuEntry->SubMenu->Y < 0 )
                        menuEntry->SubMenu->Y = 0;
                }

                fgSetWindow( menuEntry->SubMenu->Window );
                glutPositionWindow( menuEntry->SubMenu->X,
                                    menuEntry->SubMenu->Y );
                glutReshapeWindow( menuEntry->SubMenu->Width,
                                   menuEntry->SubMenu->Height );
                glutPopWindow( );
                glutShowWindow( );
                menuEntry->SubMenu->Window->ActiveMenu = menuEntry->SubMenu;
                fgSetWindow( current_window );
                menuEntry->SubMenu->Window->State.MouseX =
                    x + menu->X - menuEntry->SubMenu->X;
                menuEntry->SubMenu->Window->State.MouseY =
                    y + menu->Y - menuEntry->SubMenu->Y;
                fghCheckMenuStatus( menuEntry->SubMenu );
            }

            /* Activate it because its parent entry is active */
            menuEntry->SubMenu->IsActive = GL_TRUE;
        }

        /* Report back that we have caught the menu cursor */
        return GL_TRUE;
    }

    /* Looks like the menu cursor is somewhere else... */
    if( menu->ActiveEntry && menu->ActiveEntry->IsActive &&
            ( !menu->ActiveEntry->SubMenu ||
              !menu->ActiveEntry->SubMenu->IsActive ) )
    {
        menu->Window->State.WorkMask |= GLUT_DISPLAY_WORK;
        menu->ActiveEntry->IsActive = GL_FALSE;
        menu->ActiveEntry = NULL;
    }

    return GL_FALSE;
}
Exemplo n.º 8
0
void GlutWindow::setY(GLint x)
{
    this->y = y;
    executeAsCurrentWindow([&](){ glutPositionWindow(x, y); });
}
Exemplo n.º 9
0
void onSpecKeyDown(int key, int x, int y) {
	switch (key) {
		case GLUT_KEY_F1: {
			g_fullScreen = !g_fullScreen;
			if (g_fullScreen) {
				g_width = glutGet(GLUT_WINDOW_WIDTH); g_height = glutGet(GLUT_WINDOW_HEIGHT);
				g_posX = glutGet(GLUT_WINDOW_X); g_posY = glutGet(GLUT_WINDOW_Y);
				glutFullScreen();
			}
			else {
				glutReshapeWindow(g_width,g_height);
				glutPositionWindow(g_posX, g_posY);
			}
			glutPostRedisplay();
			break;

						  }
			case GLUT_KEY_UP: {
			X++;

			glutPostRedisplay();
			break;}

			case GLUT_KEY_DOWN: {
			X--;

			glutPostRedisplay();
			break;}

			case GLUT_KEY_LEFT: {
			Z++;

			glutPostRedisplay();
			break;}

			case GLUT_KEY_RIGHT: {
			Z--;
			glutPostRedisplay();
			break;
								 }

			case GLUT_KEY_PAGE_UP: {
			Y++;
			glutPostRedisplay();
			break;	}

			case GLUT_KEY_PAGE_DOWN: {
			Y--;
			glutPostRedisplay();
			break;
								 }
			case GLUT_KEY_HOME: {
			speed=speed+0.5;
			glutPostRedisplay();
			break;
								 }
			case GLUT_KEY_END: {
			speed=speed-0.5;
			glutPostRedisplay();
			break;
								 }
				  }

}
Exemplo n.º 10
0
int main(int argc, char** argv) 
{
		g_filename=argv[1];


//	testTriangulation();
//downsampling();

//	float error=0.005;
//printf("value=%f\n",-error*log2(error)-(1-error)*log2(1-error)+error*log2(359));
//getchar();

readPatches_region();


	VECTOR3 minB, maxB; 

	osuflow = new OSUFlowEntropy(); 
	//printf("read file %s\n", argv[1]); 
//	g_filename=argv[1];
	osuflow->LoadData((const char*)argv[1], true);//, minB, maxB); //true: a steady flow field 

	osuflow->Boundary(minLen, maxLen); // get the boundary 
	minB[0] = minLen[0]; minB[1] = minLen[1];  minB[2] = minLen[2];
	maxB[0] = maxLen[0]; maxB[1] = maxLen[1];  maxB[2] = maxLen[2];
	osuflow->SetBoundary(minB, maxB);  // set the boundary. just to test
	// the subsetting feature of OSUFlow
	printf(" volume boundary X: [%f %f] Y: [%f %f] Z: [%f %f]\n", 
		minLen[0], maxLen[0], minLen[1], maxLen[1], 
		minLen[2], maxLen[2]); 

	center[0] = (minLen[0]+maxLen[0])/2.0; 
	center[1] = (minLen[1]+maxLen[1])/2.0; 
	center[2] = (minLen[2]+maxLen[2])/2.0; 
	printf("center is at %f %f %f \n", center[0], center[1], center[2]); 
	len[0] = maxLen[0]-minLen[0]; 
	len[1] = maxLen[1]-minLen[1]; 
	len[2] = maxLen[2]-minLen[2]; 

	int xdim,ydim,zdim;
	osuflow->GetFlowField()->getDimension(xdim,ydim,zdim);
	//	reseeding(xdim, ydim,"Time00_fake_3D.vec.data", "Time02_fake_3D.vec.data","seed1.data","seed2.data");

	glutInit(&argc, argv); 
	glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH); 
	glutInitWindowSize(winWidth,winHeight); 

	glutCreateWindow("Display streamlines"); 
	glutPositionWindow(700,50);
	glutDisplayFunc(display); 
	//  glutIdleFunc(idle); 
	glutTimerFunc(10, timer, 0); 
	glutMouseFunc(mymouse); 
	glutMotionFunc(mymotion);
	glutKeyboardFunc(mykey); 
	//SetShaders();

	#if	ENTER_GLUT_LOOP	
	glutMainLoop();

	#else
	compute_streamlines();
	#endif
	return 0;
}
Exemplo n.º 11
0
int main(int argc, char *argv[])
{
	printf("Debut initialisation\n");
    /// Chargement des objets
	//on ne stocke plus dans des mesh, mais dans un tableau possible de mesh à charger. L'id du meche à charger par le patron correspond
	//à l'indice dans le tableau de mesh
	mesh.push_back(new MeshObj("Others\\legoTexture.obj",NULL));
	mesh.push_back(new MeshObj("Others\\brique_lego.obj", NULL));

	printf("Chargement des objets réussi\n");
    /// Initialisation de glut
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

    glClearColor(0, 0, 0, 0);
    glEnable(GL_CULL_FACE);
    glCullFace(GL_BACK);

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    glShadeModel(GL_SMOOTH);

    /// Initialisation d'ARToolKit et de la fenetre + appel boucle infini
    arInit();
    arVideoCapStart();
    glutPositionWindow((glutGet(GLUT_SCREEN_WIDTH)-cparam.xsize)/2, (glutGet(GLUT_SCREEN_HEIGHT)-cparam.ysize)/2);
    glutReshapeFunc(resize);
    glutMotionFunc(mouseMove);

	//init du menu d'aide (aide mouvement)
	menu.addBoutton("img\\delete.png",true,0,cparam.ysize-75,75,cparam.ysize);
	menu.addBoutton("img\\move.png",true,75,cparam.ysize-75,150,cparam.ysize);
	menu.addBoutton("img\\resize.png",true,150,cparam.ysize-75,225,cparam.ysize);

	//init bouttons help/scan

	//quit
	quit.addBoutton("img\\quit.png",true,cparam.xsize-120,30,cparam.xsize-16,54+30,true);
	quit.addBoutton("img\\quit1.png",true,cparam.xsize-120,30,cparam.xsize-16,54+30,false);
	difQuit=differ(2000);

	//help; 
	help.addBoutton("img\\aide1.png",true, cparam.xsize-120,54+35,cparam.xsize-16,54+54+35,true);
	help.addBoutton("img\\aide2.png",true, cparam.xsize-120,54+35,cparam.xsize-16,54+54+35,false); //activé
	help.addBoutton("img\\aide3.png",true, cparam.xsize-120,54+35,cparam.xsize-16,54+54+35,false); //selectioné
	difAide=differ(2000); 
	menuShow=false;

	//scan
	scan.addBoutton("img\\scan5.png",true,cparam.xsize-120,54+40+54,cparam.xsize-16,54+54+54+40,true);
	scan.addBoutton("img\\scan6.png",true,cparam.xsize-120,54+40+54,cparam.xsize-16,54+54+54+40,false);
	scan.addBoutton("img\\scan7.png",true,cparam.xsize-120,54+40+54,cparam.xsize-16,54+54+54+40,false);
	difScan=differ(2000);

	/*FMOD_System_Create(&systemSon);
	FMOD_System_Init(systemSon, 2, FMOD_INIT_NORMAL, NULL);
	if(!FMOD_System_CreateSound(systemSon, "Data\\mouseclickDown.wav", FMOD_CREATESAMPLE, 0, &clickDown)) printf("chargement son: ok\n");
	else printf("chargement son: echec\n");
	if(!FMOD_System_CreateSound(systemSon, "Data\\mouseclickUp.wav", FMOD_CREATESAMPLE, 0, &clickUP)) printf("chargement son: ok\n");
	else printf("chargement son: echec\n");*/

	 difIndex=differ(2000);
	 difMajeur=differ(2000);

	printf("Fin initialisation\n");

	argMainLoop(mouseClick, key, mainLoop);
 

    return EXIT_SUCCESS;
}
Exemplo n.º 12
0
/***************************************************
** deal with key strokes                          **
***************************************************/
void special_keys(int key, int x, int y)
{
  switch ( key )
    {
    default:
      break;
	case GLUT_KEY_LEFT:
		moveOthersX -= 0.2;
		needToRerenderCaustics = 1;
		glutPostRedisplay();
		break;
	case GLUT_KEY_RIGHT:
		moveOthersX += 0.2;
		needToRerenderCaustics = 1;
		glutPostRedisplay();
		break;
	case GLUT_KEY_UP:
		moveOthersY += 0.2;
		needToRerenderCaustics = 1;
		glutPostRedisplay();
		break;
	case GLUT_KEY_DOWN:
		moveOthersY -= 0.2;
		needToRerenderCaustics = 1;
		glutPostRedisplay();
		break;

	case GLUT_KEY_F5:
		drawRefractionOnly = !drawRefractionOnly;
		break;

	case GLUT_KEY_F8:
		if (lookAtZ == 0)
			lookAtZ = -3;
		else
			lookAtZ=0;
		/* compute the new, updated gluLookAt() matrix for the eye */
		glMatrixMode( GL_MODELVIEW );
		glPushMatrix();
		glLoadIdentity();
		gluLookAt(lookFrom[EYE_POV][0], lookFrom[EYE_POV][1], lookFrom[EYE_POV][2],
	  				    0, 0, lookAtZ,  
						0,1,0);
		glGetDoublev( GL_MODELVIEW_MATRIX, lookAtMatrix[EYE_POV] );
		matInvertd( lookAtMatrix[EYE_POV], inverseLookAtMatrix[EYE_POV] );
		glPopMatrix();
		glutPostRedisplay();
		break;

	case GLUT_KEY_F11:
		{
			char buf[128];
			sprintf( buf, "myMovie%d.avi", movieNum );
			printf("    (-) Starting video capture to '%s'\n", buf);
			makeMovie->StartCapture( buf, min(30, (int)((2*fps)+0.5)) );
			makingMovie = 1;
			movieNum++;
		}
		break;	
	case GLUT_KEY_F12:
		printf("    (-) Done capturing video...\n");
		makingMovie = 0;
		makeMovie->EndCapture();
		break;
	

	case GLUT_KEY_PAGE_UP:
		{
			int xPos = glutGet( GLUT_WINDOW_X );
			int yPos = glutGet( GLUT_WINDOW_Y );
			glutPositionWindow( xPos, yPos-10 );
		}
		break;

	case GLUT_KEY_PAGE_DOWN:
		{
			int xPos = glutGet( GLUT_WINDOW_X );
			int yPos = glutGet( GLUT_WINDOW_Y );
			glutPositionWindow( xPos, yPos+10 );
		}
		break;

	 case GLUT_KEY_END:
		{
			screenShot=1;
			printf("    (-) Capturing screen...\n");
			glutPostRedisplay();
		}
		break;
	}
}
Exemplo n.º 13
0
// GLUT key event handler
//*****************************************************************************
void KeyboardGL(unsigned char key, int /*x*/, int /*y*/)
{
    switch (key) 
    {
        case ' ': // space toggle computation flag on/off
            bPause = !bPause;
            shrLog("\nSim %s...\n\n", bPause ? "Paused" : "Running");
            break;
        case '`':   // Tilda toggles slider display
            bShowSliders = !bShowSliders;
            shrLog("\nSlider Display %s...\n\n", bShowSliders ? "ON" : "OFF");
            break;
        case 'p':   // 'p' falls through to 'P' 
        case 'P':   // p switched between points and blobs 
            displayMode = (ParticleRenderer::DisplayMode)((displayMode + 1) % ParticleRenderer::PARTICLE_NUM_MODES);
            break;
        case 'c':   // 'c' falls through to 'C'
        case 'C':   // c switches between cycle demo mode and fixed demo mode
            bTour = bTour ? shrFALSE : shrTRUE;
            shrLog("\nTour Mode %s...\n\n", bTour ? "ON" : "OFF");
            break;
        case '[':
            activeDemo = (activeDemo == 0) ? numDemos - 1 : (activeDemo - 1) % numDemos;
            SelectDemo(activeDemo);
            break;
        case ']':
            activeDemo = (activeDemo + 1) % numDemos;
            SelectDemo(activeDemo);
            break;
        case 'd':   // 'd' falls through to 'D'
        case 'D':   // d toggled main graphics display on/off
            displayEnabled = !displayEnabled;
            shrLog("\nMain Graphics Display %s...\n\n", displayEnabled ? "ON" : "OFF");
            break;
        case 'f':   // 'f' falls through to 'F'
        case 'F':   // f toggles main graphics display full screen
            bFullScreen = !bFullScreen;
            if (bFullScreen)
            {
                iGraphicsWinPosX = glutGet(GLUT_WINDOW_X) - 8;
                iGraphicsWinPosY = glutGet(GLUT_WINDOW_Y) - 30;
                iGraphicsWinWidth  = min(glutGet(GLUT_WINDOW_WIDTH) , glutGet(GLUT_SCREEN_WIDTH) - 2*iGraphicsWinPosX ); 
                iGraphicsWinHeight = min(glutGet(GLUT_WINDOW_HEIGHT), glutGet(GLUT_SCREEN_HEIGHT)- 2*iGraphicsWinPosY ); 
                printf("(x,y)=(%d,%d), (w,h)=(%d,%d)\n", iGraphicsWinPosX, iGraphicsWinPosY, iGraphicsWinWidth, iGraphicsWinHeight);
                glutFullScreen();
            }
            else
            {
                glutPositionWindow(iGraphicsWinPosX, iGraphicsWinPosY);
	            glutReshapeWindow(iGraphicsWinWidth, iGraphicsWinHeight);
            }
            shrLog("\nMain Graphics %s...\n\n", bFullScreen ? "FullScreen" : "Windowed");
            break;
        case 'o':   // 'o' falls through to 'O'
        case 'O':   // 'O' prints Nbody sim physical parameters
            activeParams.print();
            break;
        case 'T':   // Toggles from (T)our mode to standard mode and back
        case 't':   // Toggles from (t)our mode to standard mode and back
            bTour = bTour ? shrFALSE : shrTRUE;
            shrLog("\nTour Mode %s...\n", bTour ? "ON" : "OFF");
            break;
        case '1':
            ResetSim(nbody, numBodies, NBODY_CONFIG_SHELL, true);
            break;
        case '2':
            ResetSim(nbody, numBodies, NBODY_CONFIG_RANDOM, true);
            break;
        case '3':
            ResetSim(nbody, numBodies, NBODY_CONFIG_EXPAND, true);
            break;
        case '\033': // escape quits
        case '\015': // Enter quits    
        case 'Q':    // Q quits
        case 'q':    // q (or escape) quits
            // Cleanup and quit
            bNoPrompt = shrTRUE;
            shrQAFinish2(false, *pArgc, (const char **)pArgv, QA_PASSED);
            Cleanup(EXIT_SUCCESS);
            break;
    }

    // Trigger fps update and call for refresh
    TriggerFPSUpdate();
    glutPostRedisplay();
}
Exemplo n.º 14
0
	void doSetWindowPosition(const Point& position)
	{
		if (Point(glutGet(GLUT_WINDOW_X), glutGet(GLUT_WINDOW_Y)) != position) {
			glutPositionWindow(position.x, position.y);
		}
	}
Exemplo n.º 15
0
void SimulatorSingleton::run_sim()
{
  int argc = 0;
  char *argv[1];
  unsigned width, height;
  read_common_mv_setting ("IMG_WIDTH_COMMON", width);
  read_common_mv_setting ("IMG_HEIGHT_COMMON", height);
  
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE | GLUT_DEPTH | GLUT_RGB | GLUT_DOUBLE);
  glutInitWindowSize (width, height);
  glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION);
  glutInitWindowPosition(10, 0);

  dwn_window = glutCreateWindow ("Down Cam");
  glutPositionWindow(0, 400);
  glutReshapeFunc  (::sim_reshape);
  glutDisplayFunc  (::sim_display);
  glutIdleFunc     (::sim_idle);
  glutKeyboardFunc (::sim_keyboard);
  glutCloseFunc    (::sim_close_window);
  init_sim();

  fwd_window = glutCreateWindow ("Forwards Cam");
  glutReshapeFunc  (::sim_reshape);
  glutDisplayFunc  (::sim_display);
  glutIdleFunc     (::sim_idle);
  glutKeyboardFunc (::sim_keyboard);
  glutCloseFunc    (::sim_close_window);
  init_sim();

  img_fwd = cvCreateImage (cvSize(width,height), IPL_DEPTH_8U, 3);
  img_dwn = cvCreateImage (cvSize(width,height), IPL_DEPTH_8U, 3);

  // set initial position
  std::string start_at;
  read_mv_setting(SIM_SETTINGS_FILE, "START_AT", start_at);

  float start_x = 0.f;
  float start_y = 0.f;
  float start_z = 0.f;
  float start_yaw = 0.f;

  if (start_at == "GATE") {
    start_x = -3.f;
    start_y = 7.5f;
    start_z = 16.f;
  } else if (start_at == "BUOY") {
    start_x = -3.3f;
    start_y = 4.5f;
    start_z = 3.f;
    start_yaw = 18.f;
  } else if (start_at == "GOALPOST") {
    start_x = 1.f;
    start_y = 2.5f;
    start_z = -4.2f;
    start_yaw = 80.f;
  } else if (start_at == "MULTIPATH") {
    start_x = 7.f;
    start_y = 2.5f;
    start_z = -5.f;
    start_yaw = 80.f;
  } else if (start_at == "TORPEDO_TARGET") {
    start_x = 10.1f;
    start_y = 2.35f;
    start_z = -1.9f;
    start_yaw = -170.f;
  } else if (start_at == "MARKER_DROPPER") {
    start_x = 10.8f;
    start_y = 2.5f;
    start_z = -7.1f;
    start_yaw = -4.f;
  }

  model.position.x = start_x;
  model.position.y = start_y;
  model.position.z = start_z;
  model.angle.yaw = start_yaw;

  set_target_depth(POOL_HEIGHT - start_y);
  set_target_yaw(start_yaw);

  // Sim has initialized
  sem_post(&sema);

  glutMainLoop();
}
Exemplo n.º 16
0
//--------------------------------------
void ofSetWindowPosition(int x, int y){
	glutPositionWindow(x,y);
}
/* myKeyboardFunc():  Keyboard input menu.  */
void myKeyboardFunc( unsigned char key, int x, int y ) {
	switch ( key ) {
	case 'f':
		glutFullScreen();
		break;
	case 'b':
		fprintf(stderr, "[b]:  Current torque value is:  %i.\n", rawTorque);
		break;
	case 'g':
		fprintf(stderr, "[g]:  Active torque mode.  Press \"s\" to stop.\n");
		runMode = 1;
		glutPostRedisplay();
		break;
	case 's':
		fprintf(stderr, "[s]:  Stop mode.  Press \"g\" to run.\n");
		oscillationMode = 0;
		runMode = 0;
		break;
	case 'r':
		fprintf(stderr, "[r]:  Recording %i samples.\n", numberOfSamples);
		fprintf(stderr, "Current displayMode is:  %i.\n", displayMode);
		fprintf(stderr, "Current size is:  %.3f.\n", size);
		fprintf(stderr, "Current curvature of the display is:  %.3f.\n", curve);
		fprintf(stderr, "Current bias is:  %i.\n", bias);
		fprintf(stderr, "Current gain is:  %.3f.\n\n", gain);
		recordMode = 1;
		dataCounter = 0;
		break;
	case 'w':
		fprintf(stderr, "[w]:  Increasing width by %i, size is now: %.3f.\n", sizeMod, size);
		size = size+sizeMod;
		glutPostRedisplay();
		break;
	case 't':
		fprintf(stderr, "[t]:  Decreasing width by %i, size is now: %.3f.\n", sizeMod, size);
		size = size-sizeMod;
		glutPostRedisplay();
		break;
	case 'c':
		fprintf(stderr, "[c]:  Increasing the curvature of the display to: %.3f).\n", curve);
		curve = curve+0.5;
		glutPostRedisplay();
		break;
	case 'p':
		fprintf(stderr, "[p]:  Decreasing the curvature of the display to: %.3f).\n.", curve);
		curve = curve-0.5;
		glutPostRedisplay();
		break;
	case '0':
		fprintf(stderr, "[0]:  Setting displayMode to 0 (blank screen).\n");
		displayMode = 0;
		glutPostRedisplay();
		break;
	case '1':
		fprintf(stderr, "[1]:  Setting displayMode to 1 (verticalBar).\n");
		displayMode = 1;
		shift = 0;
		glutPostRedisplay();
		break;
	case '2':
		fprintf(stderr, "[2]:  Setting displayMode to 2 (sineGradient).\n");
		displayMode = 2;
		shift = 0;
		glutPostRedisplay();
		break;
	case '3':
		fprintf(stderr, "[3]:  Setting displayMode to 3 (horizontalBar).\n");
		displayMode = 3;
		shift = 0;
		glutPostRedisplay();
		break;
	case '4':
		fprintf(stderr, "[4]:  Setting displayMode to 4 (solidCircle).\n");
		displayMode = 4;
		shift = 0;
		glutPostRedisplay();
		break;
	case '.':
		bias=bias+biasMod;
		fprintf(stderr, "[.]:  Increasing clockwise bias to: %i.\n",bias);
		break;
	case ',':
		bias=bias-biasMod;
		fprintf(stderr, "[,]:  Increasing counterclockwise bias to:  %i.\n",bias);
		break;
	case 'k':
		fprintf(stderr, "[k]:  Resetting bias and gain.\n");
		gain = 0.6;
		bias = 0;
		break;
	case 'o':
		fprintf(stderr, "[o]:  Starting oscillation mode (no torque input).\n");
		runMode = 1;
		oscillationMode = 1;
		break;
	case 'q':
		exit(1);
	case 27:
		glutReshapeWindow(window_width,window_height);
		glutPositionWindow(100,100);
		break;
	}
}
Exemplo n.º 18
0
void SpecialKeyDown(int key, int x, int y)
{
	Keyboard *keyboard = CurrentGame()->getKeyboard();
	keyboard->special_key_state[key] = true;
	keyboard->m_special_key_event_board.onEvent(key, EnumEventType::ON_DOWN);

	// HACK
	static bool fullscreen = 0;
	switch (key){

		//toggle Creative Mode
		case GLUT_KEY_F2:
			bCreative ^= 1;
			bGravity ^= 1;
			break;
		/*
		//toggle the shader
		case GLUT_KEY_F1:
			bCustomGLSL ^= 1;
			break;
		*/

		//toggle view_mode
		case GLUT_KEY_F5:
			view_mode = (view_mode + 1) % VIEW_MODE_TOTAL_NUMBER;
			break;

		//toggle showing the observer
		case GLUT_KEY_F6: {
			Entity *entity = CurrentGame()->getPlayerEntity();
			if (entity != nullptr) entity->render_config.is_visible ^= 1;
			break;
		}

		//toggle moving sun light
		case GLUT_KEY_F7:
			bMovingLight ^= 1;
			break;

		//toggle showing the box lines
		case GLUT_KEY_F9:
			bBoxLine ^= 1;
			break;

		//toggle showing the shadow depth map at the top right corner
		case GLUT_KEY_F10:
			bDebugDepthMap ^= 1;
			break;

		//toggle fullscreen
		case GLUT_KEY_F11:
			if (fullscreen){
				glutReshapeWindow(1000, 700);
				glutPositionWindow(0, 0);
				fullscreen = 0;
			}
			else {
				glutFullScreen();
				fullscreen = 1;
			}
			break;

		//screen_shot
		case GLUT_KEY_F12: {
			std::string filename = "screenshot_" + std::to_string(screenshot_count) + ".bmp";
			ScreenShot(filename);
			screenshot_count++;
			break;
		}
	}
}
Exemplo n.º 19
0
void onKeyboard(unsigned char key, int x, int y) {
	unsigned long i = 0;
	char *name = malloc(20 * sizeof(char));
	switch (key) {
		case 27: // Escape
			printf("x %d, y %d\n", x, y);
			printf("INFO: exit loop\n");
			glutLeaveMainLoop();
			break;
		case 'x':
			xx += 1.0;
			printf("INFO: x = %f\n", xx);
			break;
		case 'X':
			xx -= 1.0;
			printf("INFO: x = %f\n", xx);
			break;
		case 'y':
			yy += 1.0;
			printf("INFO: y = %f\n", yy);
			break;
		case 'Y':
			yy -= 1.0;
			printf("INFO: y = %f\n", yy);
			break;
		case 'f':
			fullScreen = !fullScreen;
			printf("INFO: fullscreen %d\n", fullScreen);
			if (fullScreen) {
				glutFullScreen();
			} else {
				glutPositionWindow(120,10);
				glutReshapeWindow(winSizeW, winSizeH);
			}
			break;
		case 'h':
			displayHilbert = !displayHilbert;
			printf("INFO: display Hilbert graph %d\n", displayHilbert);
			break;
		case 't':
			displayFFT = !displayFFT;
			printf("INFO: display FFT graph %d\n", displayFFT);
			break;
		case 'a':
			alpha -= 0.05;
			if (alpha <= 0) { alpha = 1.0; }
			for (i=0; i<sampleSize; i++) {
				pointsList[i].a = alpha;
			}
			printf("INFO: alpha channel %f\n", alpha);
			break;
		case 's':
			pSize += 1.0;
			if (pSize >= 20) { pSize = 0.5; }
			printf("INFO: point size %f\n", pSize);
			break;
		case 'r':
			rotate = !rotate;
			printf("INFO: rotate %d\n", rotate);
			break;
		case 'z':
			zoom -= 5.0;
			if (zoom < 5.0) {
				zoom = 5.0;
			}
			printf("INFO: zoom = %f\n", zoom);
			break;
		case 'Z':
			zoom += 5.0;
			printf("INFO: zoom = %f\n", zoom);
			break;
		case 'p':
			printf("INFO: take a screenshot\n");
			sprintf(name, "capture_%.3d.png", cpt);
			takeScreenshot(name);
			cpt += 1;
			break;
		default:
			break;
	}
	free(name);
	glutPostRedisplay();
}
Exemplo n.º 20
0
static void KeyPressFunc(unsigned char Key, int x, int y)
{
    switch (Key)
    {
    case 'q':
    case 'Q': //toggle screenmode
        if (!fullscreen)
        {
            glutFullScreen();
            fullscreen = true;
        }
        else if (fullscreen)
        {
            glutReshapeWindow(300, 300);
            glutPositionWindow(600, 600);
            fullscreen = false;
        }
        break;
    case 'H':
    case 'h': //toggle screenmode
        glutHideWindow();
        break;
    case 'S':
    case 's': //toggle screenmode
        glutShowWindow();
        break;

    case 'r': //toggle screenmode
        for (int i = 0; i < 27; i++)
        {
            if (fabs(list[i].getX() - 0.3) < eps)
            {
                list[i].rotate(0.3, 0, 0, 90, 0, 0);
                list[i].plusXRotated(90.0);
            }
        }
        break;
    case 'R': //toggle screenmode
        for (int i = 0; i < 27; i++)
        {
            if (fabs(list[i].getX() - 0.3) < eps)
            {
                list[i].rotate(0.3, 0, 0, -90, 0, 0);
                list[i].plusXRotated(-90.0);
            }
        }
        break;
    case 'l': //toggle screenmode

        for (int i = 0; i < 27; i++)
        {
            if (fabs(list[i].getX() + 0.3) < eps)
            {
                list[i].rotate(-0.3, 0, 0, 90, 0, 0);
                list[i].plusXRotated(90.0);
            }
        }
        break;
    case 'L': //toggle screenmode
        for (int i = 0; i < 27; i++)
        {
            if (fabs(list[i].getX() + 0.3) < eps)
            {
                list[i].rotate(-0.3, 0, 0, -90, 0, 0);
                list[i].plusXRotated(-90.0);
            }
        }
        break;
    case 'd': //toggle screenmode
        for (int i = 0; i < 27; i++)
        {
            if (fabs(list[i].getY() + 0.3) < eps)
            {
                list[i].rotate(0, -0.3, 0, 0, 90, 0);
                list[i].plusYRotated(90.0);
            }
        }
        break;
    case 'D': //toggle screenmode
        for (int i = 0; i < 27; i++)
        {
            if (fabs(list[i].getY() + 0.3) < eps)
            {
                list[i].rotate(0, -0.3, 0, 0, -90, 0);
                list[i].plusYRotated(-90.0);
            }
        }
        break;
    case 'u': //toggle screenmode
        for (int i = 0; i < 27; i++)
        {
            if (fabs(list[i].getY() - 0.3) < eps)
            {
                list[i].rotate(0, 0.3, 0, 0, 90, 0);
                list[i].plusYRotated(90.0);
            }
        }
        break;
    case 'U': //toggle screenmode
        for (int i = 0; i < 27; i++)
        {
            if (fabs(list[i].getY() - 0.3) < eps)
            {
                list[i].rotate(0, 0.3, 0, 0, -90, 0);
                list[i].plusYRotated(-90.0);
            }
        }
        break;
    case 'f': //toggle screenmode
        for (int i = 0; i < 27; i++)
        {
            if (fabs(list[i].getZ() + 0.3) < eps)
            {
                list[i].rotate(0, 0, -0.3, 0, 0, 90);
                list[i].plusZRotated(90.0);
            }
        }
        break;
    case 'F': //toggle screenmode
        for (int i = 0; i < 27; i++)
        {
            if (fabs(list[i].getZ() + 0.3) < eps)
            {
                list[i].rotate(0, 0, -0.3, 0, 0, -90);
                list[i].plusZRotated(-90.0);
            }
        }
        break;
    case 'b': //toggle screenmode
        for (int i = 0; i < 27; i++)
        {
            if (fabs(list[i].getZ() - 0.3) < eps)
            {
                list[i].rotate(0, 0, 0.3, 0, 0, 90);
                list[i].plusZRotated(90.0);
            }
        }
        break;
    case 'B': //toggle screenmode
        for (int i = 0; i < 27; i++)
        {
            if (fabs(list[i].getZ() - 0.3) < eps)
            {
                list[i].rotate(0, 0, 0.3, 0, 0, -90);
                list[i].plusZRotated(-90.0);
            }
        }
        break;
    case 27: // Escape key
        exit(1);
    }
}
Exemplo n.º 21
0
/*
 * Activates a menu pointed by the function argument
 */
static void fghActivateMenu( SFG_Window* window, int button )
{
    int max_x, max_y;
    SFG_XYUse mouse_pos;

    /* We'll be referencing this menu a lot, so remember its address: */
    SFG_Menu* menu = window->Menu[ button ];
    SFG_Window* current_window = fgStructure.CurrentWindow;

    /* If the menu is already active in another window, deactivate it (and any submenus) there */
    if ( menu->ParentWindow )
        fgDeactivateMenu(menu->ParentWindow);

    /* Mark the menu as active, so that it gets displayed: */
    window->ActiveMenu = menu;
    menu->IsActive = GL_TRUE;
    fghSetMenuParentWindow ( window, menu );
    fgState.ActiveMenus++;

    /* Set up the initial menu position now: */
    fghGetVMaxExtent(menu->ParentWindow, &max_x, &max_y);
    fgSetWindow( window );
    /* get mouse position on screen (window->State.MouseX and window->State.MouseY
     * are relative to client area origin), and not easy to correct given that
     * glutGet( GLUT_WINDOW_X ) and glutGet( GLUT_WINDOW_Y ) return relative to parent
     * origin when looking at a child window
     * for parent windows: window->State.MouseX + glutGet( GLUT_WINDOW_X ) == mouse_pos.X
     */
    fghPlatformGetCursorPos(NULL, GL_FALSE, &mouse_pos);
    menu->X = mouse_pos.X;
    menu->Y = mouse_pos.Y;

    /* Make sure the whole menu is on the screen */
    if( menu->X + menu->Width > max_x )
        menu->X -=menu->Width;

    if( menu->Y + menu->Height > max_y )
    {
        menu->Y -=menu->Height;
        if( menu->Y < 0 )
            menu->Y = 0;
    }

    /* Set position of mouse relative to top-left menu in menu's window state (could as well set 0 at creation time...) */
    menu->Window->State.MouseX = mouse_pos.X - menu->X;
    menu->Window->State.MouseY = mouse_pos.Y - menu->Y;

    /* Menu status callback */
    if (fgState.MenuStateCallback || fgState.MenuStatusCallback)
    {
        fgStructure.CurrentMenu = menu;
        fgStructure.CurrentWindow = window;
        if (fgState.MenuStateCallback)
            fgState.MenuStateCallback(GLUT_MENU_IN_USE);
        if (fgState.MenuStatusCallback)
            /* window->State.MouseX and window->State.MouseY are relative to client area origin, as needed */
            fgState.MenuStatusCallback(GLUT_MENU_IN_USE, window->State.MouseX, window->State.MouseY);
    }

    fgSetWindow( menu->Window );
    glutPositionWindow( menu->X, menu->Y );
    glutReshapeWindow( menu->Width, menu->Height );
    glutPopWindow( );
    glutShowWindow( );
    menu->Window->ActiveMenu = menu;
    fghCheckMenuStatus( menu );
    fgSetWindow( current_window );
}
Exemplo n.º 22
0
int main(int argc,char **argv)
{
    const char    *name          ="ClusterServer";
    const char    *connectionType="StreamSock";
//     const char    *connectionType="Multicast";
    bool           fullscreen     =true;
    std::string    address        ="";
    int            width=-1,height=300,x=0,y=0;
    bool           doStereo=false;
    char           *str;

    for(int i = 1 ; i < argc ; ++i)
    {
        if(argv[i][0] == '-')
        {
            switch(argv[i][1])
            {
                case 'm':
                    connectionType="Multicast";
                    break;
                case 's':
                    doStereo=true;
                    break;
                case 'w':
                    fullscreen=false;
                    break;
                case 'e':
                    exitOnError=true;
                    break;
                case 'a':
                    address=&(argv[i][2]);
                    break;
                case 'g':
                    if(argv[i][2] != '\0')
                        str=argv[i]+2;
                    else
                        str=argv[++i];
                    if(sscanf(str,"%d,%d,%d,%d",
                              &width,&height,&x,&y)!=4)
                    {
                        SWARNING << "Wrong args in -g. Use -gw,h,x,y" 
                                 << std::endl;
                        cleanup();
                        exit(0);
                    }
                    break;
                case 'p':
                    if(argv[i][2] != '\0')
                        servicePort=atoi(argv[i]+2);
                    else
                        servicePort=atoi(argv[++i]);
                    break;
                case 'j':
                    if(argv[i][2] != '\0')
                        serviceGroup=argv[i]+2;
                    else
                        serviceGroup=argv[++i];
                    break;
                case 'h':
                    std::cout << argv[0] 
                              << "-m "
                              << "-s "
                              << "-w "
                              << "-e "
                              << "-g w,h,x,y "
                              << "-a Address "
                              << "-j group "
                              << "-p servicePort "
                              << std::endl;
                    std::cout << "-m         use multicast" << std::endl;
                    std::cout << "-s         enable stereo" << std::endl;
                    std::cout << "-w         no fullscreen" << std::endl;
                    std::cout << "-e         exit after closed connection" 
                              << std::endl;
                    std::cout << "-g         geometry" << std::endl;
                    std::cout << "-a Address Server network address"
                              << std::endl;
                    std::cout << "-m Address wait for requests on "
                              << "multicast group" << std::endl;
                    std::cout << "-p port    wait for requests on port"
                              << std::endl;
                    return 0;
            }
        }
        else
        {
            name=argv[i];
        }
    }

    try
    {
        OSG::osgInit            (argc, argv);
        OSG::ClusterServer::init(argc, argv);

        glutInit(&argc, argv);

        if(doStereo)
            glutInitDisplayMode( GLUT_STEREO | 
                                 GLUT_RGB | 
                                 GLUT_DEPTH | 
                                 GLUT_DOUBLE);
        else
            glutInitDisplayMode( GLUT_RGB | 
                                 GLUT_DEPTH | 
                                 GLUT_DOUBLE);
        glutInitWindowPosition(x,y);
        if(width>0)
            glutInitWindowSize(width,height);
        winid = glutCreateWindow("OpenSG Cluster Client");
        if(fullscreen)
            glutFullScreen();
        /*
          else
          glutReshapeWindow(300,300);
        */
        if(width>0)
            glutReshapeWindow(width,height);
        glutPositionWindow(x, y);

        glutPopWindow();
        glutDisplayFunc(display);       
        glutIdleFunc(display);       
        glutKeyboardFunc(key);
        glutReshapeFunc(reshape);       
        glutSetWindowTitle(name);
        // switch off cursor
        glutSetCursor(GLUT_CURSOR_NONE);
        glEnable( GL_LIGHTING );
        glEnable( GL_LIGHT0 );
        glEnable( GL_DEPTH_TEST );
        glEnable( GL_NORMALIZE );
        ract = OSG::RenderAction::create();
//        ract->setFrustumCulling(false);
        window     = OSG::GLUTWindow::create();
        window->setGlutId(winid);
        window->init();
        server     = new OSG::ClusterServer(window,
                                            name,
                                            connectionType,
                                            address,
                                            servicePort,
                                            serviceGroup);
        server->start();
        running=true;
        glutMainLoop();
    } 
    catch(OSG_STDEXCEPTION_NAMESPACE::exception &e)
    {
        SLOG << e.what() << std::endl;
        delete server;
        cleanup();
        OSG::osgExit(); 
    }
    return 0;
}
Exemplo n.º 23
0
static void make_new_window(int mode) {
    if ( (mode != MODE_WINDOW) &&  (mode != MODE_FULLSCREEN) ) {
        // nothing to be done here
        return;
    }

    if (glut_is_initialized && glut_is_freeglut) {
        if (!FREEGLUT_IS_INITIALIZED) {
            glut_is_initialized = false;
            fg_window_is_fullscreen = false;
	        fg_window_state = 0;
        }
    }
    if (!glut_is_initialized)  {
        boinc_glut_init();
    }

    if (debug) fprintf(stderr, "make_new_window(): now calling glutCreateWindow(%s)...\n", aid.app_name);
    char window_title[256];
    get_window_title(aid, window_title, 256);

    // just show the window if its hidden
    // if it used to be fullscreen (before
    // it was hidden, reset size and position
    // to defaults
    //
    bool have_window = false;
    if (glut_is_freeglut && GLUT_HAVE_WINDOW) {
          have_window = true;
          glutShowWindow();
          if (fg_window_is_fullscreen) {
             glutPositionWindow(xpos, ypos);
             glutReshapeWindow(600, 400);
             fg_window_is_fullscreen = false;
          }
	  fg_window_state = MODE_WINDOW;
    }
    
#ifdef __APPLE__
    if (win)
        have_window = true;
#endif

    if (!have_window) {
        win = glutCreateWindow(window_title); 
        if (debug) fprintf(stderr, "glutCreateWindow() succeeded. win = %d\n", win);

        glutReshapeFunc(app_graphics_resize);
        glutKeyboardFunc(keyboardD);
        glutKeyboardUpFunc(keyboardU);
        glutMouseFunc(mouse_click);
        glutMotionFunc(mouse_click_move);
        glutDisplayFunc(maybe_render); 
        glEnable(GL_DEPTH_TEST);
  
        app_graphics_init();
    }
  
#ifdef __APPLE__
    glutWMCloseFunc(CloseWindow);   // Enable the window's close box
    BringAppToFront();
    // Show window only after a successful call to throttled_app_render(); 
    // this avoids momentary display of old image when screensaver restarts 
    // which made image appear to "jump."
    need_show = true;
#endif

    if (mode == MODE_FULLSCREEN)  {
        glutFullScreen();
    }

    return;
}
Exemplo n.º 24
0
// Callback handler for special-key event
void specialKeys(int key, int x, int y) {
	switch (key) {
		case GLUT_KEY_F1:														// F1: Toggle between full-screen and windowed mode
			fullScreenMode = !fullScreenMode;									// Toggle state
			if (fullScreenMode) {												// Full-screen mode
				windowPosX   = glutGet(GLUT_WINDOW_X);							// Save parameters
				windowPosY   = glutGet(GLUT_WINDOW_Y);
				windowWidth  = glutGet(GLUT_WINDOW_WIDTH);
				windowHeight = glutGet(GLUT_WINDOW_HEIGHT);
				glutFullScreen();												// Switch into full screen
			} else {															// Windowed mode
				glutReshapeWindow(windowWidth, windowHeight);					// Switch into windowed mode
				glutPositionWindow(windowPosX,windowPosY);						// Postion top-left corner
		}
        break;
		case GLUT_KEY_UP:														// Up: increase speed
			if(eyePositionVerticalDeg < 88.0 ){
				eyePositionVerticalDeg +=2.0;
				tmpY = 20*sin(eyePositionVerticalDeg* 2*PI / 360.0) * eyePositionZoom;
				tmpX = 20*sin(eyePositionHorizontalDeg* 2*PI / 360.0)*cos(eyePositionVerticalDeg* 2*PI / 360.0) * eyePositionZoom;
				tmpZ = 20*cos(eyePositionHorizontalDeg* 2*PI / 360.0)*cos(eyePositionVerticalDeg* 2*PI / 360.0) * eyePositionZoom;
				if(tmpX <= 20.0 && tmpZ <= 40.0 && tmpX >=-20.0 && tmpZ >= -40 && tmpY >= -2.0 && tmpY < 20.0){
					eyePositionY = tmpY;
					eyePositionX = tmpX;
					eyePositionZ = tmpZ;
				}
				else eyePositionVerticalDeg -=2.0;
			}
			break;
		case GLUT_KEY_DOWN:														// Up: decrease speed
			if(eyePositionVerticalDeg > -88.0){
				eyePositionVerticalDeg -=2.0;
				tmpY = 20*sin(eyePositionVerticalDeg* 2*PI / 360.0) * eyePositionZoom;
				tmpX = 20*sin(eyePositionHorizontalDeg* 2*PI / 360.0)*cos(eyePositionVerticalDeg* 2*PI / 360.0) * eyePositionZoom;
				tmpZ = 20*cos(eyePositionHorizontalDeg* 2*PI / 360.0)*cos(eyePositionVerticalDeg* 2*PI / 360.0) * eyePositionZoom;
				if(tmpX <= 20.0 && tmpZ <= 40.0 && tmpX >=-20.0 && tmpZ >= -40 && tmpY >= -2.0 && tmpY < 20.0){
					eyePositionY = tmpY;
					eyePositionX = tmpX;
					eyePositionZ = tmpZ;
				}
				else eyePositionVerticalDeg +=2.0;
			}
			break;
		case GLUT_KEY_LEFT:														// Up: increase speed
			if(eyePositionHorizontalDeg > 0.0){
				eyePositionHorizontalDeg -=4.0;
				tmpX = 20*sin(eyePositionHorizontalDeg* 2*PI / 360.0)*cos(eyePositionVerticalDeg* 2*PI / 360.0) * eyePositionZoom;
				tmpZ = 20*cos(eyePositionHorizontalDeg* 2*PI / 360.0)*cos(eyePositionVerticalDeg* 2*PI / 360.0) * eyePositionZoom;
				if(tmpX <= 20.0 && tmpZ <= 40.0 && tmpX >=-20.0 && tmpZ >= -40){
					eyePositionX = tmpX;
					eyePositionZ = tmpZ;
				}
				else eyePositionHorizontalDeg +=4.0;
			}
			else eyePositionHorizontalDeg = 360.0;
			break;
		case GLUT_KEY_RIGHT:														// Up: decrease speed
			if(eyePositionHorizontalDeg < 360.0){
				eyePositionHorizontalDeg +=4.0;
				tmpX = 20*sin(eyePositionHorizontalDeg* 2*PI / 360.0)*cos(eyePositionVerticalDeg* 2*PI / 360.0) * eyePositionZoom;
				tmpZ = 20*cos(eyePositionHorizontalDeg* 2*PI / 360.0)*cos(eyePositionVerticalDeg* 2*PI / 360.0) * eyePositionZoom;
				if(tmpX <= 20.0 && tmpZ <= 40.0 && tmpX >=-20.0 && tmpZ >= -40){
				eyePositionX = tmpX;
				eyePositionZ = tmpZ;
				}
				else eyePositionHorizontalDeg -=4.0;
			}
			else eyePositionHorizontalDeg = 0.0;
			break;
		case GLUT_KEY_PAGE_UP:														// Up: decrease speed
			if(eyePositionZoom > 0.1){
				eyeZoomTmp = eyePositionZoom * 0.99;
				tmpX = 20*sin(eyePositionHorizontalDeg* 2*PI / 360.0)*cos(eyePositionVerticalDeg* 2*PI / 360.0) * eyeZoomTmp;
				tmpY = 20*sin(eyePositionVerticalDeg* 2*PI / 360.0) * eyeZoomTmp;
				tmpZ = 20*cos(eyePositionHorizontalDeg* 2*PI / 360.0)*cos(eyePositionVerticalDeg* 2*PI / 360.0) * eyeZoomTmp;
				if(tmpX <= 20.0 && tmpZ <= 40.0 && tmpX >=-20.0 && tmpZ >= -40 && tmpY >= -2.0 && tmpY < 20.0){
					eyePositionX = tmpX;
					eyePositionY = tmpY;
					eyePositionZ = tmpZ;
					eyePositionZoom = eyeZoomTmp;
				}
			}
			break;
		case GLUT_KEY_PAGE_DOWN:														// Up: decrease speed
			if(eyePositionZoom < 10.0 ){
				eyeZoomTmp = eyePositionZoom * 1.01;
				tmpX = 20*sin(eyePositionHorizontalDeg* 2*PI / 360.0)*cos(eyePositionVerticalDeg* 2*PI / 360.0) * eyeZoomTmp;
				tmpY = 20*sin(eyePositionVerticalDeg* 2*PI / 360.0) * eyeZoomTmp;
				tmpZ = 20*cos(eyePositionHorizontalDeg* 2*PI / 360.0)*cos(eyePositionVerticalDeg* 2*PI / 360.0) * eyeZoomTmp;
				if(tmpX <= 20.0 && tmpZ <= 40.0 && tmpX >=-20.0 && tmpZ >= -40 && tmpY >= -2.0 && tmpY < 20.0){
					eyePositionX = tmpX;
					eyePositionY = tmpY;
					eyePositionZ = tmpZ;
					eyePositionZoom = eyeZoomTmp;
				}
			}
			break;
		case GLUT_KEY_END:														// Up: decrease speed
			if(lookAtPositionY > -2.0){
				lookAtPositionY -= 0.5;
				//eyePositionY -= 0.5;
			}
			break;
		case GLUT_KEY_HOME:														// Up: decrease speed
			if(lookAtPositionY < 20.0){
				lookAtPositionY += 0.5;
				//eyePositionY += 0.5;
			}
			break;
			
   }
}
Exemplo n.º 25
0
//------------------------------------------------------------
void ofAppGlutWindow::setWindowPosition(int x, int y){
	glutPositionWindow(x,y);
}
Exemplo n.º 26
0
int main(int argc, char *argv[])
{        
    // Initialise OpenGL
    glutInit(&argc, argv); 

    // Set window position, size & create window
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowPosition(50,50);
    glutInitWindowSize(width,height);
	windowId = glutCreateWindow("Ray Cast Volume Rendering");
	
	glewInit();

    // Set GLUT callback functions
	glutDisplayFunc(renderScene);
	//glutIdleFunc(updateScene);
	glutKeyboardFunc(keypress);

    // Setup OpenGL state & scene resources 
    init();

	//GLUI
    glui = GLUI_Master.create_glui( "Controls", 0, 865, 50); 

	movement_panel = new GLUI_Panel( glui, "Movement Parameters" );
    
	view_rot = new GLUI_Rotation( movement_panel, "Rotate", view_rotate );
	view_rot->set_spin( 1.0 );

	trans_z = new GLUI_Translation( movement_panel, "Zoom", GLUI_TRANSLATION_Z, &zoom );
	trans_z->set_speed( .05 );

	raycastPGM = new GLUI_Checkbox(glui, "Raycast /w XToon & Alpha Interpolation", &raycastEnable, RAYCAST, controlCB);
	xtoonPGM = new GLUI_Checkbox(glui, "Raycast XToon Shader", &xtoonEnable, XTOONPGM, controlCB);
	gradientPGM = new GLUI_Checkbox(glui, "Gradient", &gradientEnable, GRADIENT, controlCB);
	dvrPGM = new GLUI_Checkbox(glui, "DVR", &dvrEnable, DVR, controlCB);
	rin = new GLUI_Checkbox(glui, "Show Ray Start", &rayinToggle, RAYIN, controlCB);
	rout = new GLUI_Checkbox(glui, "Show Ray Stop", &rayoutToggle, RAYOUT, controlCB);

	column_01 = new GLUI_Column( glui );

	GUIRayCastRoll = new GLUI_Rollout( glui, "Ray Cast Parameters", false);

	raycaster_panel = new GLUI_Panel( GUIRayCastRoll, "" );
	jittering = new GLUI_Checkbox( raycaster_panel, "Stippling", &j, JITTER, controlCB );
	jittering->set_alignment( GLUI_ALIGN_RIGHT );

    GUIsamples = new GLUI_Spinner( raycaster_panel, "N Samples", &nSamples );
	GUIsamples->set_int_limits( 0, 255 );
    GUIsamples->set_alignment( GLUI_ALIGN_RIGHT );

    GUInoise = new GLUI_Spinner( raycaster_panel, "Noise Delta", &noiseDelta );
	GUInoise->set_float_limits( 1.0, 10.0 );
    GUInoise->set_alignment( GLUI_ALIGN_RIGHT );

    GUIstep = new GLUI_Spinner( raycaster_panel, "Step Length", &stepLength );
	GUIstep->set_float_limits( 0.01f, 1.0f );
    GUIstep->set_alignment( GLUI_ALIGN_RIGHT );

    GUIt = new GLUI_Spinner( raycaster_panel, "Threshold", &threshold );
	GUIt->set_float_limits( 0.01f, 1.0f );
    GUIt->set_alignment( GLUI_ALIGN_RIGHT );

    GUIgscale = new GLUI_Spinner( raycaster_panel, "Gradient Scale", &gradientScale );
	GUIgscale->set_float_limits( 0.01f, 1.0f );
    GUIgscale->set_alignment( GLUI_ALIGN_RIGHT );

    GUIgdelta = new GLUI_Spinner( raycaster_panel, "Gradient Delta", &gradientDelta );
	GUIgdelta->set_float_limits( 0.01f, 1.0f );
    GUIgdelta->set_alignment( GLUI_ALIGN_RIGHT );

    GUIfmax = new GLUI_Spinner( raycaster_panel, "Histogram (Alpha) Max", &fMax );
	GUIfmax->set_float_limits( 0.01f, 255.0f );
    GUIfmax->set_alignment( GLUI_ALIGN_RIGHT );

    GUIfmin = new GLUI_Spinner( raycaster_panel, "Histogram (Alpha) Min", &fMin );
	GUIfmin->set_float_limits( 0.0f, 255.0f );
    GUIfmin->set_alignment( GLUI_ALIGN_RIGHT );

    GUIalpha = new GLUI_Spinner( raycaster_panel, "Alpha Value", &alpha );
	GUIalpha->set_float_limits( 0.01f, 1.0f );
    GUIalpha->set_alignment( GLUI_ALIGN_RIGHT );

    GUItscale = new GLUI_Spinner( raycaster_panel, "Transfer Scale", &transferScale );
	GUItscale->set_float_limits( 0.01f, 1.0f );
    GUItscale->set_alignment( GLUI_ALIGN_RIGHT );

    GUIthick = new GLUI_Spinner( raycaster_panel, "Thickness", &thickness );
	GUIthick->set_float_limits( 0.01f, 1.0f );
    GUIthick->set_alignment( GLUI_ALIGN_RIGHT );

	GUIXToonRoll = new GLUI_Rollout( glui, "XTOON Parameters", false );
	
	xtoon_panel = new GLUI_Panel( GUIXToonRoll, "" );

	toneDetailBox = new GLUI_Checkbox(xtoon_panel, "Tone Detail", &toneDetail, XTOONTYPE, controlCB );

    GUIr = new GLUI_Spinner( xtoon_panel, "Coarse Detail", &R );
	GUIr->set_float_limits( 1.0f, 25.0f );
    GUIr->set_alignment( GLUI_ALIGN_RIGHT );

	backlightBOX = new GLUI_Checkbox(xtoon_panel, "Backlighting", &backlight, XTOONTYPE, controlCB );

    GUIR = new GLUI_Spinner( xtoon_panel, "Backlight Detail", &backlight_detail );
	GUIR->set_float_limits( 0.0f, 25.0f );
    GUIR->set_alignment( GLUI_ALIGN_RIGHT );

	specularBOX = new GLUI_Checkbox(xtoon_panel, "Specular Highlight", &specHighlight, XTOONTYPE, controlCB );

    GUIs = new GLUI_Spinner( xtoon_panel, "Shine Factor", &S );
	GUIs->set_float_limits( 1.0f, 25.0f );
    GUIs->set_alignment( GLUI_ALIGN_RIGHT );

	xtoonBOX = new GLUI_Checkbox(xtoon_panel, "Enable / Disable", &xToonFlag, XTOON, controlCB );

	glui->set_main_gfx_window(windowId);
    
	glutInitWindowSize(300, 300);
	subWindowId = glutCreateWindow("Transfer Function 2D Texture");
	glutPositionWindow(865, 350);

	// Set GLUT callback functions
	glutReshapeFunc(setViewport);
	glutDisplayFunc(renderSub);
	glutKeyboardFunc(keypressSub);
	
	// Setup OpenGL state & scene resources 
	initSub();

	GLUI_Master.set_glutIdleFunc(updateScene); 

    // Show window & start update loop
    glutMainLoop();    

	return 0;
}