Beispiel #1
0
 void draw(GLProgram &s){
   set_line_width(ceil(width*scale));
   bind_buffer_object(line_vbo,0);
   s.uniformf("pos",pos_start.x,pos_start.y); //Assume line attr = {(0,0),(1,1)}
   s.uniformf("size", pos_end.x - pos_start.x , pos_end.y - pos_start.y);
   s.uniformf("color",line_color.r,line_color.g,line_color.b,line_color.a);
   draw_buffers_line_loop(2);
 }
Beispiel #2
0
 void draw(GLProgram &s){
   bind_buffer_object(square_vbo,0);
   s.uniformf("pos",pos.x,pos.y);
   s.uniformf("size",size.x,size.y);
   s.uniformf("color",bg.r,bg.g,bg.b,bg.a);
   
   draw_buffers_triangle_fan(4);
   if(border.a != 0.0 && width > 0.0){
     set_line_width(ceil(width*scale));
     s.uniformf("color",border.r,border.g,border.b,border.a);
     draw_buffers_line_loop(4);
   }
 }
Beispiel #3
0
void test_nodeui_base(){
  
  RtAudio dac;
  RtAudio::StreamParameters parm;
  parm.deviceId = 0;//dac.getDefaultOutputDevice();
  parm.nChannels = 2;
  parm.firstChannel = 0;

  RtAudio::StreamOptions so;
  
  unsigned int bufferFrames = BUFFERSIZE;
  AudioScheduler a_sched;
  ControlScheduler c_sched;

  dac.openStream(&parm,NULL,RTAUDIO_SINT16, 44100, &bufferFrames, & saw, (void *) &a_sched);
  dac.startStream();
  
  
  init_ogl(1024,1024);
  

  GLProgram shader = make_program("shaders/naive.vert","shaders/naive.frag");
  UiBox ub1(Vec2f(-400.0,-300.0),Vec2f(800.0,600.0),{0.0,0.0,0.0,1.0},0.0,{0.0,0.0,0.0,0.0});
  
  square_vbo  = make_buffer<float>( {0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0}, 2,ARRAY_BUFFER, STATIC_DRAW);
  line_vbo = make_buffer<float>({0.0,0.0,1.0,1.0}, 2,ARRAY_BUFFER, STATIC_DRAW);
  float it = 0.0;
  scale =0.5;
  camera_x = 200.0;
  camera_y = -50.0;

  bool running = true;
  bool pause_proc = false;
  bool pause_ready = false;
  NodeGridInputHandler ngrid(&pause_proc, &pause_ready);;
  ngrid.backend.register_scheduler(&a_sched);
  ngrid.backend.register_scheduler(&c_sched);
  ngrid.shader = shader;
  ngrid.node_creators["osc"] = [](){return new Osc(440);};
  ngrid.node_creators["add-audio"] = [](){return new AddAudio();};
  ngrid.node_creators["audio-out"] = [](){return new AudioOut3();};
  ngrid.node_creators["line-play"] = [](){return new line_play(1.0,std::vector<float>({0.0})) ;};
  ngrid.node_creators["phasor"] = [](){return new Phasor(440) ;};
  ngrid.node_creators["multiply"] = []() {return new MultNode();};
  ngrid.node_creators["sub-audio"] = [](){return new SubAudio();};
  ngrid.node_creators["divide"] = []() {return new DivNode();};
  ngrid.node_creators["clip"] = []() {return new ClipNode();};
  ngrid.node_creators["quit-program"] = [&running](){return new QuitProgramNode(&running);};
  ngrid.node_creators["save-patch"] = [&ngrid](){return new SavePatchNode(&ngrid);};
  ngrid.node_creators["load-patch"] = [&ngrid](){return new LoadPatchNode(&ngrid);};
  Node * n1 = ngrid.create_and_insert_node("osc", Vec2f(0.0,0.0));
  Node *n2 = ngrid.create_and_insert_node("audio-out", Vec2f(0.0,50.0));
  Node *n3 = ngrid.create_and_insert_node("line-play 0.01 10 12 10 8",Vec2f(0.0,-100));
  ngrid.connect(n1,0,n2,0);
  ngrid.connect(n3,0,n1,0);
  mouse_move_spawner.register_listener(&ngrid);
  mouse_click_handler.register_listener(&ngrid);
  char_event_spawner.register_listener(&ngrid);
  key_event_handler.register_listener(&ngrid);
  mouse_wheel_event_spawner.register_listener(&ngrid);
  
  std::thread ngrid_thread([&](){
      while(running){
	
	if(pause_proc){
	  pause_ready = true;
	}else{
	  pause_ready = false;
	  ngrid.backend.update();
	}
	
      }
    });

  while(running){
    float t = get_time();
    if(ngrid.change){
      shader.uniformf("camera_scale",1.0,1.0);
      shader.uniformf("camera_translate",0.0,0.0);
      bind_buffer_object(square_vbo,0);
      shader.uniformf("size",2.0,2.0);
      shader.uniformf("pos",-1.0,-1.0);
      shader.uniformf("color",0.0,0.0,0.5,1.0);
      draw_buffers_triangle_fan(4);


      shader.uniformf("camera_scale",2.0/1024.0*scale,2.0/1024.0*scale);
      shader.uniformf("camera_translate",camera_x,camera_y);
      ngrid.draw();
      ngrid.draw2(shader);
      ngrid.change = false;
    }else{
      std::cout << "Graphics sleeping.. \n";
    }
    swapbuffers();
    std::cout << "DT: " << get_time() - t << "\n";
    float t_left = 1.0/30.0 - (get_time() - t);
    std::cout << t_left << "\n";
    if(t_left > 0){
      sleep_sec(t_left);
    }
    
  }

  ngrid_thread.join();

}