Example #1
0
File: load.c Project: mtmiron/lich
void
prompt_to_load_file()
{
	char msg[] = "Please select the map file you wish to load";
	char path[FILENAME_MAX * 6] = { "\0" };
	int result;

	mouse_callback = NULL;
	result = file_select_ex(msg, path, "txt", sizeof(path), 0, 0);
	if (!result)
	{
		if (nodelist != NULL && vector_len((vector_t*)nodelist) > 0)
			return;
		allegro_message("You did not select a file to load: there's nothing for the program to do.  Exiting.");
		exit(0);
	}

	if (debugging)
		fprintf(stderr, "%s\n", path);
	nodelist = load_file(path);

	render_image(screen);
	render_image(backbuffer);
	render_info(screen);
	render_info(backbuffer);
	strncpy(last_file, path, sizeof(last_file));
	mouse_callback = mouse_cb;
}
Example #2
0
void
rxvt_term::bg_render ()
{
  if (bg_flags & BG_INHIBIT_RENDER)
    return;

  delete bg_img;
  bg_img = 0;
  bg_flags = 0;

  if (!mapped)
    return;

# if BG_IMAGE_FROM_ROOT
  if (root_img)
    {
      render_root_image ();
      bg_flags |= BG_IS_TRANSPARENT;
    }
# endif

# if BG_IMAGE_FROM_FILE
  if (fimage.img)
    render_image (fimage);
# endif

  scr_recolour (false);
  bg_flags |= BG_NEEDS_REFRESH;

  bg_valid_since = ev::now ();
}
Example #3
0
void draw_execp(void *obj, cairo_t *c)
{
	Execp *execp = obj;
	PangoLayout *layout = pango_cairo_create_layout(c);

	if (execp->backend->has_icon && execp->backend->icon) {
		imlib_context_set_image(execp->backend->icon);
		// Render icon
		render_image(execp->area.pix, execp->frontend->iconx, execp->frontend->icony);
	}

	// draw layout
	pango_layout_set_font_description(layout, execp->backend->font_desc);
	pango_layout_set_width(layout, execp->frontend->textw * PANGO_SCALE);
	pango_layout_set_alignment(layout, execp->backend->centered ? PANGO_ALIGN_CENTER : PANGO_ALIGN_LEFT);
	pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
	pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_NONE);
	if (!execp->backend->has_markup)
		pango_layout_set_text(layout, execp->backend->text, strlen(execp->backend->text));
	else
		pango_layout_set_markup(layout, execp->backend->text, strlen(execp->backend->text));

	pango_cairo_update_layout(c, layout);
	draw_text(layout,
	          c,
	          execp->frontend->textx,
	          execp->frontend->texty,
	          &execp->backend->font_color,
	          panel_config.font_shadow);

	g_object_unref(layout);
}
void Instructions_State::render(){
	Widget_Gamestate::render();

	get_Video().set_2d(make_pair(Point2f(0.0f, 0.0f), Point2f(1920.0f, 1200.0f)), true);
	if(state == 0){
		render_image("Control_1", Point2f(0.0f,0.0f), Point2f(2048.0f,2048.0f));
	}
	if(state == 1){
		render_image("Control_2", Point2f(0.0f,0.0f), Point2f(2048.0f,2048.0f));
	}
	if(state == 2){
		render_image("Objective", Point2f(0.0f,0.0f), Point2f(2048.0f,2048.0f));
	}
	if(state == 3){
		render_image("World", Point2f(0.0f,0.0f), Point2f(2048.0f,2048.0f));
	}
	if(state == 4){
		render_image("HUD", Point2f(0.0f,0.0f), Point2f(2048.0f,2048.0f));
	}
	if(state == 5){
		render_image("Instructions", Point2f(0.0f,0.0f), Point2f(2048.0f,2048.0f));
	}
	if(state == 6){
		render_image("StillConfused", Point2f(0.0f,0.0f), Point2f(2048.0f,2048.0f));
	}
  
	render_controls(0);
}
void
um_user_image_set_user (UmUserImage *image,
                        ActUser     *user)
{
        g_clear_object (&image->priv->user);
        image->priv->user = g_object_ref (user);

        render_image (image);
}
Example #6
0
int tick()
{
  // In this case, just run once.
  render_image();
  
  trace("all done\n");
  
  return 0;
}
Example #7
0
void View::refresh() {
    
    if (!need_to_refresh()) return;
    
    // Refresh self. (First display image, then each child.)
    
    render_image(image, w, h, DispPoint(0,0));
    
    Subview_list_t::iterator child;
    for(child = children.begin(); child != children.end(); child++) {
        
        (*child)->refresh();
                
        render_image((*child)->display, (*child)->w, (*child)->h, (*child)->pos);
    }
    
    changed = false;
}
Example #8
0
void Thing::render(const String &texture, Point2f pos, Vector2f size, float rotation, Color tint) const {
  if (!noRender) {
    render_image(texture, 
                 Point2f(pos.x-(renderSize.x/2), pos.y-renderSize.y), 
                 Point2f(pos.x+(renderSize.x/2), pos.y), 
                 rotation,
                 1,
                 Point2f(pos.x, pos.y-size.y/2),
                 flipped, 
                 tint);
  }
}
Example #9
0
void
center_on_node(mapnode_t *nd)
{
	if (!nd)
		nd = selected_node;
	if (!nd)
		return;

	yoffset = screen->h/2 - nd->y;
	xoffset = screen->w/2 - nd->x;

	render_image(screen);
}
Example #10
0
/**
 * \brief Render a sprite with transformation (flip or mirror).
 * \param pos On screen position of the sprite.
 * \param s The sprite to draw.
 */
