void CScoreBoard::UpdateItem(const int id, const int new_value) { ScoreItem* tmp = NULL; if((tmp = this->FindItem(id)) == NULL) return; tmp->var = new_value; ss << tmp->main_line << new_value; SDL_FreeSurface(tmp->to_show); tmp->to_show = render_text(this->MainFont, ss.str(), NULL, this->TextColor, CREATE_SURFACE | TRANSPARENT_BG); ss.str(std::string()); }
static void profile_show_text(lua_State *L) { check_start(L); // Spent runtime so far. float total_spent = calc_elapsed_time(PROFILE_START_TIME, clock()); // Lua args lua_Object lobj = lua_getparam(L, 1); char *breakln = lua_isstring(L, lobj) ? lua_getstring(L, lobj) : "\n"; lobj = lua_getparam(L, 2); char *offsetc = lua_isstring(L, lobj) ? lua_getstring(L, lobj) : "\t"; Meta **array = get_metadata_array(L); render_text(L, array, STACK_INDEX - 1, offsetc, breakln); printf("TOTAL TIME SPENT: %.3f%s", total_spent, breakln); }
void PasteTextCommand::onExecute(Context* ctx) { Editor* editor = current_editor; if (editor == NULL) return; Preferences& pref = Preferences::instance(); PasteTextWindow window(pref.textTool.fontFace(), pref.textTool.fontSize(), pref.colorBar.fgColor()); window.userText()->setText(last_text_used); window.openWindowInForeground(); if (window.getKiller() != window.ok()) return; last_text_used = window.userText()->getText(); std::string faceName = window.faceValue(); int size = window.sizeValue(); size = MID(1, size, 999); pref.textTool.fontFace(faceName); pref.textTool.fontSize(size); try { std::string text = window.userText()->getText(); app::Color appColor = window.fontColor()->getColor(); doc::color_t color = doc::rgba(appColor.getRed(), appColor.getGreen(), appColor.getBlue(), appColor.getAlpha()); doc::ImageRef image(render_text(faceName, size, text, color)); if (image) { editor->pasteImage(image.get()); } } catch (const std::exception& ex) { ui::Alert::show(PACKAGE "<<%s" "||&OK", ex.what()); } }
void render() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //Configurando el frustrum glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(camera->aperture,(GLfloat)screen_width/(GLfloat)screen_height,1.0f,1000.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(camera->position.x, camera->position.y, camera->position.z, camera->center.x, camera->center.y, camera->center.z, camera->up.x, camera->up.y, camera->up.z); /* //Rendering light point glPushMatrix(); glDisable(GL_LIGHTING); glColor3f(0, 0.7, 0); glTranslatef(light_point->position[0], light_point->position[1], light_point->position[2]); glutSolidSphere(0.1, 10, 10); glEnable(GL_LIGHTING); glPopMatrix(); */ glPushMatrix(); glRotatef(surface->alphax,1.0,0.0,0.0); glRotatef(surface->alphaz,0.0,0.0,1.0); render_surface(surface); render_control_points(surface); render_ball(ball, surface); glPopMatrix(); render_level(); render_text(); glFlush(); glutSwapBuffers(); }
static void render_widget(AlWidget *widget, Vec2 translate, Box2 scissor) { widget->valid = true; if (!widget->visible) return; Vec2 location = vec2_add(widget->location, translate); Box2 bounds = box2_add_vec2(widget->bounds, location); scissor = box2_round(box2_intersect(scissor, bounds)); if (!box2_is_valid(scissor)) return; if (!widget->passThrough) { set_scissor(scissor); render_widget_main(widget, bounds); if (widget->border.width > 0) { scissor = box2_expand(scissor, -widget->border.width); set_scissor(scissor); } if (widget->model.model) { render_model(widget->model.model, vec2_add(widget->model.location, location), widget->model.scale); } if (widget->text.value) { render_text(widget->text.value, widget->text.colour, vec2_add(widget->text.location, location), widget->text.size); } } FOR_EACH_WIDGET(child, widget) { render_widget(child, location, scissor); }
int CScoreBoard::AddItem(const int x, const int y, const char* primary, int var) { static int id = rand() % 1234; ScoreItem* Item = new ScoreItem; Item->x = x; Item->y = y; Item->id = id; Item->var = var; /* C-string voodoo .__. */ Item->main_line = new char[strlen(primary) + 1]; strcpy(Item->main_line, primary); ss << primary << var; Item->to_show = render_text(this->MainFont, ss.str(), NULL, this->TextColor, CREATE_SURFACE|TRANSPARENT_BG); ss.str(std::string()); this->Items.push_back(Item); id++; return Item->id; }
surface get_rendered_text(const std::string& str, int size, const SDL_Color& colour, int style) { // TODO maybe later also to parse markup here, but a lot to check return render_text(str, size, colour, style, false); }
SDL_Surface * Text::render_text_large_gray(const char * t) { return render_text(font_large, GLYPH_LARGE_W, GLYPH_LARGE_H, GLYPH_LARGE_SPACING, t, true); }
SDL_Surface * Text::render_text_medium_gray(const char * t) { return render_text(font_medium, GLYPH_MEDIUM_W, GLYPH_MEDIUM_H, GLYPH_MEDIUM_SPACING, t, true); }
/* Text Gray */ SDL_Surface * Text::render_text_small_gray(const char * t) { return render_text(font_small, GLYPH_SMALL_W, GLYPH_SMALL_H, GLYPH_SMALL_SPACING, t, true); }
int main(int argc, char * argv[]) try { std::cout << "Waiting for device..." << std::endl; // Declare RealSense pipeline, encapsulating the actual device and sensors rs2::pipeline pipe; // Create a configuration for configuring the pipeline with a non default profile rs2::config cfg; // Enable fisheye and pose streams cfg.enable_stream(RS2_STREAM_POSE, RS2_FORMAT_6DOF); cfg.enable_stream(RS2_STREAM_FISHEYE, 1); cfg.enable_stream(RS2_STREAM_FISHEYE, 2); // Start pipeline with chosen configuration rs2::pipeline_profile pipe_profile = pipe.start(cfg); // T265 has two fisheye sensors, we can choose any of them (index 1 or 2) const int fisheye_sensor_idx = 1; // Get fisheye sensor intrinsics parameters rs2::stream_profile fisheye_stream = pipe_profile.get_stream(RS2_STREAM_FISHEYE, fisheye_sensor_idx); rs2_intrinsics intrinsics = fisheye_stream.as<rs2::video_stream_profile>().get_intrinsics(); // Get fisheye sensor extrinsics parameters. // This is the pose of the fisheye sensor relative to the T265 coordinate system. rs2_extrinsics extrinsics = fisheye_stream.get_extrinsics_to(pipe_profile.get_stream(RS2_STREAM_POSE)); std::cout << "Device got. Streaming data" << std::endl; // Create an OpenGL display window and a texture to draw the fisheye image window app(intrinsics.width, intrinsics.height, "Intel RealSense T265 Augmented Reality Example"); window_key_listener key_watcher(app); texture fisheye_image; // Create the vertices of a simple virtual object. // This virtual object is 4 points in 3D space that describe 3 XYZ 20cm long axes. // These vertices are relative to the object's own coordinate system. const float length = 0.20; const object virtual_object = {{ { 0, 0, 0 }, // origin { length, 0, 0 }, // X { 0, length, 0 }, // Y { 0, 0, length } // Z }}; // This variable will hold the pose of the virtual object in world coordinates. // We we initialize it once we get the first pose frame. rs2_pose object_pose_in_world; bool object_pose_in_world_initialized = false; // Main loop while (app) { rs2_pose device_pose_in_world; // This will contain the current device pose { // Wait for the next set of frames from the camera auto frames = pipe.wait_for_frames(); // Get a frame from the fisheye stream rs2::video_frame fisheye_frame = frames.get_fisheye_frame(fisheye_sensor_idx); // Get a frame from the pose stream rs2::pose_frame pose_frame = frames.get_pose_frame(); // Copy current camera pose device_pose_in_world = pose_frame.get_pose_data(); // Render the fisheye image fisheye_image.render(fisheye_frame, { 0, 0, app.width(), app.height() }); // By closing the current scope we let frames be deallocated, so we do not fill up librealsense queues while we do other computation. } // If we have not set the virtual object in the world yet, set it in front of the camera now. if (!object_pose_in_world_initialized) { object_pose_in_world = reset_object_pose(device_pose_in_world); object_pose_in_world_initialized = true; } // Compute the pose of the object relative to the current pose of the device rs2_pose world_pose_in_device = pose_inverse(device_pose_in_world); rs2_pose object_pose_in_device = pose_multiply(world_pose_in_device, object_pose_in_world); // Get the object vertices in device coordinates object object_in_device = convert_object_coordinates(virtual_object, object_pose_in_device); // Convert object vertices from device coordinates into fisheye sensor coordinates using extrinsics object object_in_sensor; for (size_t i = 0; i < object_in_device.size(); ++i) { rs2_transform_point_to_point(object_in_sensor[i].f, &extrinsics, object_in_device[i].f); } for (size_t i = 1; i < object_in_sensor.size(); ++i) { // Discretize the virtual object line into smaller 1cm long segments std::vector<point3d> points_in_sensor = raster_line(object_in_sensor[0], object_in_sensor[i], 0.01); std::vector<pixel> projected_line; projected_line.reserve(points_in_sensor.size()); for (auto& point : points_in_sensor) { // A 3D point is visible in the image if its Z coordinate relative to the fisheye sensor is positive. if (point.z() > 0) { // Project 3D sensor coordinates to 2D fisheye image coordinates using intrinsics projected_line.emplace_back(); rs2_project_point_to_pixel(projected_line.back().f, &intrinsics, point.f); } } // Display the line in the image render_line(projected_line, i); } // Display text in the image render_text(app.height(), "Press spacebar to reset the pose of the virtual object. Press ESC to exit"); // Check if some key is pressed switch (key_watcher.get_key()) { case GLFW_KEY_SPACE: // Reset virtual object pose if user presses spacebar object_pose_in_world = reset_object_pose(device_pose_in_world); std::cout << "Setting new pose for virtual object: " << object_pose_in_world.translation << std::endl; break; case GLFW_KEY_ESCAPE: // Exit if user presses escape app.close(); break; } } return EXIT_SUCCESS; } catch (const rs2::error & e) { std::cerr << "RealSense error calling " << e.get_failed_function() << "(" << e.get_failed_args() << "):\n " << e.what() << std::endl; return EXIT_FAILURE; } catch (const std::exception& e) { std::cerr << e.what() << std::endl; return EXIT_FAILURE; }
void display(void) { char tmps[128]; float rf; // setup projection and modelview matrices glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, DS_WIDTH, 0, DS_HEIGHT, -1, 1); glScalef(1, -1, 1); glTranslatef(0, -DS_HEIGHT, 0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // clear the back buffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // enable stuff glEnable(GL_LINE_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); // draw the current page switch (cpage) { case MAIN_PAGE1: synth_draw(); break; case MAIN_PAGE2: patch_draw(); break; case MAIN_PAGE3: pattern_draw(); break; case MAIN_PAGE4: sequencer_draw(); break; default: break; } // global ui elements console_print(6, DS_HEIGHT-27); main_ui[cpage]|=2; draw_button(DS_WIDTH-159, DS_HEIGHT-14, 16, "1", main_ui[MAIN_PAGE1]); draw_button(DS_WIDTH-137, DS_HEIGHT-14, 16, "2", main_ui[MAIN_PAGE2]); draw_button(DS_WIDTH-115, DS_HEIGHT-14, 16, "3", main_ui[MAIN_PAGE3]); draw_button(DS_WIDTH-93, DS_HEIGHT-14, 16, "4", main_ui[MAIN_PAGE4]); draw_textbox(DS_WIDTH-42, DS_HEIGHT-14, 16, 74, "komposter", main_ui[MAIN_ABOUT]); main_ui[cpage]&=1; // draw vu peak meter rf=fmin(1.0f, audio_latest_peak); rf=(0.2*lastrf) + (0.8*rf); // damping lastrf=rf; draw_textbox(728, DS_HEIGHT-14, 16, 100, "", main_ui[MAIN_VU]); glColor4f(0.68f, 0.33f, 0.0f, 0.94f); glBegin(GL_QUADS); glVertex2f(678, DS_HEIGHT-22); glVertex2f(678 + rf*100, DS_HEIGHT-22); glVertex2f(678 + rf*100, DS_HEIGHT-6); glVertex2f(678, DS_HEIGHT-6); glEnd(); sprintf(tmps, "%1.2f", audio_peak); render_text(tmps, 728, DS_HEIGHT-11, 2, (audio_peak > 1.0f) ? 0xffff8080 : 0xffffffff, 1); // if a dialog is active, dim the screen and draw it if (is_dialog()) dialog_draw(); // switch the back buffer to front glutSwapBuffers(); }
int main(int argc, char* argv[]) { // commandline argument parser options struct arg_lit *help = arg_lit0("h", "help", "print this help and exit"); struct arg_lit *vers = arg_lit0("v", "version", "print version information and exit"); struct arg_file *file = arg_file1("f", "file", "<file>", "font file"); struct arg_int *fh = arg_int1("g", "height", "<value>", "font height in pixels (6 or 8)"); struct arg_str *text = arg_str1("t", "text", "<value>", "text to show"); struct arg_int *scale = arg_int0("s", "scale", "<value>", "scaling for the window"); struct arg_end *end = arg_end(20); void* argtable[] = {help,vers,file,fh,text,scale,end}; const char* progname = "fonttool"; // Make sure everything got allocated if(arg_nullcheck(argtable) != 0) { printf("%s: insufficient memory\n", progname); goto exit_0; } // Parse arguments int nerrors = arg_parse(argc, argv, argtable); // Handle help if(help->count > 0) { printf("Usage: %s", progname); arg_print_syntax(stdout, argtable, "\n"); printf("\nArguments:\n"); arg_print_glossary(stdout, argtable, "%-25s %s\n"); goto exit_0; } // Handle version if(vers->count > 0) { printf("%s v0.1\n", progname); printf("Command line One Must Fall 2097 Font file editor.\n"); printf("Source code is available at https://github.com/omf2097 under MIT license.\n"); printf("(C) 2013 Tuomas Virtanen\n"); goto exit_0; } // Handle errors if(nerrors > 0) { arg_print_errors(stdout, end, progname); printf("Try '%s --help' for more information.\n", progname); goto exit_0; } // Init SDL SDL_Init(SDL_INIT_VIDEO); // Scale int _sc = 1; if(scale->count > 0) { _sc = scale->ival[0]; } if(_sc > 4) _sc = 4; if(_sc < 1) _sc = 1; // Font size int _fs = fh->ival[0]; if(_fs < 6 || _fs > 8 || _fs == 7) { printf("Only valid values for fontsize are 6 and 8.\n"); goto exit_1; } // Load fonts sd_font *font = sd_font_create(); if(sd_font_load(font, file->filename[0], _fs)) { printf("Couldn't load small font file!\n"); goto exit_2; } // Create surface for font rendering SDL_Surface *surface = 0; if((surface = render_text(font, text->sval[0], 320)) == 0) { printf("Failed to render text!\n"); goto exit_3; } // Init window SDL_Window *window = SDL_CreateWindow( "Fonttool v0.1", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 320 * _sc, 200 * _sc, SDL_WINDOW_SHOWN ); if (!window) { printf("Could not create window: %s\n", SDL_GetError()); goto exit_3; } // Rects SDL_Rect srcrect, dstrect; srcrect.x = 0; srcrect.y = 0; srcrect.w = surface->w; srcrect.h = surface->h; dstrect.x = 0; dstrect.y = 0; dstrect.w = surface->w * _sc; dstrect.h = surface->h * _sc; // Run until windows closed. SDL_Surface *window_surface = SDL_GetWindowSurface(window); Uint32 tcolor = SDL_MapRGBA(window_surface->format, 0, 0, 0, 0); SDL_Event e; int run = 1; while(run) { if(SDL_PollEvent(&e)) { if (e.type == SDL_QUIT) { run = 0; } } SDL_FillRect(window_surface, NULL, tcolor); if(_sc == 1) { SDL_BlitSurface(surface, &srcrect, window_surface, &dstrect); } else { SDL_SoftStretch(surface, &srcrect, window_surface, &dstrect); } SDL_UpdateWindowSurface(window); SDL_Delay(10); } // Quit SDL_DestroyWindow(window); exit_3: if(surface) SDL_FreeSurface(surface); exit_2: sd_font_delete(font); exit_1: SDL_Quit(); exit_0: arg_freetable(argtable, sizeof(argtable)/sizeof(argtable[0])); return 0; }
int main() { std::cout << glfwGetVersionString() << std::endl; GLuint texture{ 0 }, sampler{ 0 }; GLuint vbo{ 0 }, vao{ 0 }; GLuint vs{ 0 }, fs{ 0 }, program{ 0 }; FT_Library ft_lib{ nullptr }; FT_Face face{ nullptr }; auto cleanup = [&]() { FT_Done_Face(face); FT_Done_FreeType(ft_lib); glDeleteTextures(1, &texture); glDeleteSamplers(1, &sampler); glDeleteBuffers(1, &vbo); glDeleteVertexArrays(1, &vao); glDeleteShader(vs); glDeleteShader(fs); glDeleteProgram(program); }; // Initialize and load our freetype face if (FT_Init_FreeType(&ft_lib) != 0) { std::cerr << "Couldn't initialize FreeType library\n"; cleanup(); return 1; } if (FT_New_Face(ft_lib, "../Dependencies/fonts/Kalypsa-Medium.ttf", 0, &face) != 0) { std::cerr << "Unable to load myfont.ttf\n"; cleanup(); return 1; } // Create a GLFW window if (glfwInit() != GL_TRUE) { std::cerr << "Couldn't load GLFW library\n"; cleanup(); return 1; } glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); const int WIDTH = 640; const int HEIGHT = 480; const double SCALEX = 2.0 / WIDTH; const double SCALEY = 2.0 / HEIGHT; auto window = glfwCreateWindow(WIDTH, HEIGHT, "OpenGL Text Rendering", nullptr, nullptr); glfwMakeContextCurrent(window); glViewport(0, 0, WIDTH, HEIGHT); // Initialize our texture and VBOs glGenBuffers(1, &vbo); glGenVertexArrays(1, &vao); glGenTextures(1, &texture); glGenSamplers(1, &sampler); glSamplerParameteri(sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glSamplerParameteri(sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glSamplerParameteri(sampler, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glSamplerParameteri(sampler, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Initialize shader vs = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vs, 1, &VERTEX_SHADER, 0); glCompileShader(vs); fs = glCreateShader(GL_FRAGMENT_SHADER); glShaderSource(fs, 1, &FRAGMENT_SHADER, 0); glCompileShader(fs); program = glCreateProgram(); glAttachShader(program, vs); glAttachShader(program, fs); glLinkProgram(program); // Set some initialize GL state glEnable(GL_BLEND); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glClearColor(0.1, 0.2, 0.4, 0); // Get shader uniforms glUseProgram(program); glBindAttribLocation(program, 0, "in_Position"); GLuint texUniform = glGetUniformLocation(program, "tex"); GLuint colorUniform = glGetUniformLocation(program, "color"); while (glfwWindowShouldClose(window) != GL_TRUE) { glfwMakeContextCurrent(window); glClear(GL_COLOR_BUFFER_BIT); // Bind stuff glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture); glBindSampler(0, sampler); glBindVertexArray(vao); glEnableVertexAttribArray(0); glBindBuffer(GL_ARRAY_BUFFER, vbo); glUseProgram(program); glUniform4f(colorUniform, 1, 1, 1, 1); glUniform1i(texUniform, 0); FT_Set_Pixel_Sizes(face, 0, 50); render_text("Hello World!", face, -0.5, 0, SCALEX, SCALEY); glfwSwapBuffers(window); glfwPollEvents(); } cleanup(); return 0; }
static void text (Font *font, char *s, Scrd pos){ render_text(screen, font, s, pos); }
void agg_renderer<T>::process(shield_symbolizer const& sym, mapnik::feature_impl & feature, proj_transform const& prj_trans) { for (std::list<feature_ptr>::iterator f = featureList_->begin(); f != featureList_->end(); f++) { feature_ptr featurePtr = *f; shield_symbolizer_helper<face_manager<freetype_engine>, label_collision_detector4> helper( sym, *featurePtr, prj_trans, width_, height_, scale_factor_, t_, font_manager_, *detector_, query_extent_); text_renderer<T> ren(*current_buffer_, font_manager_, *(font_manager_.get_stroker()), sym.comp_op(), scale_factor_); while (helper.next()) { placements_type const& placements = helper.placements(); for (unsigned int ii = 0; ii < placements.size(); ++ii) { // get_marker_position returns (minx,miny) corner position, // while (currently only) agg_renderer::render_marker newly // expects center position; // until all renderers and shield_symbolizer_helper are // modified accordingly, we must adjust the position here pixel_position pos = helper.get_marker_position(placements[ii]); // pos.x += 0.5 * helper.get_marker_width(); // pos.y += 0.5 * helper.get_marker_height(); // render_marker(pos, // helper.get_marker(), // helper.get_image_transform(), // sym.get_opacity(), // sym.comp_op()); marker const& marker_ = helper.get_marker(); image_data_32 const& src = **marker_.get_bitmap_data(); double width = src.width(); double height = src.height(); const double shifted = 0; double markerX = pos.x + shifted, markerY = height_ - pos.y - shifted - height; glMatrixLoadIdentityEXT(GL_PROJECTION); glMatrixOrthoEXT(GL_PROJECTION, 0, width_, height_, 0, -1, 1); glMatrixLoadIdentityEXT(GL_MODELVIEW); GLubyte cmd[5]; GLfloat coord[8]; int m = 0, n = 0; cmd[m++] = GL_MOVE_TO_NV; coord[n++] = markerX; coord[n++] = markerY; cmd[m++] = GL_LINE_TO_NV; coord[n++] = markerX + width; coord[n++] = markerY; cmd[m++] = GL_LINE_TO_NV; coord[n++] = markerX + width; coord[n++] = markerY + height; cmd[m++] = GL_LINE_TO_NV; coord[n++] = markerX; coord[n++] = markerY + height; cmd[m++] = GL_CLOSE_PATH_NV; glPathCommandsNV(pathObject_, m, cmd, n, GL_FLOAT, coord); // glStencilFunc(GL_NOTEQUAL, 0, 0x1F); // glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO); //makeFaceTexture(TEXTURE_FACE); static GLuint texName; glGenTextures(1, &texName); glBindTexture(GL_TEXTURE_2D, texName); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (unsigned char *)src.getBytes()); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); GLfloat data[2][3] = { { 1,0,0 }, /* s = 1*x + 0*y + 0 */ { 0,1,0 } }; /* t = 0*x + 1*y + 0 */ //glEnable(GL_STENCIL_TEST); //glColor3f(1,1,1); glEnable(GL_TEXTURE_2D); glPathTexGenNV(GL_TEXTURE0, GL_PATH_OBJECT_BOUNDING_BOX_NV, 2, &data[0][0]); glStencilFillPathNV(pathObject_, GL_COUNT_UP_NV, 0x1F); glCoverFillPathNV(pathObject_, GL_BOUNDING_BOX_NV); glDisable(GL_TEXTURE_2D); pathObject_++; //Text rendering //ren.prepare_glyphs(placements[ii]); //ren.render(placements[ii].center); const int size = placements[ii].num_nodes(); int strokeEnable = 0; char word[size]; unsigned red,green,blue,alpha; double textWidth = 0; double textHeight = 0; color textColor,strokeColor; double opacity = 0.0; for (int i = 0; i < placements[ii].num_nodes(); i++) { char_info_ptr c; double x, y, angle; placements[ii].vertex(&c, &x, &y, &angle); word[i] = (char)c->c; textWidth += c->width; textHeight = c->height(); double halo_radius = c->format->halo_radius; if (halo_radius > 0.0 && halo_radius < 1024.0){ strokeEnable = 1; // red = c->format->halo_fill.red(); // green = c->format->halo_fill.green(); // blue = c->format->halo_fill.blue(); // alpha = c->format->halo_fill.alpha(); strokeColor = c->format->halo_fill; } textColor = c->format->fill; opacity = c->format->text_opacity; } double posX = placements[ii].center.x, posY = placements[ii].center.y; int centerText = textWidth / 2; double posTextY = height_ - markerY - (height)/2; double posTextX = posX - centerText; if(posTextY <= height_ / 2) posTextY -= 5; if(posTextX >= width_ / 2) posTextX += 5; if(!strokeEnable){ render_text(size, word, posTextX, posTextY,textColor, opacity); } if(strokeEnable){ render_text(size, word, posTextX, posTextY,textColor,strokeColor,opacity); } } } } }
void GLWidget::paintGL() { draw_engine_->draw_frame(time_->elapsed(), this->width(), this->height()); render_text(); glFlush(); swapBuffers(); }
void display(sd_font *font, int _sc, const char *text) { // Init SDL SDL_Init(SDL_INIT_VIDEO); // Create surface for font rendering SDL_Surface *surface = 0; if((surface = render_text(font, text, 320)) == 0) { printf("Failed to render text!\n"); goto d_exit_0; } // Init window SDL_Window *window = SDL_CreateWindow( "Fonttool v0.1", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 320 * _sc, 200 * _sc, SDL_WINDOW_SHOWN ); if (!window) { printf("Could not create window: %s\n", SDL_GetError()); goto d_exit_1; } // Rects SDL_Rect srcrect, dstrect; srcrect.x = 0; srcrect.y = 0; srcrect.w = surface->w; srcrect.h = surface->h; dstrect.x = 0; dstrect.y = 0; dstrect.w = surface->w * _sc; dstrect.h = surface->h * _sc; // Run until windows closed. SDL_Surface *window_surface = SDL_GetWindowSurface(window); Uint32 tcolor = SDL_MapRGBA(window_surface->format, 0, 0, 0, 0); SDL_Event e; int run = 1; while(run) { if(SDL_PollEvent(&e)) { if (e.type == SDL_QUIT) { run = 0; } } SDL_FillRect(window_surface, NULL, tcolor); if(_sc == 1) { SDL_BlitSurface(surface, &srcrect, window_surface, &dstrect); } else { SDL_BlitScaled(surface, &srcrect, window_surface, &dstrect); } SDL_UpdateWindowSurface(window); SDL_Delay(10); } // Quit SDL_DestroyWindow(window); d_exit_1: SDL_FreeSurface(surface); d_exit_0: SDL_Quit(); }
SDL_Rect draw_text_line(surface gui_surface, const SDL_Rect& area, int size, const SDL_Color& colour, const std::string& text, int x, int y, bool use_tooltips, int style) { if (gui_surface.null()) { text_surface const &u = text_cache::find(text_surface(text, size, colour, style)); SDL_Rect res = {0, 0, u.width(), u.height()}; return res; } if(area.w == 0) { // no place to draw SDL_Rect res = {0,0,0,0}; return res; } const std::string etext = make_text_ellipsis(text, size, area.w); // for the main current use, we already parsed markup surface surface(render_text(etext,size,colour,style,false)); if(surface == NULL) { SDL_Rect res = {0,0,0,0}; return res; } SDL_Rect dest; if(x!=-1) { dest.x = x; #ifdef HAVE_FRIBIDI // Oron -- Conditional, until all draw_text_line calls have fixed area parameter if(getenv("NO_RTL") == NULL) { bool is_rtl = text_cache::find(text_surface(text, size, colour, style)).is_rtl(); if(is_rtl) dest.x = area.x + area.w - surface->w - (x - area.x); } #endif } else dest.x = (area.w/2)-(surface->w/2); if(y!=-1) dest.y = y; else dest.y = (area.h/2)-(surface->h/2); dest.w = surface->w; dest.h = surface->h; if(line_width(text, size) > area.w) { tooltips::add_tooltip(dest,text); } if(dest.x + dest.w > area.x + area.w) { dest.w = area.x + area.w - dest.x; } if(dest.y + dest.h > area.y + area.h) { dest.h = area.y + area.h - dest.y; } if(gui_surface != NULL) { SDL_Rect src = dest; src.x = 0; src.y = 0; SDL_BlitSurface(surface,&src,gui_surface,&dest); } if(use_tooltips) { tooltips::add_tooltip(dest,text); } return dest; }
int main(int argc, char* argv[]) { if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("Can't initialize video \n"); return 1; } if (TTF_Init() < 0) { printf("Can't initialize ttf \n"); return 1; } lil_yuv_spec spec = lil_yuv420(3840, 2160); const size_t frame_size = lil_yuv_size(spec); const int frame_count = 500; int frame = 250; //yuv_video *video = yuv_video_alloc(argv[1], frame_size, frame_count); //yuv_video_read_frame(video, 0); //printf("Page size: %ld\n", ); file_reader *reader = file_reader_alloc(argv[1]); if (!reader) { printf("Can't reader reader\n"); return 1; } file_reader_map(reader, 0, frame_size); //TTF_Font *font = TTF_OpenFont("courier-new.ttf", 15); //This loads courier, but any font will do. //TTF_Font* font = loadfont("C:/windows/fonts/cour.ttf", 10); SDL_SetEventFilter(event_filter, NULL); atexit(SDL_Quit); int update_flag = 1; SDL_Window *window = SDL_CreateWindow( "An SDL2 window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 2 * spec.width, spec.height, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); const Uint32 windowID = SDL_GetWindowID(window); SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0); SDL_RendererInfo info; SDL_GetRendererInfo(renderer, &info); printf("Renderer: %s\n", info.name); //SDL_RenderSetLogicalSize(renderer, width, height); SDL_Texture *texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STREAMING, spec.width, spec.height); SDL_UpdateTexture(texture, NULL, file_reader_get(reader), spec.width); SDL_Color color = { 255, 255, 255, 255 }; SDL_Color color2 = { 0, 0, 0, 128 }; while (1) { SDL_Event event; while (SDL_PollEvent(&event)) { // PrintEvent(&event); switch (event.type) { case SDL_WINDOWEVENT: { if (event.window.windowID == windowID) { switch (event.window.event) { case SDL_WINDOWEVENT_SIZE_CHANGED: { const int width = event.window.data1; const int height = event.window.data2; update_flag = 1; break; } case SDL_WINDOWEVENT_CLOSE: { event.type = SDL_QUIT; SDL_PushEvent(&event); break; } } } break; } case SDL_KEYDOWN: { switch (event.key.keysym.sym) { case SDLK_1: printf("1\n"); SDL_SetWindowSize(window, 2 * spec.width, spec.height); break; case SDLK_2: printf("2\n"); SDL_SetWindowSize(window, 2 * 2 * spec.width, 2 * spec.height); break; case SDLK_LEFT: if (frame > 0) { --frame; update_flag = 1; } break; case SDLK_RIGHT: if (frame < frame_count - 1) { ++frame; update_flag = 1; } break; } break; } case SDL_QUIT: { return 0; } } // after switch if (update_flag) { //yuv_video_read_frame(video, frame); if (!file_reader_map(reader, frame_size * frame, frame_size)) { perror("Can't map file\n"); } SDL_UpdateTexture(texture, NULL, file_reader_get(reader), spec.width); char buf[100]; sprintf(buf, "352 x 288\n%d/90\npsnr=43.4", frame); SDL_Texture *text = render_text(renderer, buf, "courier-new.ttf", color, 25); SDL_Texture *text2 = render_text(renderer, buf, "courier-new.ttf", color2, 25); SDL_Point size = {spec.width, spec.height}; render_all(renderer, &size, texture, texture, text, text2); SDL_RenderPresent(renderer); SDL_DestroyTexture(text); SDL_DestroyTexture(text2); --update_flag; } } SDL_Delay(1); } SDL_DestroyWindow(window); SDL_Quit(); //yuv_video_free(video); file_reader_free(reader); return 0; }
void render_line(slide *sl, displayline *out, DrawMode *dm, SDL_Surface *surface) { style *st = sl->st; int single_line; int textshift, x, shift; int xmargin = st->leftmargin; int xbase = st->leftmargin + st->foldmargin; TTF_Font *font; if(dm != NULL) { // Store initial draw mode to make future individual line redraws easy: out->initial_dm = *dm; single_line = 0; } else { // Just drawing this line (not whole slide), so use saved draw mode: dm = new DrawMode; *dm = out->initial_dm; single_line = 1; } shift = 0; if(out->bullet == -1) { shift = dm->lastshift; } else if(out->bullet > 0) { shift = 10 + 30 * out->bullet; bullet(out->bullet, xbase + shift - 20, out->y + (st->text_ascent - st->text_descent) / 2, surface, st); } if(out->centred) { int text_area = sl->des_w - st->leftmargin - st->foldmargin - st->rightmargin; shift = (sl->des_w - out->width) / 2 - st->leftmargin - st->foldmargin; /* Force long lines into the text area, even if that means they end up off-centre within the slide itself due to different left/fold and right margins: */ if(shift + out->width > text_area) // Too far right shift = text_area - out->width; if(shift < 0) // Too far left shift = 0; } if(out->exposed > 0) exposeicon(out->exposed, xmargin, out->y, out->height, surface, st); if(out->type == TYPE_FOLDED) { textshift = 0; if(dm->ttmode) textshift += (st->text_ascent - st->fixed_ascent) / 2; else if(dm->italicmode) textshift += (st->text_ascent - st->italic_ascent) / 2; else if(dm->boldmode) textshift += (st->text_ascent - st->bold_ascent) / 2; foldicon(1, out->exposed, xmargin, out->y, out->height, out->y + (st->text_ascent - st->text_descent) / 2 + textshift, surface, st, out->highlighted); } else if(out->type == TYPE_EXPANDED) { textshift = 0; if(dm->ttmode) textshift += (st->text_ascent - st->fixed_ascent) / 2; else if(dm->italicmode) textshift += (st->text_ascent - st->italic_ascent) / 2; else if(dm->boldmode) textshift += (st->text_ascent - st->bold_ascent) / 2; foldicon(0, out->exposed, xmargin, out->y, out->height, out->y + (st->text_ascent - st->text_descent) / 2 + textshift, surface, st, out->highlighted); } x = xbase + shift; if(out->bullet == 0 && out->prespace > 0) { x += out->prespace * (dm->ttmode ? st->fixed_space_width : st->text_space_width); } if(out->import != NULL) { SDL_Rect dst; dst.x = x; dst.y = out->y + st->latexspaceabove; SDL_BlitSurface(out->import, NULL, surface, &dst); } else if(out->rule) { int width; SDL_Rect dst; width = sl->des_w * st->rulewidth / 100; dst.x = (sl->des_w - width) / 2; dst.y = out->y + st->rulespaceabove; dst.w = width; dst.h = st->ruleheight; SDL_FillRect(surface, &dst, colour->fills->item(st->rulecolour)); } else if(out->line == NULL) error("Impossible out->line in render.cpp"); else if(out->heading && strlen(out->line) > 0) { x = render_text(out->line, st->heading_font, st->headingcolour, surface, x, out->y + st->headspaceabove, 0); } else if(strlen(out->line) > 0) { svector *codes; char code; svector *v = split_string(out->line, &codes); const char *s; int link_text_colour_index; if(out->highlighted) link_text_colour_index = st->highlightcolour; else link_text_colour_index = st->linkcolour; for(int j = 0; j < v->count(); j++) { s = v->item(j); code = codes->item(j)[0]; if(strlen(s) > 0) { textshift = 0; if(dm->italicmode) { font = st->italic_font; textshift += st->text_ascent - st->italic_ascent; } else if(dm->boldmode) { font = st->bold_font; textshift += st->text_ascent - st->bold_ascent; } else if(dm->ttmode) { font = st->fixed_font; textshift += st->text_ascent - st->fixed_ascent; } else { font = st->text_font; } x = render_text(s, font, out->link == NULL ? dm->current_text_colour_index : link_text_colour_index, surface, x, out->y + textshift, out->link == NULL || !st->underlinelinks ? 0 : st->textsize); } if(code == '$') dm->ttmode = 1 - dm->ttmode; else if(code == '%') { if(codes->item(j)[1] == '\0') { dm->current_text_colour_index = st->textcolour; // Default } else { int colour_index; if(codes->item(j)[1] == '#') { colour_index = colour->search_add(codes->item(j) + 2); if(colour_index == -1) error("Incorrect hex colour %s", codes->item(j) + 1); } else { colour_index = colour->names->find(codes->item(j) + 1); if(colour_index == -1) error("Unknown colour <%s>", codes->item(j) + 1); } dm->current_text_colour_index = colour_index; } } else if(code == '*') { if(dm->ttmode == 0) dm->boldmode = 1 - dm->boldmode; else x = render_text("*", st->fixed_font, out->link == NULL ? dm->current_text_colour_index : link_text_colour_index, surface, x, out->y + st->text_ascent - st->fixed_ascent, out->link == NULL || !st->underlinelinks ? 0 : st->textsize); } else if(code == '/') { if(dm->ttmode == 0) dm->italicmode = 1 - dm->italicmode; else x = render_text("/", st->fixed_font, out->link == NULL ? dm->current_text_colour_index : link_text_colour_index, surface, x, out->y + st->text_ascent - st->fixed_ascent, out->link == NULL || !st->underlinelinks ? 0 : st->textsize); } } delete v; delete codes; } if(debug & DEBUG_BASELINES) { pixelColor(surface, xbase, out->y, colour->red_pen); pixelColor(surface, xbase - 1, out->y - 1, colour->red_pen); pixelColor(surface, xbase + 1, out->y + 1, colour->red_pen); pixelColor(surface, xbase - 1, out->y + 1, colour->red_pen); pixelColor(surface, xbase + 1, out->y - 1, colour->red_pen); } if(single_line) delete dm; else dm->lastshift = shift; }
int main (int argc, char ** argv) { int numloops = 0; int fpstimer; double a1, a2; tolerance_file_t * tol = get_tolerance ("colors.tol"); memset (tol, '\0', sizeof (tolerance_file_t)); int do_blob = -1; int do_text = -1; Uint8 mouse_button; SDL_Surface * image; SDL_Surface * image_2; SDL_Surface * screen; SDL_Surface * back = IMG_Load ("back.png"); SDL_Color white = {255, 255, 255}; SDL_Event event; char * jpeg_buff; char * jpeg_buff_2; int jpeg_buff_size; int jpeg_buff_size_2; int x, y; FILE * log_fp; blob * cam1_green; blob * cam1_red; blob * cam2_green; blob * cam2_red; blob * vision_targets = NULL; CvCapture * capture; CvCapture * capture_2; IplImage * cam_img; IplImage * cam_img_2; FILE * color_fp; if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) { SDL_Quit (); printf ("SDL Initialization failed\n"); exit (1); } if ((screen = SDL_SetVideoMode (800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN )) == NULL) { SDL_Quit (); printf ("Could not create output surface\n"); exit (1); } if (TTF_Init () == -1) { SDL_Quit (); printf ("TTF_Init: %s\n", TTF_GetError()); exit (1); } if (!(capture = cvCaptureFromCAM (0))) { SDL_Quit (); printf ("Failed to start capture\n"); exit (1); } if (!(capture_2 = cvCaptureFromCAM (1))) { SDL_Quit (); printf ("Failed to start capture\n"); exit (1); } int start = SDL_GetTicks (); int lastfps; TTF_Font * arial = TTF_OpenFont ("arial.ttf", 12); while (1) { fpstimer = SDL_GetTicks (); numloops++; if (fpstimer - start > 1000) { start = SDL_GetTicks (); lastfps = numloops; numloops = 0; } while (SDL_PollEvent (&event)) { switch (event.type) { case SDL_KEYDOWN: switch (event.key.keysym.sym) { case 'q': TTF_Quit (); SDL_Quit (); exit (0); break; case 'b': do_blob = -do_blob; break; case 'v': do_text = -do_text; break; case 'i': tol->cam1_green.blob_minlength++; break; case 'k': tol->cam1_green.blob_minlength--; break; case 'o': tol->cam1_green.blob_tolerance++; break; case 'l': tol->cam1_green.blob_tolerance--; break; case 'y': tol->cam1_red.blob_minlength++; break; case 'h': tol->cam1_red.blob_minlength--; break; case 'u': tol->cam1_red.blob_tolerance++; break; case 'j': tol->cam1_red.blob_tolerance--; break; case 'w': tol->cam2_green.blob_minlength++; break; case 's': tol->cam2_green.blob_minlength--; break; case 'e': tol->cam2_green.blob_tolerance++; break; case 'd': tol->cam2_green.blob_tolerance--; break; case 'r': tol->cam2_red.blob_minlength++; break; case 'f': tol->cam2_red.blob_minlength--; break; case 't': tol->cam2_red.blob_tolerance++; break; case 'g': tol->cam2_red.blob_tolerance--; break; case 'z': color_fp = fopen ("colors.tol", "wb"); fwrite (tol, sizeof (tolerance_file_t), 1, color_fp); fclose (color_fp); break; } break; case SDL_MOUSEBUTTONDOWN: mouse_button = SDL_GetMouseState (&x,&y); if (mouse_button & SDL_BUTTON(1)) { if (x > 352) { set_tracking (x, y, screen, &(tol->cam2_green)); } else { set_tracking (x, y, screen, &(tol->cam1_green)); } } else { if (x > 352) { set_tracking (x, y, screen, &(tol->cam2_red)); } else { set_tracking (x, y, screen, &(tol->cam1_red)); } } break; } } cam_img = cvQueryFrame (capture); image = ipl_to_surface (cam_img); cam_img_2 = cvQueryFrame (capture_2); image_2 = ipl_to_surface (cam_img_2); easy_blit (0, 0, back, screen); if (do_blob == 1) { cam1_green = find (image, &(tol->cam1_green)); cam1_red = find (image, &(tol->cam1_red)); cam2_green = find (image_2, &(tol->cam2_green)); cam2_red = find (image_2, &(tol->cam2_red)); vision_targets = target (cam1_red, cam1_green, ALLIANCE_BLUE); print_blobs_lighter (image, cam1_green, 0, 150, 0); print_blobs_lighter (image, cam1_red, 150, 0, 0); print_blobs_lighter (image_2, cam2_green, 0, 150, 0); print_blobs_lighter (image_2, cam2_red, 150, 0, 0); if (vision_targets != NULL) { render_text (screen, arial, 100, 490, "Found target!"); print_blobs (image, vision_targets, 0, 0, 0); free_blobs (vision_targets); } } if (do_text == 1) { render_text (screen, arial, 600, 308, "FPS: %d", (lastfps)); //print_blobs (image_2, cam2_red, 0, 0, 0); render_text (screen, arial, 10, 308, "Hotkey list:"); render_text (screen, arial, 20, 328, "i - increase left green blob minimum length: %d", tol->cam1_green.blob_minlength); render_text (screen, arial, 20, 348, "k - decrease left green blob minimum length"); render_text (screen, arial, 20, 368, "o - increase left green check tolerance: %d", tol->cam1_green.blob_tolerance); render_text (screen, arial, 20, 388, "l - decrease left green check tolerance"); render_text (screen, arial, 20, 408, "y - increase left red blob minimum length: %d", tol->cam1_red.blob_minlength); render_text (screen, arial, 20, 428, "h - decrease left red blob minimum length"); render_text (screen, arial, 20, 448, "u - increase left red check tolerance: %d", tol->cam1_red.blob_tolerance); render_text (screen, arial, 20, 468, "j - decrease left red check tolerance"); render_text (screen, arial, 50, 508, "Green check color: %d, %d, %d", tol->cam1_green.r, tol->cam1_green.g, tol->cam1_green.b); SPG_RectFilled (screen, 20, 500, 40, 520, SDL_MapRGB (screen->format, tol->cam1_green.r, tol->cam1_green.g, tol->cam1_green.b)); render_text (screen, arial, 50, 548, "Red check color: %d, %d, %d", tol->cam1_red.r, tol->cam1_red.g, tol->cam1_red.b); SPG_RectFilled (screen, 20, 540, 40, 560, SDL_MapRGB (screen->format, tol->cam1_red.r, tol->cam1_red.g, tol->cam1_red.b)); render_text (screen, arial, 320, 328, "w - increase right green blob minimum length: %d", tol->cam2_green.blob_minlength); render_text (screen, arial, 320, 348, "s - decrease right green blob minimum length"); render_text (screen, arial, 320, 368, "e - increase right green check tolerance: %d", tol->cam2_green.blob_tolerance); render_text (screen, arial, 320, 388, "d - decrease right green check tolerance"); render_text (screen, arial, 320, 408, "r - increase right red blob minimum length: %d", tol->cam2_red.blob_minlength); render_text (screen, arial, 320, 428, "f - decrease right red blob minimum length"); render_text (screen, arial, 320, 448, "t - increase right red check tolerance: %d", tol->cam2_red.blob_tolerance); render_text (screen, arial, 320, 468, "g - decrease right red check tolerance"); render_text (screen, arial, 350, 508, "Green check color: %d, %d, %d", tol->cam2_green.r, tol->cam2_green.g, tol->cam2_green.b); SPG_RectFilled (screen, 320, 500, 340, 520, SDL_MapRGB (screen->format, tol->cam2_green.r, tol->cam2_green.g, tol->cam2_green.b)); render_text (screen, arial, 350, 548, "Red check color: %d, %d, %d", tol->cam2_red.r, tol->cam2_red.g, tol->cam2_red.b); SPG_RectFilled (screen, 320, 540, 340, 560, SDL_MapRGB (screen->format, tol->cam2_red.r, tol->cam2_red.g, tol->cam2_red.b)); if ((cam1_green != NULL) && (cam2_green != NULL)) { a1 = image_angle (cam1_green->center_x); a2 = image_angle (cam2_green->center_x); render_text (screen, arial, 580, 348, "Image 1 centroid: %d, %d", cam1_green->center_x, cam1_green->center_y); render_text (screen, arial, 580, 368, "Image 2 centroid: %d, %d", cam2_green->center_x, cam2_green->center_y); render_text (screen, arial, 580, 388, "Depth, Method 1: %f", find_depth (a1, a2, 0)); render_text (screen, arial, 580, 408, "Depth, Method 2: %f", find_depth (a1, a2, 1)); render_text (screen, arial, 580, 428, "Depth, Method 3: %f", find_depth (a1, a2, 2)); render_text (screen, arial, 580, 448, "Angle, Left: %f", a1 * (180/PI)); render_text (screen, arial, 580, 468, "Angle, Right: %f", a2 * (180/PI)); SPG_RectFilled (screen, 780, (int)(35 * find_depth (a1, a2, 2)) - 300, 800, 20 + (int)(35 * find_depth (a1, a2, 1)) - 300, SDL_MapRGB (screen->format, tol->cam2_green.r, tol->cam2_green.g, tol->cam2_green.b)); } } if (do_blob == 1) { free_blobs (cam1_green); free_blobs (cam1_red); free_blobs (cam2_green); free_blobs (cam2_red); } easy_blit (0, 0, image, screen); easy_blit (352, 0, image_2, screen); SDL_FreeSurface (image); SDL_FreeSurface (image_2); SDL_Flip (screen); log_fp = fopen ("colors.tol", "wb"); fwrite (&tol, sizeof (tolerance_file_t), 1, log_fp); fclose (log_fp); } return 0; }
void render_background(slide *sl, SDL_Surface *surface) { SDL_Rect dst; style *st = sl->st; // Set slide area to the background colour: dst.x = 0; dst.y = 0; dst.w = sl->des_w; dst.h = sl->des_h; SDL_FillRect(surface, &dst, colour->fills->item(st->bgcolour)); // Fill in the titlebar area: if(st->enablebar) { dst.h = st->titlespacing - TITLE_EDGE; SDL_FillRect(surface, &dst, colour->fills->item(st->barcolour)); } // Draw background image or texture: if(st->background != NULL) { int src_w, src_h, dst_w, dst_h; SDL_Surface *scaled; SDL_Rect dst; // Scale background image to fit this slide: src_w = st->background->w; src_h = st->background->h; dst_w = sl->des_w; if(st->bgbar || !st->enablebar) { dst_h = sl->des_h; dst.y = 0; } else { dst_h = sl->des_h - (st->titlespacing - TITLE_EDGE); dst.y = st->titlespacing - TITLE_EDGE; } scaled = zoomSurface(st->background, (double)dst_w / (double)src_w, (double)dst_h / (double)src_h, 1); // Blit: dst.x = 0; SDL_BlitSurface(scaled, NULL, surface, &dst); SDL_FreeSurface(scaled); } else if(st->texture != NULL) { SDL_Rect dst; int w, h; int xrepeats, yrepeats; int vert_offset; w = st->texture->w; h = st->texture->h; if(st->bgbar || !st->enablebar) vert_offset = 0; else vert_offset = st->titlespacing - TITLE_EDGE; xrepeats = SCREEN_WIDTH / w; if(SCREEN_WIDTH % w > 0) xrepeats++; yrepeats = (SCREEN_HEIGHT - vert_offset) / h; if((SCREEN_HEIGHT - vert_offset) % h > 0) yrepeats++; for(int x = 0; x < xrepeats; x++) { for(int y = 0; y < yrepeats; y++) { dst.x = x * w; dst.y = vert_offset + y * h; SDL_BlitSurface(st->texture, NULL, surface, &dst); } } } // Draw the slide border: for(int i = 0; i < st->slideborder; i++) { rectangleColor(surface, i, i, sl->des_w - 1 - i, sl->des_h - 1 - i, colour->pens->item(st->bordercolour)); } // Draw dividing line between titlebar and slide body, and the slide title: if(st->enablebar) { char *title = sl->content->line; int xbase = st->leftmargin + st->foldmargin; for(int i = 0; i < st->barborder; i++) { hlineColor(surface, 1, sl->des_w - 2, st->titlespacing - TITLE_EDGE - 1 + i, colour->pens->item(st->bordercolour)); } render_text(title, st->title_font, colour->inks->item(st->titlecolour), surface, xbase, (st->titlespacing - TITLE_EDGE - (st->title_ascent - st->title_descent)) / 2 - 1 + st->topmargin); } }