void makegltext(GLuint &texture1, std::string path) { glGenTextures(1, &texture1); glBindTexture(GL_TEXTURE_2D, texture1); // All upcoming GL_TEXTURE_2D operations now have effect on our texture object // Set our texture parameters glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // Set texture filtering glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Load, create texture and generate mipmaps int width, height; //unsigned char* image = SOIL_load_image(FileSystem::getPath(path).c_str(), &width, &height, 0, SOIL_LOAD_RGB); //unsigned char dummyimage[3] = { 50, 180, 100 }; //msg(float(lfsr()) / (1 << 16)); //auto color = vector<unsigned char> pixels; auto a = rgb_from_hue(dist(mt)); pixels.push_back(a[0]); pixels.push_back(a[1]); pixels.push_back(a[2]); cout << (int)a[0] << " " << (int)a[1] << " " << (int)a[2] << endl; a = rgb_from_hue(dist(mt)); pixels.push_back(a[0]); pixels.push_back(a[1]); pixels.push_back(a[2]); cout << (int)a[0] << " " << (int)a[1] << " " << (int)a[2] << endl; a = rgb_from_hue(dist(mt)); pixels.push_back(a[0]); pixels.push_back(a[1]); pixels.push_back(a[2]); cout << (int)a[0] << " " << (int)a[1] << " " << (int)a[2] << endl; a = rgb_from_hue(dist(mt)); pixels.push_back(a[0]); pixels.push_back(a[1]); pixels.push_back(a[2]); cout << (int)a[0] << " " << (int)a[1] << " " << (int)a[2] << endl; glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 2, 2, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels.data()); //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image); glGenerateMipmap(GL_TEXTURE_2D); //SOIL_free_image_data(image); glBindTexture(GL_TEXTURE_2D, 0); // Unbind texture when done, so we won't accidentily mess up our texture. }
int effect_update(struct razer_fx_render_node *render) { float percentage = daemon_get_parameter_float(daemon_effect_get_parameter_by_index(render->effect,0)); int x,y; struct razer_rgb col; #ifdef USE_DEBUGGING printf(" (Bar.%d ## %%:%f)",render->id,percentage); #endif int xmax = (int)((21.0f / 100.0f) * percentage); for(x=0;x<render->device->columns_num;x++) for(y=0;y<render->device->rows_num;y++) { float dist = 0.0f; if(x-xmax <= 0) dist = 1.0f; else { dist = (21.0f / (x-xmax))/21.0f; } rgb_from_hue(dist,0.3f,0.0f,&col); rgb_mix_into(&render->output_frame->rows[y]->column[x],&render->input_frame->rows[y]->column[x],&col,render->opacity);//*render->opacity //&render->second_input_frame->rows[y]->column[x] render->output_frame->update_mask |= 1<<y; } return(1); }
//void demography :: add() //{ //// if(false) // { // b2CircleShape Shape; // Shape.m_radius = radius; // auto position = // Vec2(wsize.x*getrangerand(.1,.9), // wsize.y*getrangerand(.1,.9)); // // auto Body = makebody(World,&Shape,conv(position),b2_dynamicBody,0,0.01,0,.9); // // Body->SetLinearVelocity( // b2Vec2(5*getrangerand(-1,1), // 5*getrangerand(-1,1))); // cellbodies.push_back(Body); // pos.push_back(b2Vec2()); // //// cells.push_back(CircleShape(0,4)); //// cells.back().setFillColor(Color(255,80,160)); //// cells.back().setRadius(SCALE*radius*GR_PH_COEFF); //// cells.back().setOrigin(cells.back().getRadius(), cells.back().getRadius()); // vbunk.add(); // // cells.back().setPosition(conv(position)); // } // if(false) // { // pos.push_back(b2Vec2()); // // pos_sf.push_back(Vec2()); // // b2BodyDef BodyDef; // BodyDef.position = b2Vec2 // ((getrand(0.3)+0.2)*wsize.x/SCALE, // (getrand(0.3)+0.2)*wsize.y/SCALE); // BodyDef.type = b2_dynamicBody; // // BodyDef.linearDamping=dampen; // b2Body* Body = World.CreateBody(&BodyDef); // // b2CircleShape Shape; // Shape.m_radius = radius; // //Body->setv // b2FixtureDef FixtureDef; // FixtureDef.density = 4.f; // FixtureDef.restitution = .9f; // FixtureDef.shape = &Shape; // Body->CreateFixture(&FixtureDef); // Body->SetLinearVelocity(b2Vec2 // (5*getrangerand(-1,1), // 5*getrangerand(-1,1))); // cellbodies.push_back(Body); // // cells.push_back(CircleShape(SCALE,4)); // cells.back().setFillColor(Color(255,80,160)); // cells.back().setRadius(SCALE*radius); // cells.back().setOrigin(cells.back().getRadius(), cells.back().getRadius()); // } // lb2(cells.size()); //} void demography :: add_agent(Vec2 position, int is_enemy) { b2CircleShape shape,shape_s,shape_s_e; shape .m_radius = radius; shape_s .m_radius = sensor_radius; shape_s_e .m_radius = sensor_radius_e; auto Body = make_body(World,conv(position),b2_dynamicBody,dampen); b2FixtureDef fixdef, fixdef_s, fixdef_s_e; if(use_masks) { fixdef = make_fixture(static_cast<b2Shape*>(&shape), false, &filters[is_enemy][0],.1,4); //fixdef_s = make_fixture(static_cast<b2Shape*>(&shape_s), true, &filters[is_enemy][1] ); //fixdef_s_e = make_fixture(static_cast<b2Shape*>(&shape_s_e),true, &filters[is_enemy][2]); } else { fixdef = make_fixture (static_cast<b2Shape*>(&shape),false); fixdef.density=4; //fixdef_s = make_fixture(static_cast<b2Shape*>(&shape_s),true); //fixdef_s_e = make_fixture(static_cast<b2Shape*>(&shape_s_e),true); } Body->CreateFixture(&fixdef); //Body->CreateFixture(&fixdef_s); //Body->CreateFixture(&fixdef_s_e); if(!is_enemy)cellbodies.insert(Body); //if(draw_sensors) //{ // sensors[Body]=(CircleShape(SCALE*shape_s.m_radius,16)); // sensors[Body].setFillColor(Color(0,0,0,0)); // sensors[Body].setOutlineColor(Color(64,64,64)); // //sensors[Body].setOutlineColor(Color(0,64,0)); // sensors[Body].setOutlineThickness(0.5); // sensors[Body].setOrigin(sensors[Body].getRadius(), sensors[Body].getRadius()); // sensors2[Body]=(CircleShape(SCALE*shape_s_e.m_radius,16)); // sensors2[Body].setFillColor(Color(0,0,0,0)); // //sensors2[Body].setOutlineColor(Color(96,0,0)); // sensors2[Body].setOutlineColor(Color(64,64,64)); // sensors2[Body].setOutlineThickness(0.5); // sensors2[Body].setOrigin(sensors2[Body].getRadius(), sensors2[Body].getRadius()); //} #define USE_SHAPES #ifdef USE_SHAPES cells[Body]=CircleShape(SCALE,getrangerand(3,6)); cells[Body].setFillColor(rgb_from_hue(getrand(1))); cells[Body].setRadius(SCALE*radius); cells[Body].setOrigin(cells[Body].getRadius(), cells[Body].getRadius()); #else vbunk.add(); #endif nears[Body]=unordered_set<b2Body*>(); pos.push_back(b2Vec2()); }
int effect_update(struct razer_fx_render_node *render) { float magnitude = daemon_get_parameter_float(daemon_effect_get_parameter_by_index(render->effect,1)); int x,y; struct razer_rgb col; #ifdef USE_DEBUGGING printf(" (Fft.%d ## %%:%f)",render->id); #endif unsigned long samples_left=0; while((samples_left=wav_samples_left(effect_input_file))) { unsigned int sample = read_wav_stereo_sample(effect_input_file); short high = sample >> 16; short low = sample & 0xFFFF; //add sample to fft buffer effect_fft_in[effect_fft_samples_used][0] = (double)high * effect_fft_hamming_buffer[effect_fft_samples_used];///(double)32768;//* windowHanning(step++, N); effect_fft_in[effect_fft_samples_used++][1] = 0.0f; //enough samples gathered? if(effect_fft_samples_used==effect_fft_samples) { printf("Computing fft, still %d samples left\n",samples_left); //compute fft effect_fft_plan = fftw_plan_dft_1d(effect_fft_samples, effect_fft_in, effect_fft_out, FFTW_FORWARD, FFTW_ESTIMATE); fftw_execute(effect_fft_plan); fftw_destroy_plan(effect_fft_plan); effect_fft_samples_used = 0; double tmp_magnitude = sqrt(effect_fft_out[0][0]*effect_fft_out[0][0] + effect_fft_out[0][1]*effect_fft_out[0][1]); tmp_magnitude = 10./log(10.) * log(tmp_magnitude + 1e-6); printf("new fft mag db:%f\n",tmp_magnitude); double sum = 0.0f; for(int i=0;i<effect_fft_samples/2;i++) { double tmp_bin_magnitude = sqrt(effect_fft_out[i][0]*effect_fft_out[i][0] + effect_fft_out[i][1]*effect_fft_out[i][1]); tmp_bin_magnitude = 10./log(10.) * log(tmp_bin_magnitude + 1e-6); sum += tmp_bin_magnitude; } printf("sum:%f\n",sum/(effect_fft_samples/2)); magnitude = (float)tmp_magnitude - 50.0f; break; } } if(!samples_left) { #ifdef USE_DEBUGGING printf("no samples left to analyze, closing input file\n"); #endif close_wav(effect_input_file); effect_input_file = NULL; return(0); } //set color to avg magnitude ,transformed to 0.0-1.0 space //calculate hue from magnitude rgb_from_hue(magnitude/96,0.3f,0.0f,&col); for(x=0;x<22;x++) for(y=0;y<6;y++) { rgb_mix_into(&render->output_frame->rows[y].column[x],&render->input_frame->rows[y].column[x],&col,render->opacity);//*render->opacity //&render->second_input_frame->rows[y].column[x] render->output_frame->update_mask |= 1<<y; } daemon_set_parameter_float(daemon_effect_get_parameter_by_index(render->effect,1),magnitude); return(1); }
int main(int argc, char*argv[]) { // ████████ INITS 1 ████████ #ifndef COMMON_INITS1 cfg.init("bedlab.cfg"); ui2::init_ui(); Vec2i windowsize; Vec2i screen_resolution = { int(VideoMode::getDesktopMode().width), int(VideoMode::getDesktopMode().height) }; if (cfg.getvar<int>("auto_winsize")) { auto window_scale = cfg.getvar<Vec2>("window_scale"); windowsize = Vec2i(scal(Vec2(screen_resolution), window_scale)); } else { windowsize = cfg.getvar<Vec2i>("windowsize"); } winsize = Vec2(windowsize); //UI.init_console(); // ALWAYS AFTER SO IT CAN GET WINDOW SIZE ui2::init_console(); // ALWAYS AFTER SO IT CAN GET WINDOW SIZE wincenter = 0.5f*Vec2(windowsize); Vec2i windowpos; VideoMode::getDesktopMode().height; if (cfg.getvar<int>("stick_left")) { windowpos = Vec2i( screen_resolution.x - windowsize.x - 10, screen_resolution.y - windowsize.y - 40 ); } else windowpos = (Vec2i(5, 25)); sf::RenderWindow window(sf::VideoMode(windowsize.x, windowsize.y), "bedlab!", 7 //,sf::ContextSettings(0, 0, 1) ); window.setFramerateLimit(cfg.getvar<int>("fps_max")); frame_duration = 1.0f / cfg.getvar<int>("fps_max"); window.setPosition(windowpos); vector<string> keys; auto choice = cfg.getstr("app"); // show_keys(cfg.getstr("app"), keys); #endif // ████████ INITS2 ████████ #ifndef COMMON_INITS2 // we don't have a class/interface/struct with data, everything is local to this function, like a classic stack that all programs are anyway. // Texture cursor_tx; // if (!cursor_tx.loadFromFile(cfg.getstr("cursor"))) // cout << "did not load cursor" << endl; // Sprite cursor; // cursor.setTexture(cursor_tx); // cursor.setOrigin(3, 3); CircleShape cursor = mkcircle({ 0,0 }, Color::Transparent, 3, 1); Color background = cfg.getvar<Color>("background"); window.setMouseCursorVisible(false); Vec2 mpos; bool leftclicked = false, rightclicked = false; // view and zoom View view, ui_view; ui_view = view = window.getDefaultView(); float zoomlevel = 1; Vec2 mpos_abs; float frame_duration = 1.0f / cfg.getvar<int>("fps_max"); #endif // COMMON_INITS2 // ████████ APP ACTUAL ████████ { auto testarea = Vec2(winsize.y, winsize.y); auto offset = Vec2(-.5f*testarea); offset = { 0,0 }; int many = 4; float cellsize = 0.5*testarea.x / many; map<Vec2i, RectangleShape> zone_rects; for (int i = 0; i < many + 1; ++i) { for (int j = 0; j < many + 1; ++j) { auto c = rgb_from_hue((float((i + j) % many)) / many); c.a = 128; auto r = mkrect2( Vec2(i*cellsize, j*cellsize) //+ offset , Vec2(1, 1)*(cellsize - 10), Color::Transparent, 5, false ); r.setOutlineColor(c); //auto r_p = new RectangleShape(); //*r_p = r; //grid[Vec2i(i, j)].insert(r_p); zone_rects[Vec2i(i, j)] = r; lf.logw(strfy( (float((i + j) % many)) / many) + " " + strfy(c) ); } } } set<Vec2i> surround = { Vec2i(-1, -1) , Vec2i(0, -1) , Vec2i(1, -1) , Vec2i(1, 0) , Vec2i(1, 1) , Vec2i(0, 1) , Vec2i(-1, 1) , Vec2i(-1, 0), Vec2i(0, 0) }, active_chunks; float cell_size = 30; RectangleShape view_center = mkrect2({ 0,0 }, { 10,10 }, Color::Transparent, 1); RectangleShape world_center = mkrect2({ 0,0 }, { 6,6 }, Color::Red); //Vec2i reference_chunk = { 2,2 }; Vec2i reference_chunk = {0,0}; map<Vec2i, RectangleShape> chunks; for (int i = -5; i <= 5; ++i) { for (int j = -5; j <= 5; ++j) { chunks[Vec2i(i, j)] = mkrect2(cell_size*Vec2(i, j), { cell_size,cell_size }, Color::Transparent, 1); } } auto recenter_world = [&](Vec2i shift) { msgm("shifting", shift); world_center.move(Vec2(shift)*cell_size); for (auto&a : chunks) { a.second.move(Vec2(shift)*cell_size); } view.move(Vec2(shift)*cell_size); //world_center.setPosition(view.getCenter()); world_center.move(-Vec2(shift)*cell_size); //for (auto&a : chunks) { // a.second.setPosition(cell_size*Vec2(shift)); //} for (auto&a : active_chunks) { chunks[a].setFillColor(Color::Transparent); } active_chunks.clear(); // activate chunk surrounding the reference for (auto&a : surround) { auto index = reference_chunk + a; active_chunks.insert(index); //chunks[index].setPosition(cell_size*Vec2(index)); chunks[index].setFillColor(Color(255,0,0,128)); } }; recenter_world({ 0,0 }); auto recenter_check = [&]() { view_center.setPosition(view.getCenter()); //auto shift = Vec2i(2.f*view.getCenter() / (1.2f*cellsize)); auto shift = -Vec2i(0.8f * view.getCenter() / cell_size); show(view.getCenter()); //if (view.getCenter().x > cell_size*1.2f) reference_chunk.x -= 1; //if (view.getCenter().y > cell_size*1.2f) reference_chunk.y -= 1; //if (view.getCenter().x < -cell_size*1.2f) reference_chunk.x += 1; //if (view.getCenter().y < -cell_size*1.2f) reference_chunk.y += 1; //msg("recenter triggered!"); //reposition_chunks(); //reference_chunk = Vec2i(); if (shift != Vec2i{0, 0}) recenter_world(shift); reference_chunk -= shift; }; // ████████ callbacks ████████ bool panning = false; Vec2 previous_mouse_pos; view.setCenter({ 0,0 }); //view.sets #ifndef LOOP_LAMBDAS draw = [&]() { window.setView(view); //////////////// OBJECTS THAT CAN ZOOMED //////////////// window.draw(glob_vert_single); for (auto&a : glob_pts)window.draw(a); for (auto&a : glob_rects)window.draw(a); for (auto&a : glob_vert)window.draw(a); for (auto&a : glob_texts)window.draw(a); //////////////// OBJECTS THAT CAN ZOOMED //////////////// //for (auto&a : zone_rects) window.draw(a.second); for (auto&a : chunks) window.draw(a.second); window.draw(view_center); window.draw(world_center); // UI draw, AFTER ui view and BEFORE other draw window.setView(ui_view); //////////////// OBJECTS THAT CANNOT ZOOMED, MEANING UI //////////////// //br.drawwithtext(window); ui2::draw(window); //UI.draw(window); window.draw(cursor); }; update = [&]() { recenter_check(); }; treatkeyevent = [&](Keyboard::Key k) { switch (k) { case Keyboard::E: break; case Keyboard::I: break; case Keyboard::Q: break; case Keyboard::BackSpace: glob_pts.clear(); glob_texts.clear(); glob_rects.clear(); glob_vert.clear(); break; case Keyboard::Space: break; case Keyboard::S: screenshot(window); break; case Keyboard::Num1: case Keyboard::Num2: case Keyboard::Num3: case Keyboard::Num4: case Keyboard::Num5: break; } }; mousemoved = [&](Vec2 pos) { cursor.setPosition(pos); if (leftclicked); if (panning) { view.move((previous_mouse_pos - pos)); } previous_mouse_pos = pos; }; mouseclick = [&](sf::Mouse::Button button) { if (button == Mouse::Button::Left) leftclicked = true; if (button == Mouse::Button::Right) rightclicked = true; if (button == Mouse::Button::Left) { }; panning = leftclicked; }; mouserelease = [&](sf::Mouse::Button button) { if (button == Mouse::Button::Left) leftclicked = false; if (button == Mouse::Button::Right) rightclicked = false; if (button == Mouse::Button::Left) { } panning = leftclicked; }; loop = [&]() { while (window.isOpen()) { sf::Event event; while (window.pollEvent(event)) { switch (event.type) { case sf::Event::KeyPressed: if (event.key.code == sf::Keyboard::Escape) window.close(); treatkeyevent(event.key.code); break; case sf::Event::Closed: window.close(); break; case sf::Event::MouseButtonPressed: mouseclick(event.mouseButton.button); break; case sf::Event::MouseButtonReleased: mouserelease(event.mouseButton.button); break; case sf::Event::MouseMoved: mpos = Vec2(event.mouseMove.x, event.mouseMove.y); mpos_abs = window.mapPixelToCoords(Vec2i(mpos), view); mousemoved(mpos); break; default: treatotherevent(event); break; } } window.clear(background); update(); draw(); window.display(); } }; treatotherevent = [&](Event&e) { if (e.type == Event::MouseWheelMoved && e.mouseWheel.delta) { mpos_abs = window.mapPixelToCoords(Vec2i(mpos), view); //view = window.getView(); if (e.mouseWheel.delta < 0) { zoomlevel *= 2.f; view.setSize(view.getSize()*2.f); view.setCenter(interp(mpos_abs, view.getCenter(), 2.f)); //view.setCenter(interp(mpos_abs, view.getCenter(), 2.f)); } if (e.mouseWheel.delta > 0) { zoomlevel *= 0.5; view.setSize(view.getSize()*.5f); view.setCenter(.5f*(view.getCenter() + mpos_abs)); //view.setCenter(.5f*(view.getCenter() + mpos_abs)); } window.setView(view); } }; #endif // LOOP_LAMBDAS loop(); }
static void mode_colors(od_color *colors, int nmodes) { int i; for (i = 0; i < nmodes; i++) { rgb_from_hue(colors[i], HUE_MAX*i/nmodes); } }