void bear::visual::gl_screen::render_sprite
( const position_type& pos, const sprite& s )
{
  if ( (s.clip_rectangle().width == 0) || (s.clip_rectangle().height == 0 ) )
    return;

  const claw::math::box_2d<GLdouble> clip_vertices = get_texture_clip(s);

  typedef claw::math::coordinate_2d<GLdouble> coord_double;

  coord_double render_coord[4];
  get_render_coord( pos, s, render_coord );

  render_image( render_coord, clip_vertices );
} // gl_screen::render_sprite()
Example #11
0
void systray_render_icon_from_image(TrayWindow *traywin)
{
	if (!traywin->image)
		return;
	imlib_context_set_image(traywin->image);
	XCopyArea(server.display,
			  render_background,
			  systray.area.pix,
			  server.gc,
			  traywin->x - systray.area.posx,
			  traywin->y - systray.area.posy,
			  traywin->width,
			  traywin->height,
			  traywin->x - systray.area.posx,
			  traywin->y - systray.area.posy);
	render_image(systray.area.pix, traywin->x - systray.area.posx, traywin->y - systray.area.posy);
}
Example #12
0
static void in_received_handler(DictionaryIterator *iter, void *ctx) {

   APP_LOG(APP_LOG_LEVEL_INFO, "Time flies!");

  Tuple *icon_tuple = dict_find(iter, WEATHER_ICON_KEY);

  if (icon_tuple) {
    render_image(icon_tuple->value->uint8, ctx);
  }

  Tuple *temp_tuple = dict_find(iter, WEATHER_TEMPERATURE_KEY);

  if (temp_tuple) {
    text_layer_set_text(temperature_layer, temp_tuple->value->cstring);
  }

}
Example #13
0
File: ctl.c Project: penma/feht2
void ctl_handle_fd(int fd) {
	/* zomfg hax */

	char command[5];
	memset(command, '\0', 5);
	read(fd, command, 4);

	if (!strcmp(command, "OPEN")) {
		char count;
		read(fd, &count, 1);

		char filename[256];
		read(fd, filename, count);
		filename[count] = '\0';

		fprintf(stderr, "loading image file: %s\n", filename);

		load_image(filename);
		render_image();
	} else {
		fprintf(stderr, "unknown command on ctl pipe: %s\n", command);
	}
}
void Team_Select_State::render() {
        Widget_Gamestate::render();

		render_image("Teamselect", Point2f(0.0f,0.0f), Point2f(1024.0f,1024.0f));
		get_Fonts()["system_36_800x600"].render_text("Player 1" ,Point2f(270, 30), Color(0x99FF1111));
		get_Fonts()["system_36_800x600"].render_text("Player 2" ,Point2f(750, 30), Color(0x99FF1111));
		get_Fonts()["system_36_800x600"].render_text("Player 3" ,Point2f(270, 330), Color(0x99FF1111));
		get_Fonts()["system_36_800x600"].render_text("Player 4" ,Point2f(750, 330), Color(0x99FF1111));

		for(int player_idx = 0; player_idx < 4; player_idx ++){

			render_image("Wanted",Point2f(-40.0f + player_render_offset[player_idx].x, 0.0f + player_render_offset[player_idx].y), Point2f(290.0f + player_render_offset[player_idx].x, 330.0f + player_render_offset[player_idx].y));

			if(player_state[player_idx] != 0){
				render_image("Snowball",Point2f(233.0f + player_render_offset[player_idx].x, 67.0f + 42.0f * player_cursor[player_idx] + player_render_offset[player_idx].y), Point2f(265.0f + player_render_offset[player_idx].x, 97.0f + 42.0f * player_cursor[player_idx] + player_render_offset[player_idx].y));
				get_Fonts()["cat"].render_text("Gender      > " + player_gender[player_idx] ,Point3f(265 + player_render_offset[player_idx].x, 72 + player_render_offset[player_idx].y, 0), Vector3f(0.28 ,0,0), Vector3f(0,0.28,0), Color(0x99FF1111));
				get_Fonts()["cat"].render_text("Team        > " + player_team[player_idx] ,Point3f(265 + player_render_offset[player_idx].x, 114 + player_render_offset[player_idx].y, 0), Vector3f(0.28 ,0,0), Vector3f(0,0.28,0), Color(0x99FF1111));
				get_Fonts()["cat"].render_text("Control     > " + player_control[player_idx] ,Point3f(265 + player_render_offset[player_idx].x, 156 + player_render_offset[player_idx].y, 0), Vector3f(0.28 ,0,0), Vector3f(0,0.28,0), Color(0x99FF1111));
				get_Fonts()["cat"].render_text("Sensitivity > " + itoa(player_sensitivity_state[player_idx]) ,Point3f(265 + player_render_offset[player_idx].x, 198 + player_render_offset[player_idx].y, 0), Vector3f(0.28 ,0,0), Vector3f(0,0.28,0), Color(0x99FF1111));
				render_image(player_gender[player_idx] + player_team[player_idx] + "Regular", Point2f(55 + player_render_offset[player_idx].x,125 + player_render_offset[player_idx].y),Point2f(188 + player_render_offset[player_idx].x,258 + player_render_offset[player_idx].y));
			}
			else
				render_image("Join",Point2f(250.0f + player_render_offset[player_idx].x, 100.0f + player_render_offset[player_idx].y), Point2f(400.0f + player_render_offset[player_idx].x, 250.0f + player_render_offset[player_idx].y));

			if(player_state[player_idx] >= 2){
				render_image("Ready",Point2f(100.0f + player_render_offset[player_idx].x, 70.0f + player_render_offset[player_idx].y), Point2f(430.0f + player_render_offset[player_idx].x, 400.0f + player_render_offset[player_idx].y));
			}
		}

		if(player_state[0] == 2)
			get_Fonts()["system_36_800x600"].render_text("P1 Press A to continue" ,Point2f(510, 568), Color(0xFF000000));

		if(loading){
			render_image("Loading", Point2f(0.0f,0.0f), Point2f(1024.0f,1024.0f));
			start_game += 1.0f;
		}


    }
