void main_loop() { bool quit = false; while (!quit) { SDL_Event e; while (SDL_PollEvent(&e) != 0) { if (e.type == SDL_QUIT) { quit = true; } } const double freq = double(bx::getHPFrequency()); const double toMs = 1000.0 / freq; static int64_t totalMeasureTime = 0; int64_t measureTimeLast = bx::getHPCounter(); transform_system.update(); solid_quads.draw(transform_system, renderer); totalMeasureTime = ((bx::getHPCounter() - measureTimeLast) * 0.01 + totalMeasureTime * 0.99); renderer.begin_frame(); renderer.render(); bgfx::dbgTextPrintf(1, 1, 0x0f, "frame time: %f[ms]", 16.0f); bgfx::dbgTextPrintf(1, 2, 0x0f, "transform & draw time: %7.3f[ms]", double(totalMeasureTime)*toMs); bgfx::dbgTextPrintf(1, 3, 0x0f, "total entities: %d", entity_system.count()); renderer.end_frame(); T::main_loop(0.016f); SDL_Delay(16); } shutdown(); }
void highlight_box_rep::post_display (renderer &ren) { if (shape == "ring") display_ring (ren); if (shape == "band") display_band (ren); ren->set_background (old_bg); ren->set_pencil (old_pen); }
void edit_interface_rep::draw_surround (renderer ren, rectangle r) { ren->set_background (light_grey); string medium= get_init_string (PAGE_MEDIUM); if ((medium == "papyrus") || (medium == "paper")) ren->clear (max (eb->x2, r->x1), r->y1, r->x2, min (eb->y2+ 2*pixel, r->y2)); else if (medium == "paper") ren->clear (r->x1, r->y1, r->x2, min (eb->y1, r->y2)); }
void edit_interface_rep::draw_context (renderer ren, rectangle r) { int i; ren->set_color (light_grey); ren->set_line_style (pixel); for (i=1; i<N(eb[0]); i++) { SI y= eb->sy(0)+ eb[0]->sy2(i); if ((y >= r->y1) && (y < r->y2)) ren->line (r->x1, y, r->x2, y); } draw_surround (ren, r); }
void highlight_box_rep::pre_display (renderer& ren) { old_bg = ren->get_background (); old_pen= ren->get_pencil (); if (shape == "classic") display_classic (ren); else if (shape == "rounded") display_rounded (ren, ROUNDED_NORMAL); else if (shape == "angular") display_rounded (ren, ROUNDED_ANGULAR); else if (shape == "cartoon") display_rounded (ren, ROUNDED_CARTOON); else if (shape == "ring"); else if (shape == "band"); else display_classic (ren); }
void edit_interface_rep::draw_post (renderer ren, rectangle r) { renderer win= get_renderer (this); win->set_shrinking_factor (sfactor); ren->set_shrinking_factor (sfactor); draw_context (ren, r); draw_env (ren); draw_selection (ren); draw_graphics (ren); draw_cursor (ren); // the text cursor must be drawn over the graphical object ren->set_shrinking_factor (1); win->set_shrinking_factor (1); }
void poor_stretched_font_rep::draw_fixed (renderer ren, string s, SI x, SI y, SI xk) { if (ren->is_screen) { STACK_NEW_ARRAY (xpos, SI, N(s)+1); get_xpositions (s, xpos, xk); draw_fixed (ren, s, x, y, xpos); STACK_DELETE_ARRAY (xpos); } else { ren->set_transformation (scaling (point (1.0, factor), point (0.0, 0.0))); base->draw_fixed (ren, s, x, y, xk); ren->reset_transformation (); } }
void render(renderer& r) { auto const w = map_.width(); auto const h = map_.height(); for (int y = 0; y < h; ++y) { for (int x = 0; x < w; ++x) { auto const cat = map_.get<map_property::category>(x, y); using category = yama::tile_category; switch (cat) { case category::empty: r.set_color(0, 0, 0); break; case category::wall: r.set_color(100, 100, 100); break; case category::floor: r.set_color(200, 200, 200); break; case category::door: r.set_color(0, 0, 200); break; case category::corridor: r.set_color(0, 100, 0); break; case category::stair: r.set_color(255, 0, 0); break; case category::invalid: r.set_color(100, 100, 200); break; default: r.set_color(100, 100, 200); break; } r.fill_rect(x*16, y*16, 16, 16); } } r.set_color(255, 0, 0); for (auto const& region : regions_) { r.draw_rect(region.left*16, region.top*16, region.width()*16, region.height()*16); } }
void edit_interface_rep::draw_selection (renderer ren) { if (!is_nil (locus_rects)) { ren->set_color (rgb_color (32, 160, 96)); ren->draw_rectangles (locus_rects); } if (made_selection && !is_nil (selection_rects)) { ren->set_color (table_selection? rgb_color (192, 0, 255): red); #ifdef QTTEXMACS ren->draw_selection (selection_rects); #else ren->draw_rectangles (selection_rects); #endif } }
virtual void render() { copy_to_inner(); inner->render(); ++framesNotPrinted; int gfps = enabler->calculated_gfps; if (gfps == 0) gfps = 1; // send a frame roughly every 128 mibiseconds (1 second = 1024 mibiseconds) if ((framesNotPrinted * 1024) / gfps <= 128) return; client_pool::lock lock(clients); if (!clients.has_clients()) return; framesNotPrinted = 0; std::stringstream frame; frame << gps->dimx << ' ' << gps->dimy << " 0 0 " << gps->dimx << ' ' << gps->dimy << '\n'; unsigned char * sc_ = gps->screen; for (int y = 0; y < gps->dimy; ++y) { unsigned char * sc = sc_; for (int x = 0; x < gps->dimx; ++x) { unsigned char ch = sc[0]; unsigned char bold = (sc[3] != 0) * 8; unsigned char translate[] = { 0, 4, 2, 6, 1, 5, 3, 7, 8, 12, 10, 14, 9, 13, 11, 15 }; unsigned char fg = translate[(sc[1] + bold) % 16]; unsigned char bg = translate[sc[2] % 16]*16; frame.put(ch); frame.put(fg+bg); sc += 4*gps->dimy; } sc_ += 4; } clients.broadcast(frame.str()); }
void clear_pattern_rectangles (renderer ren, rectangles l) { while (!is_nil (l)) { rectangle r (l->item); ren->clear_pattern (r->x1- ren->ox, r->y1- ren->oy, r->x2- ren->ox, r->y2- ren->oy); l= l->next; } }
void cg::render(renderer &r, const model &m) { r.be(render_operation::triangles(), [&](renderer::primitive &p){ boost::for_each(m.triangles, [&](const model::triangle &t){ add_vertex(p, t.a); add_vertex(p, t.b); add_vertex(p, t.c); }); }); }
void highlight_box_rep::display_classic (renderer& ren) { SI X1= x1 - lx, Y1= y1 - bx; SI X2= x2 + rx, Y2= y2 + tx; SI LW= lw, BW= bw, RW= rw, TW= tw; if (!ren->is_printer ()) { SI pixel= ren->pixel; LW= ((lw + pixel - 1) / pixel) * pixel; BW= ((bw + pixel - 1) / pixel) * pixel; RW= ((rw + pixel - 1) / pixel) * pixel; TW= ((tw + pixel - 1) / pixel) * pixel; } ren->set_background (bg); ren->clear_pattern (X1+LW, Y1+BW, X2-RW, Y2-TW); if (N(bs)>1) { SI m= (sy2(0) + sy1(1)) >> 1; ren->set_background (xc); ren->clear_pattern (X1+LW, m, X2-RW, Y2-TW); }
//--Implementations void render() { //abort execution here if we are to stop running if(!keepRunning) { cleanUp(); exit(0); } //call renderer's render simRenderer.render(); }
void edit_interface_rep::draw_text (renderer ren, rectangles& l) { nr_painted=0; bool tp_found= false; tree bg= get_init_value (BG_COLOR); ren->set_background_pattern (bg); refresh_needed= do_animate; refresh_next = next_animate; eb->redraw (ren, eb->find_box_path (tp, tp_found), l); do_animate = refresh_needed; next_animate= refresh_next; }
void edit_graphics_rep::draw_graphical_object (renderer ren) { if (is_nil (go_box)) set_graphical_object (graphical_object); if (is_nil (go_box)) return; SI ox1, oy1, ox2, oy2; ren->get_clipping (ox1, oy1, ox2, oy2); SI gx1, gy1, gx2, gy2; if (find_graphical_region (gx1, gy1, gx2, gy2)) ren->extra_clipping (gx1, gy1, gx2, gy2); int i; for (i=0; i<go_box->subnr(); i++) { box b= go_box->subbox (i); if ((tree)b=="point" || (tree)b=="curve") b->display (ren); else { rectangles rs; b->redraw (ren, path (), rs); } } ren->set_clipping (ox1, oy1, ox2, oy2); }
bool postInitialize() { bool returnVal = true; //init the entity manager so it can finish what it needs to do after the shaders are in place simEntities.initialize(); //separate init for old renderer stuff returnVal = returnVal && simRenderer.initialize(); return returnVal; }
void poor_bbb_font_rep::draw_fixed (renderer ren, string s, SI x, SI y, SI* xpos) { int i=0; while (i < N(s)) { int start= i; tm_char_forwards (s, i); string ss= s (start, i); font_metric fnm; font_glyphs fng; int c= index_glyph (ss, fnm, fng); if (c >= 0) ren->draw (c, fng, start==0? x: x + xpos[start], y); } }
void poor_distorted_font_rep::draw_fixed (renderer ren, string s, SI x, SI y, SI* xpos) { int i=0; while (i < N(s)) { int start= i; base->advance_glyph (s, i); string ss= s (start, i); font_metric fnm; font_glyphs fng; int c= index_glyph (ss, fnm, fng); if (c >= 0) ren->draw (c, fng, start==0? x: x + xpos[start], y); } }
bool initialize() { bool returnVal = true; //initialize stuff //shader needs config for program stuff to setup our shaders returnVal = returnVal && simShaderManager.giveLinks(&simConfig); //config needs links to everything so it can let everyone access modules from anywhere returnVal = returnVal && simConfig.giveLinks(&simShaderManager, &simEntities); //renderer needs config for access to it and other modules returnVal = returnVal && simRenderer.giveLinks(&simConfig); return returnVal; }
void poor_stretched_font_rep::draw_fixed (renderer ren, string s, SI x, SI y, SI* xpos) { int i=0; while (i < N(s)) { int start= i; base->advance_glyph (s, i); string ss= s (start, i); font_metric fnm; font_glyphs fng; int c= index_glyph (ss, fnm, fng); //cout << "Drawing " << ss << ", " << c // << " at " << (xpos[start]/PIXEL) << "\n"; //cout << fng->get (c) << "\n\n"; if (c >= 0) ren->draw (c, fng, start==0? x: x + xpos[start], y); } }
void edit_interface_rep::draw_pre (renderer ren, rectangle r) { // draw surroundings tree bg= get_init_value (BG_COLOR); ren->set_background_pattern (bg); clear_pattern_rectangles (ren, rectangles (translate (r, ren->ox, ren->oy))); draw_surround (ren, r); // predraw cursor renderer win= get_renderer (this); draw_cursor (ren); rectangles l= copy_always; while (!is_nil (l)) { rectangle lr (l->item); win->put_shadow (ren, lr->x1, lr->y1, lr->x2, lr->y2); l= l->next; } }
bool postInitialize() { bool returnVal = true; //init the entity manager so it can finish what it needs to do after the shaders are in place simEntities.initialize(); //separate init for old renderer stuff returnVal = returnVal && simRenderer.initialize(); //init the lights, turning them "ON" simConfig.worldLights->init(); //init the game system simConfig.gameData.init(); return returnVal; }
void edit_interface_rep::draw_cursor (renderer ren) { if (!temp_invalid_cursor && (got_focus || full_screen)) { cursor cu= get_cursor(); if (!inside_active_graphics ()) { cu->y1 -= 2*pixel; cu->y2 += 2*pixel; SI x1= cu->ox + ((SI) (cu->y1 * cu->slope)), y1= cu->oy + cu->y1; SI x2= cu->ox + ((SI) (cu->y2 * cu->slope)), y2= cu->oy + cu->y2; ren->set_line_style (pixel); string mode= get_env_string (MODE); string family, series; if ((mode == "text") || (mode == "src")) { family= get_env_string (FONT_FAMILY); series= get_env_string (FONT_SERIES); } else if (mode == "math") { family= get_env_string (MATH_FONT_FAMILY); series= get_env_string (MATH_FONT_SERIES); } else if (mode == "prog") { family= get_env_string (PROG_FONT_FAMILY); series= get_env_string (PROG_FONT_SERIES); } if (cu->valid) { if (mode == "math") ren->set_color (rgb_color (192, 0, 255)); else ren->set_color (red); } else ren->set_color (green); SI lserif= (series=="bold"? 2*pixel: pixel), rserif= pixel; if (family == "ss") lserif= rserif= 0; ren->line (x1-lserif, y1, x1+rserif, y1); if (y1<=y2-pixel) { ren->line (x1, y1, x2, y2-pixel); if (series == "bold") ren->line (x1-pixel, y1, x2-pixel, y2-pixel); ren->line (x2-lserif, y2-pixel, x2+rserif, y2-pixel); } } } }
void edit_interface_rep::draw_env (renderer ren) { if (!full_screen) { if (!is_nil (env_rects)) { ren->set_color (rgb_color (0, 85, 85, 24)); ren->draw_rectangles (env_rects); } if (!is_nil (foc_rects)) { ren->set_color (rgb_color (0, 255, 255)); ren->draw_rectangles (foc_rects); } if (!is_nil (sem_rects)) { if (sem_correct) ren->set_color (rgb_color (112, 208, 112)); else ren->set_color (rgb_color (208, 144, 80)); ren->draw_rectangles (sem_rects); } } }
void init() { L = luaL_newstate(); create_window(); bgfx::init(bgfx::RendererType::OpenGL); uint32_t debug = BGFX_DEBUG_TEXT; uint32_t reset = 0; bgfx::reset(window_width, window_height, reset); bgfx::setDebug(debug); bgfx::setViewClear( 0 , BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH , 0x303030ff , 1.0f , 0); vertex::init(); renderer.init(); T::application = this; T::init(); }
void edit_interface_rep::draw_graphics (renderer ren) { if (got_focus || full_screen) { cursor cu= get_cursor(); if (over_graphics(cu->ox, cu->oy) && inside_active_graphics ()) { eval ("(graphics-reset-context 'graphics-cursor)"); draw_graphical_object (ren); string tm_curs= as_string (eval ("graphics-texmacs-pointer")); if (tm_curs != "none") { if (tm_curs == "graphics-cross") { ren->set_line_style (pixel); ren->set_color (red); ren->line (cu->ox, cu->oy-5*pixel, cu->ox, cu->oy+5*pixel); ren->line (cu->ox-5*pixel, cu->oy, cu->ox+5*pixel, cu->oy); } else if (tm_curs == "graphics-cross-arrows") { static int s= 6*pixel, a= 2*pixel; ren->set_line_style (pixel); ren->set_color (red); ren->line (cu->ox, cu->oy-s, cu->ox, cu->oy+s); ren->line (cu->ox-s, cu->oy, cu->ox+s, cu->oy); ren->line (cu->ox, cu->oy-s,cu->ox-a, cu->oy-s+a); ren->line (cu->ox, cu->oy-s, cu->ox+a, cu->oy-s+a); ren->line (cu->ox, cu->oy+s, cu->ox-a, cu->oy+s-a); ren->line (cu->ox, cu->oy+s, cu->ox+a, cu->oy+s-a); ren->line (cu->ox-s, cu->oy, cu->ox-s+a, cu->oy+a); ren->line (cu->ox-s, cu->oy, cu->ox-s+a, cu->oy-a); ren->line (cu->ox+s, cu->oy, cu->ox+s-a, cu->oy+a); ren->line (cu->ox+s, cu->oy, cu->ox+s-a, cu->oy-a); } } } else eval ("(graphics-reset-context 'text-cursor)"); } }
virtual bool uses_opengl() { return inner->uses_opengl(); }
virtual bool get_mouse_coords(int * x, int * y) { return inner->get_mouse_coords(x, y); }
virtual void grid_resize(int w, int h) { copy_to_inner(); inner->grid_resize(w, h); copy_from_inner(); }