int main(int argc, char **argv)
{
	try 
	{
		// create the file watcher object
		FW::FileWatcher fileWatcher;

		// add a watch to the system
		FW::WatchID watchID = fileWatcher.addWatch("./test", new UpdateListener(), true);
		
		std::cout << "Press ^C to exit demo" << std::endl;

		// loop until a key is pressed
		while(1)
		{
			fileWatcher.update();
		}
	} 
	catch( std::exception& e ) 
	{
		fprintf(stderr, "An exception has occurred: %s\n", e.what());
	}

	return 0;
}
Example #2
0
int main(int argc, char **argv)
{
//	SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
//	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);

	/* initialize OpenGL */
	initGraphics(800,600,0);
	initGL( );
	initInput();
	renderInit();
	imguiRenderGLInit("DroidSans.ttf");
	curl_global_init(CURL_GLOBAL_ALL); 

	FW::FileWatcher* watcher = new FW::FileWatcher();
	/*FW::WatchID watchid = */watcher->addWatch( "./", new RecompileListener() );

	recompile();
	/* resize the initial window */
//	resizeWindow( xres, yres );

	/* These are to calculate our fps */
	static GLint T0     = 0;
	static GLint Frames = 0;



	/* wait for events */
	bool done = false;
	SDL_Event event;
	while ( !done )
	{
		/* handle the events in the queue */

		while ( SDL_PollEvent( &event ) )
		{
			switch( event.type )
			{
			//case SDL_ACTIVEEVENT:
				/* Something's happend with our focus
				* If we lost focus or we are iconified, we
				* shouldn't draw the screen
				*/
				//if ( event.active.gain == 0 )
				//	isActive = FALSE;
				//   else
				//		isActive = TRUE;
			//	break;			    
#if 0
			case SDL_VIDEORESIZE:
				/* handle resize event */
				surface = SDL_SetVideoMode( event.resize.w,
					event.resize.h,
					16, videoFlags );
				if ( !surface )
				{
					fprintf( stderr, "Could not get a surface after resize: %s\n", SDL_GetError( ) );
					Quit( 1 );
				}
				resizeWindow( event.resize.w, event.resize.h );
				break;
#endif
			case SDL_KEYDOWN:
				/* handle key presses */
				handleKeyPress( &event.key.keysym );
				break;
			case SDL_KEYUP:
                    if(event.key.keysym.sym<=255){
                        keystat[event.key.keysym.sym] = 0;
                    }
                    break;
			case SDL_MOUSEMOTION:
				mousexr = event.motion.xrel;
				mouseyr = event.motion.yrel;
				mousex = event.motion.x;
				mousey = event.motion.y;
				break;
			case SDL_MOUSEBUTTONDOWN:
				mousestat[event.button.button] = 1;
				break;
			case SDL_MOUSEBUTTONUP:
				mousestat[event.button.button] = 0;
				break;
			case SDL_QUIT:
				/* handle quit requests */
				done = TRUE;
				break;
			default:
				break;
			}
		}

		/* draw the scene */
		//if ( isActive )
		{
			watcher->update();
            
            //glClearColor(1, 0, 0, 1);
            //glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
            
			if(update)
			{
				update();
			}
            /*
            glMatrixMode(GL_PROJECTION);
            glLoadIdentity();
            float projection[16] = { 2.f/800, 0.f, 0.f,  0.f,
                0.f, 2.f/600,  0.f,  0.f,
                0.f,  0.f, -2.f, 0.f,
                -1.f, -1.f,  -1.f,  1.f };
            glLoadMatrixf(projection);
            glMatrixMode(GL_MODELVIEW);
            glLoadIdentity();*/
            glEnable(GL_BLEND);
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            glDisable(GL_DEPTH_TEST);
			imguiRenderGLDraw(800, 600);
            
/*
            glBegin(GL_TRIANGLES);
            glColor3f(1, 1, 0);
            glVertex2d(1, 1);
            glVertex2d(1, 0);
            glVertex2d(0, 1);
            glEnd();
*/
			/* Draw it to the screen */
			swapBuffers();
			
			/* Gather our frames per second */
			Frames++;
			{
				GLint t = SDL_GetTicks();
				if (t - T0 < 16) {
//					SDL_Delay(16 - (t-T0));

//					GLfloat seconds = (t - T0) / 1000.f;
//					GLfloat fps = Frames / seconds;
//					Frames = 0;
				}

				T0 = t;
			}

		}
	}

	imguiRenderGLDestroy();
	renderFini();

	/* clean ourselves up and exit */
	Quit( 0 );

	/* Should never get here */
	return( 0 );
}
int main(int argc, char* argv[]) {
  if(argc>1) {
    mainScript=argv[1];
  }

  //glfw
  if(!glfwInit()) {
    std::cout << "GLFW init error.\n";
    return 1;
  }

  window = glfwCreateWindow(1280, 600, "Demo", 0, 0);

  if(!window) {
    glfwTerminate();
    std::cout << "GLFW window creation error.\n";
    return 2;
  }

  glfwMakeContextCurrent(window);
  glfwSwapInterval(1);

  //glfw callbacks
  glfwSetKeyCallback(window, onKey);
  glfwSetMouseButtonCallback(window, onMouseButton);
  glfwSetCursorPosCallback(window, onCursor);
  glfwSetScrollCallback(window, onScroll);
  glfwSetWindowIconifyCallback(window,onIconify);
  glfwSetWindowFocusCallback(window,onFocus);
  glfwSetCursorEnterCallback(window, onCursorEnter);
  glfwSetCharCallback(window, onChar);

  //glew
  GLenum glewErr = glewInit();

  if(GLEW_OK != glewErr) {
    std::cout << "GLEW Error " << glewGetErrorString(glewErr) << std::endl;
    glfwTerminate();
    return 3;
  }

  //
  printVers();

  //


  int majorVer,minorVer;
  glGetIntegerv(GL_MAJOR_VERSION,&majorVer);
  glGetIntegerv(GL_MINOR_VERSION,&minorVer);
  //std::cout << majorVer<<" "<<minorVer << std::endl;

  //
  programManager=new ProgramManager();

  //
  if(majorVer>3 || minorVer>=3) {
    geometryShaderSupport=true;
    programManager->setGeometryShaderSupport(true);
    glPrimitiveRestartIndex(-1);
  }

  //
  initDeferred();

  //inits
  textureManager=new TextureManager();
  geometryVaoManager=new GeometryVaoManager();
  scene=new Scene(mainScript);

  //
  UpdateListener *fileListener=new UpdateListener();
  FW::FileWatcher fileWatcher;
 
  fileWatcher.addWatch("data/shader/geometry", fileListener);
  fileWatcher.addWatch("data/shader/deferred", fileListener);
  fileWatcher.addWatch("data/shader", fileListener);
  fileWatcher.addWatch("data/texture", fileListener);
  fileWatcher.addWatch("data/geometry", fileListener);
  fileWatcher.addWatch("data", fileListener);

  //
  int lastClientWidth=0,lastClientHeight=0;

  //
  while(!glfwWindowShouldClose(window)) {
    fileWatcher.update();
    double time = glfwGetTime();
    int clientWidth,clientHeight;
    glfwGetWindowSize(window, &clientWidth, &clientHeight);

    scene->run(time,clientWidth,clientHeight);

    glfwSetInputMode(window,GLFW_CURSOR, scene->isLockCursor()?GLFW_CURSOR_DISABLED:GLFW_CURSOR_NORMAL);


    if(lastClientWidth != clientWidth || lastClientHeight != clientHeight) {
      setupDeferred(clientWidth?clientWidth:128, clientHeight?clientHeight:128);
    }

    render(clientWidth,clientHeight);
    glfwSwapBuffers(window);
    glfwPollEvents();

    //
    lastClientWidth=clientWidth;
    lastClientHeight=clientHeight;
  }

  //uninits

  delete programManager;
  delete textureManager;
  delete geometryVaoManager;
  delete scene;


  uninitDeferred();

  //
  glfwTerminate();
  return 0;
}