Example #15
0
int
main (int argc, char **argv)
{
  int i;

  // 处理命令行参数,获取下列信息
  //    字库文件名
  //    显示字体象素大小
  //    分辨率
  //    是否使用灰度显示
  //    将显示的文本
  parse_args (argc, argv);

  // 初始化一个新的 FreeType 库对象 library
  error = FT_Init_FreeType (&library);
  if (error)
    fatal_error ("couldn't initialize FreeType library.");

  // 为字库文件 font_filename 中的第一种字体创建一个新的字体对象 face
  error = FT_New_Face (library, font_filename, 0, &face);
  if (error == FT_Err_Unknown_File_Format)
    fatal_error ("unsupported font format in file '%s'.", font_filename);
  else if (error)
    fatal_error ("unable to open input file '%s'.", font_filename);

  // 选择字体对象 face 中的 Unicode 字符码表为缺省码表
  error = FT_Select_Charmap (face, ft_encoding_unicode);
  if (error)
    fatal_error ("couldn't select Unicode charmap.");

  // 设置字体 face 的字符宽度和高度都为 pixel_size 个象素
  // 水平和垂直分辨率都为 resolution dpi
  error = FT_Set_Char_Size (face,
			    pixel_size * 64, pixel_size * 64,
			    resolution, resolution);
  if (error)
    fatal_error ("couldn't set character size: pixel size %d, resolution %d.",
		 pixel_size, resolution);

  // 把将显示的文本转换为 Unicode 编码
  text_to_unicode ();

  // 初始化 X 窗口
  init_display ();

  // 对以 Unicode 编码的文本中所有字符进行逐一处理
  for (i = 0; i < num_glyphs; i++)
    {
      // 生成第 i 个 Unicode 字符的字形图象的位图(单色图或灰度图)
      render_glyph (unicode_text[i], grayscale);

      // 生成第 i 个字形的 X 图象(XImage),并保存下列信息:
      //        字形位图的左边轴距
      //        字形位图的顶边轴距
      //        字形的水平步幅
      //        字形的垂直步幅
      render_image (i, face->glyph->bitmap.buffer,
		    face->glyph->bitmap.rows, face->glyph->bitmap.pitch,
		    face->glyph->bitmap_left, face->glyph->bitmap_top,
		    face->glyph->advance.x / 64, face->glyph->advance.y / 64,
		    grayscale);
    }

  // 在 X 窗口中,从位置 x = 0,y = pixel_size * resolution / 72
  // 开始画出文本的所有字符的图象
  draw_image (0, pixel_size * resolution / 72);

  // X 事件循环
  event_loop ();

  // 销毁字体对象 face 及它的所有子对象
  FT_Done_Face (face);

  // 销毁 FreeType 库对象 library 及它的所有后代
  FT_Done_FreeType (library);

  return 0;
}
Example #16
0
File: main.c Project: Zeirison/sway
void render(struct render_data *render_data) {
	int i;
	for (i = 0; i < render_data->surfaces->length; ++i) {
		sway_log(L_DEBUG, "Render surface %d of %d", i, render_data->surfaces->length);
		struct window *window = render_data->surfaces->items[i];
		if (!window_prerender(window) || !window->cairo) {
			continue;
		}

		// Reset the transformation matrix
		cairo_identity_matrix(window->cairo);

		if (render_data->num_images == 0 || render_data->color_set) {
			render_color(window, render_data->color);
		}

		if (render_data->num_images == -1) {
			// One background for all
			render_image(window, render_data->image, render_data->scaling_mode);
		} else if (render_data->num_images >= 1) {
			// Different backgrounds
			if (render_data->images[i] != NULL) {
				render_image(window, render_data->images[i], render_data->scaling_mode);
			}
		}

		// Reset the transformation matrix again
		cairo_identity_matrix(window->cairo);

		// Draw specific values (copied from i3)
		const int ARC_RADIUS = 50;
		const int ARC_THICKNESS = 10;
		const float TYPE_INDICATOR_RANGE = M_PI / 3.0f;
		const float TYPE_INDICATOR_BORDER_THICKNESS = M_PI / 128.0f;

		// Add visual indicator
		if (show_indicator && render_data->auth_state != AUTH_STATE_IDLE) {
			// Draw circle
			cairo_set_line_width(window->cairo, ARC_THICKNESS);
			cairo_arc(window->cairo, window->width/2, window->height/2, ARC_RADIUS, 0, 2 * M_PI);
			switch (render_data->auth_state) {
			case AUTH_STATE_INPUT:
			case AUTH_STATE_BACKSPACE: {
				cairo_set_source_rgba(window->cairo, 0, 0, 0, 0.75);
				cairo_fill_preserve(window->cairo);
				cairo_set_source_rgb(window->cairo, 51.0 / 255, 125.0 / 255, 0);
				cairo_stroke(window->cairo);
			} break;
			case AUTH_STATE_VALIDATING: {
				cairo_set_source_rgba(window->cairo, 0, 114.0 / 255, 255.0 / 255, 0.75);
				cairo_fill_preserve(window->cairo);
				cairo_set_source_rgb(window->cairo, 51.0 / 255, 0, 250.0 / 255);
				cairo_stroke(window->cairo);
			} break;
			case AUTH_STATE_INVALID: {
				cairo_set_source_rgba(window->cairo, 250.0 / 255, 0, 0, 0.75);
				cairo_fill_preserve(window->cairo);
				cairo_set_source_rgb(window->cairo, 125.0 / 255, 51.0 / 255, 0);
				cairo_stroke(window->cairo);
			} break;
			default: break;
			}

			// Draw a message
			char *text = NULL;
			cairo_set_source_rgb(window->cairo, 0, 0, 0);
			cairo_set_font_size(window->cairo, ARC_RADIUS/3.0f);
			switch (render_data->auth_state) {
			case AUTH_STATE_VALIDATING:
				text = "verifying";
				break;
			case AUTH_STATE_INVALID:
				text = "wrong";
				break;
			default: break;
			}

			if (text) {
				cairo_text_extents_t extents;
				double x, y;

				cairo_text_extents(window->cairo, text, &extents);
				x = window->width/2 - ((extents.width/2) + extents.x_bearing);
				y = window->height/2 - ((extents.height/2) + extents.y_bearing);

				cairo_move_to(window->cairo, x, y);
				cairo_show_text(window->cairo, text);
				cairo_close_path(window->cairo);
				cairo_new_sub_path(window->cairo);
			}

			// Typing indicator: Highlight random part on keypress
			if (render_data->auth_state == AUTH_STATE_INPUT || render_data->auth_state == AUTH_STATE_BACKSPACE) {
				static double highlight_start = 0;
				highlight_start += (rand() % (int)(M_PI * 100)) / 100.0 + M_PI * 0.5;
				cairo_arc(window->cairo, window->width/2, window->height/2, ARC_RADIUS, highlight_start, highlight_start + TYPE_INDICATOR_RANGE);
				if (render_data->auth_state == AUTH_STATE_INPUT) {
					cairo_set_source_rgb(window->cairo, 51.0 / 255, 219.0 / 255, 0);
				} else {
					cairo_set_source_rgb(window->cairo, 219.0 / 255, 51.0 / 255, 0);
				}
				cairo_stroke(window->cairo);

				// Draw borders
				cairo_set_source_rgb(window->cairo, 0, 0, 0);
				cairo_arc(window->cairo, window->width/2, window->height/2, ARC_RADIUS, highlight_start, highlight_start + TYPE_INDICATOR_BORDER_THICKNESS);
				cairo_stroke(window->cairo);

				cairo_arc(window->cairo, window->width/2, window->height/2, ARC_RADIUS, highlight_start + TYPE_INDICATOR_RANGE, (highlight_start + TYPE_INDICATOR_RANGE) + TYPE_INDICATOR_BORDER_THICKNESS);
				cairo_stroke(window->cairo);
			}

			// Draw inner + outer border of the circle
			cairo_set_source_rgb(window->cairo, 0, 0, 0);
			cairo_set_line_width(window->cairo, 2.0);
			cairo_arc(window->cairo, window->width/2, window->height/2, ARC_RADIUS - ARC_THICKNESS/2, 0, 2*M_PI);
			cairo_stroke(window->cairo);
			cairo_arc(window->cairo, window->width/2, window->height/2, ARC_RADIUS + ARC_THICKNESS/2, 0, 2*M_PI);
			cairo_stroke(window->cairo);
		}
		window_render(window);
	}
}
Example #17
0
int main() {
    long int screensize = 0;

    int fbfd;	/* frame buffer file descriptor */
    char* fbp;	/* pointer to framebuffer */
    int location;	/* iterate to location */

    int x, y;	/* x and y location */

    char pxtst[4];
    /* open the file for reading and writing */
    fbfd = open("/dev/fb0",O_RDWR);
    if (!fbfd) {
        printf("Error: cannot open framebuffer device.\n");
        exit(1);
    }
    printf ("The framebuffer device was opened successfully.\n");

    /* get the fixed screen information */
    if (ioctl (fbfd, FBIOGET_FSCREENINFO, &finfo)) {
        printf("Error reading fixed information.\n");
        exit(2);
    }

    /* get variable screen information */
    if (ioctl (fbfd, FBIOGET_VSCREENINFO, &vinfo)) {
        printf("Error reading variable information.\n");
        exit(3);
    }

    fprintf(stderr,"Framebuffer info:\n");
    fprintf(stderr,"XRes: %d\n",vinfo.xres);
    fprintf(stderr,"YRes: %d\n",vinfo.yres);
    /* figure out the size of the screen in bytes */
    //screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;

    /* map the device to memory */
    fbp = (char*)mmap(0, finfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fbfd, 0);

    if ((int)fbp == -1) {
        printf ("Error: failed to map framebuffer device to memory.\n");
        exit(4);
    }
    printf ("Framebuffer device was mapped to memory successfully.\n");

    // Figure out where in memory to put the pixel
    //    for ( y = 0; y < (768); y++ )
    //        for ( x = 0; x < 1024; x++ ) {
    //            location = (x+vinfo.xoffset) * (vinfo.bits_per_pixel/8) + (y+vinfo.yoffset) * finfo.line_length;
    //            if ( vinfo.bits_per_pixel == 32 ) {
    //                HEADER_PIXEL(header_data,pxtst);
    //                *(fbp + location) = pxtst[2]; // Some blue
    //                *(fbp + location + 1) = pxtst[1]; // A little green
    //                *(fbp + location + 2) = pxtst[0]; // A lot of red
    //                *(fbp + location + 3) = 0; // No transparency
    //            } else { //assume 16bpp
    //                int b = 10; int g = (x-100)/6; // A little green
    //                int r = 31-(y-100)/16; // A lot of red
    //                unsigned short int t = r<<11 | g << 5 | b;
    //                *((unsigned short int*)(fbp + location)) = t;
    //            }
    //        }

    render_image(fbp,0,0,img_testqwq_1024x768);
    render_image(fbp,500,800,img_icon_lock_48x48);
    //    render_string(fbp,0,600,font_ubuntumono_9x18,"Naive!!!233333333333!!! La la la Demacia!!! OwO QwQ OAO qwq qaq",0);
    //    render_string(fbp,0,618,font_ubuntumono_9x18,"Naive!!!233333333333!!! La la la Demacia!!! OwO QwQ OAO qwq qaq",1);
    //    render_string(fbp,0,636,font_ubuntumono_9x18,"Naive!!!233333333333!!! La la la Demacia!!! OwO QwQ OAO qwq qaq",2);
    //    render_string(fbp,0,654,font_ubuntumono_9x18,"Naive!!!233333333333!!! La la la Demacia!!! OwO QwQ OAO qwq qaq",3);
    render_string(fbp,0,800,font_ubuntumono_18x36,"Satori loves Koishi~",0);

    //    render_font(fbp,209,200,font_ubuntumono_9x18,'a');
    //    render_font(fbp,218,200,font_ubuntumono_9x18,'i');
    //    render_font(fbp,227,200,font_ubuntumono_9x18,'v');
    //    render_font(fbp,236,200,font_ubuntumono_9x18,'e');
    //    render_font(fbp,245,200,font_ubuntumono_9x18,'!');

    munmap(fbp, screensize);
    close(fbfd);

    return 0;
}
Example #18
0
    int
main(int argc, char *argv[])
{
    OSMesaContext ctx;
    void *buffer;

    if (argc < 3) {
        fprintf(stderr, "Usage:\n");
        fprintf(stderr, "  render modelname pngname [width height] [camx camy camz] [centerx centerz centerz] [upx upy upz] [fovy]\n");
        fprintf(stderr, "Default: width=%d height=%d cam=[%0.4f %0.4f %0.4f] center=[%0.4f %0.4f %0.4f] up=[%0.4f %0.4f %0.4f] fovy=%0.4f\n", Width, Height, camx, camy, camz, centerx, centery, centerz, upx, upy, upz, fovy);
        return 0;
    }

    modelname = argv[1];
    pngname = argv[2];

    if (argc >= 5) {
        Width = atoi(argv[3]);
        Height = atoi(argv[4]);
    }

    if (argc >= 8) {
        camx = atoi(argv[5]);
        camy = atoi(argv[6]);
        camz = atoi(argv[7]);
    }

    if (argc >= 11) {
        centerx = atoi(argv[8]);
        centery = atoi(argv[9]);
        centerz = atoi(argv[10]);
    }

    if (argc >= 14) {
        upx = atoi(argv[11]);
        upy = atoi(argv[12]);
        upz = atoi(argv[13]);
    }
        
    if (argc >= 15) {
        fovy = atoi(argv[14]);
    }

    if (!Import3DFromFile(modelname)) {
        fprintf(stderr, "model cannot be loaded!\n");
        return 0;
    }    

    /* Create an RGBA-mode context */
#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
    /* specify Z, stencil, accum sizes */
    ctx = OSMesaCreateContextExt( OSMESA_RGBA, 16, 0, 0, NULL );
#else
    ctx = OSMesaCreateContext( OSMESA_RGBA, NULL );
#endif
    if (!ctx) {
        printf("OSMesaCreateContext failed!\n");
        return 0;
    }

    /* Allocate the image buffer */
    buffer = malloc( Width * Height * 4 * sizeof(GLubyte) );
    if (!buffer) {
        printf("Alloc image buffer failed!\n");
        return 0;
    }

    /* Bind the buffer to the context and make it current */
    if (!OSMesaMakeCurrent( ctx, buffer, GL_UNSIGNED_BYTE, Width, Height )) {
        printf("OSMesaMakeCurrent failed!\n");
        return 0;
    }

    {
        int z, s, a;
        glGetIntegerv(GL_DEPTH_BITS, &z);
        glGetIntegerv(GL_STENCIL_BITS, &s);
        glGetIntegerv(GL_ACCUM_RED_BITS, &a);
        printf("Depth=%d Stencil=%d Accum=%d\n", z, s, a);
    }

    InitGL(Width, Height);
    render_image();

    if (pngname != NULL) {
        png::image< png::rgba_pixel > image(Width, Height);
        GLubyte * p_buffer = (GLubyte*)buffer;
        for (png::uint_32 y = 0; y < Height; ++y)
        {
            for (png::uint_32 x = 0; x < Width; ++x)
            {
                png::uint_32 r, g, b, a;
                r = *(p_buffer++);
                g = *(p_buffer++);
                b = *(p_buffer++);
                a = *(p_buffer++);
                image[Height-1-y][x] = png::rgba_pixel(r, g, b, a);
            }
        }
        image.write(pngname);
    }
    else {
        printf("Specify a filename if you want to make an image file\n");
    }

    printf("all done\n");

    /* free the image buffer */
    free( buffer );

    // *** cleanup ***
    textureIdMap.clear(); //no need to delete pointers in it manually here. (Pointers point to textureIds deleted in next step)
    textureName.clear(); //no need to delete pointers in it manually here. (Pointers point to textureIds deleted in next step)

    if (textureIds)
    {
        delete[] textureIds;
        textureIds = NULL;
    }

    /* destroy the context */
    OSMesaDestroyContext( ctx );

    return 0;
}
Example #19
0
File: main.c Project: actics/sway
int main(int argc, char **argv) {
	char *image_path = NULL;
	char *scaling_mode_str = "fit";
	uint32_t color = 0xFFFFFFFF;

	init_log(L_INFO);

	static struct option long_options[] = {
		{"help", no_argument, NULL, 'h'},
		{"color", required_argument, NULL, 'c'},
		{"image", required_argument, NULL, 'i'},
		{"scaling", required_argument, NULL, 's'},
		{"tiling", no_argument, NULL, 't'},
		{"version", no_argument, NULL, 'v'},
		{0, 0, 0, 0}
	};

	const char *usage =
		"Usage: swaylock [options...]\n"
		"\n"
		"  -h, --help                 Show help message and quit.\n"
		"  -c, --color <rrggbb[aa]>   Turn the screen into the given color instead of white.\n"
		"  -s, --scaling              Scaling mode: stretch, fill, fit, center, tile.\n"
		"  -t, --tiling               Same as --scaling=tile.\n"
		"  -v, --version              Show the version number and quit.\n"
		"  -i, --image <path>         Display the given image.\n";

	int c;
	while (1) {
		int option_index = 0;
		c = getopt_long(argc, argv, "hc:i:s:tv", long_options, &option_index);
		if (c == -1) {
			break;
		}
		switch (c) {
		case 'c': 
		{
			int colorlen = strlen(optarg);
			if (colorlen < 6 || colorlen == 7 || colorlen > 8) {
				fprintf(stderr, "color must be specified in 3 or 4 byte format, e.g. ff0000 or ff0000ff\n");
				exit(EXIT_FAILURE);
			}
			color = strtol(optarg, NULL, 16);

			if (colorlen == 6) {
				color <<= 8;
				color |= 0xFF;
			}
			sway_log(L_DEBUG, "color: 0x%x", color);
			break;
		}
		case 'i':
			image_path = optarg;
			break;
		case 's':
			scaling_mode_str = optarg;
			break;
		case 't':
			scaling_mode_str = "tile";
			break;
		case 'v':
#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE
			fprintf(stdout, "swaylock version %s (%s, branch \"%s\")\n", SWAY_GIT_VERSION, SWAY_VERSION_DATE, SWAY_GIT_BRANCH);
#else
			fprintf(stdout, "version not detected\n");
#endif
			exit(EXIT_SUCCESS);
			break;
		default:
			fprintf(stderr, "%s", usage);
			exit(EXIT_FAILURE);
		}
	}

	enum scaling_mode scaling_mode = SCALING_MODE_STRETCH;
	if (strcmp(scaling_mode_str, "stretch") == 0) {
		scaling_mode = SCALING_MODE_STRETCH;
	} else if (strcmp(scaling_mode_str, "fill") == 0) {
		scaling_mode = SCALING_MODE_FILL;
	} else if (strcmp(scaling_mode_str, "fit") == 0) {
		scaling_mode = SCALING_MODE_FIT;
	} else if (strcmp(scaling_mode_str, "center") == 0) {
		scaling_mode = SCALING_MODE_CENTER;
	} else if (strcmp(scaling_mode_str, "tile") == 0) {
		scaling_mode = SCALING_MODE_TILE;
	} else {
		sway_abort("Unsupported scaling mode: %s", scaling_mode_str);
	}

	password_size = 1024;
	password = malloc(password_size);
	password[0] = '\0';
	surfaces = create_list();
	registry = registry_poll();

	if (!registry) {
		sway_abort("Unable to connect to wayland compositor");
	}

	if (!registry->swaylock) {
		sway_abort("swaylock requires the compositor to support the swaylock extension.");
	}

	if (registry->pointer) {
		// We don't want swaylock to have a pointer
		wl_pointer_destroy(registry->pointer);
		registry->pointer = NULL;
	}

	int i;
	for (i = 0; i < registry->outputs->length; ++i) {
		struct output_state *output = registry->outputs->items[i];
		struct window *window = window_setup(registry, output->width, output->height, true);
		if (!window) {
			sway_abort("Failed to create surfaces.");
		}
		list_add(surfaces, window);
	}

	registry->input->notify = notify_key;

	cairo_surface_t *image = NULL;

	if (image_path) {
#ifdef WITH_GDK_PIXBUF
		GError *err = NULL;
		GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(image_path, &err);
		if (!pixbuf) {
			sway_abort("Failed to load background image.");
		}
		image = gdk_cairo_image_surface_create_from_pixbuf(pixbuf);
		g_object_unref(pixbuf);
#else
		cairo_surface_t *image = cairo_image_surface_create_from_png(argv[1]);
#endif //WITH_GDK_PIXBUF
		if (!image) {
			sway_abort("Failed to read background image.");
		}
	}

	for (i = 0; i < surfaces->length; ++i) {
		struct window *window = surfaces->items[i];
		if (!window_prerender(window) || !window->cairo) {
			continue;
		}
		if (image) {
			render_image(window, image, scaling_mode);
		} else {
			render_color(window, color);
		}
	}

	if (image) {
		cairo_surface_destroy(image);
	}

	bool locked = false;
	while (wl_display_dispatch(registry->display) != -1) {
		if (!locked) {
			for (i = 0; i < registry->outputs->length; ++i) {
				struct output_state *output = registry->outputs->items[i];
				struct window *window = surfaces->items[i];
				lock_set_lock_surface(registry->swaylock, output->output, window->surface);
			}
			locked = true;
		}
	}

	for (i = 0; i < surfaces->length; ++i) {
		struct window *window = surfaces->items[i];
		window_teardown(window);
	}
	list_free(surfaces);
	registry_teardown(registry);

	return 0;
}