/* ensure gl_tex_info returns non nil */ VALUE check_for_texture_info(VALUE image) { VALUE info; info = rb_funcall(image, rb_intern("gl_tex_info"), 0); if(NIL_P(info)) { VALUE image_name = rb_inspect(image); int width = FIX2INT(rb_funcall(image, rb_intern("width"), 0)); int height = FIX2INT(rb_funcall(image, rb_intern("height"), 0)); rb_raise(rb_eException, "Error: gl_tex_info returns nil for %s (%i x %i). Could be caused by " "very large image or Gosu bug. Try updating Gosu or use a smaller image. Note: TexPlay should" " be able to work with %i x %i images.", StringValuePtr(image_name), width, height, max_quad_size() - 2, max_quad_size() - 2); } return info; }
void Init_texplay() { VALUE jm_Module = rb_define_module("TexPlay"); VALUE TPPoint = rb_define_class_under(jm_Module, "TPPoint", rb_cObject); /** define basic point class TPPoint **/ rb_attr(TPPoint, rb_intern("x"), 1, 1, Qtrue); rb_attr(TPPoint, rb_intern("y"), 1, 1, Qtrue); rb_define_method(TPPoint, "initialize", m_init_TPPoint, -1); /** end of TPPoint definition **/ /* TexPlay methods */ rb_define_method(jm_Module, "paint", m_paint, -1); rb_define_method(jm_Module, "get_pixel", m_getpixel, -1); rb_define_method(jm_Module, "circle", m_circle, -1); rb_define_method(jm_Module, "line", m_line, -1); rb_define_method(jm_Module, "rect", m_rect, -1); rb_define_method(jm_Module, "pixel", m_pixel, -1); rb_define_method(jm_Module, "fill", m_flood_fill, -1); rb_define_method(jm_Module, "bezier", m_bezier, -1); rb_define_method(jm_Module, "polyline", m_polyline, -1); rb_define_method(jm_Module, "ngon", m_ngon, -1); rb_define_method(jm_Module, "splice", m_splice, -1); rb_define_method(jm_Module, "color", m_color, -1); rb_define_method(jm_Module, "offset", m_offset, -1); rb_define_method(jm_Module, "method_missing", m_missing, -1); rb_define_method(jm_Module, "quad_cached?", m_quad_cached, 0); rb_define_method(jm_Module, "each", m_each, -1); /* needs to be updated, not yet done **/ /* rb_define_method(jm_Module, "bitmask", m_bitmask, -1); */ /* rb_define_method(jm_Module, "leftshift", m_lshift, -1); */ /* rb_define_method(jm_Module, "rightshift", m_rshift, -1); */ /* rb_define_method(jm_Module, "[]=", m_special_pixel, -1); */ rb_define_method(jm_Module, "dup", m_dup_image, 0); rb_define_method(jm_Module, "clone", m_clone_image, 0); rb_define_method(jm_Module, "to_blob", m_to_blob, 0); rb_define_method(jm_Module, "force_sync", m_force_sync, 1); rb_define_method(jm_Module, "set_options", m_user_set_options, 1); rb_define_method(jm_Module, "get_options", m_get_options, 0); rb_define_method(jm_Module, "delete_options", m_user_delete_options, 0); rb_define_method(jm_Module, "refresh_cache", m_cache_refresh, 0); /* a constant containing the sidelength of largest allowable quad */ rb_define_const(jm_Module, "TP_MAX_QUAD_SIZE", INT2FIX(max_quad_size() - 2)); /* singleton method for creating & removing macros */ rb_define_singleton_method(jm_Module, "create_macro", M_create_macro, 1); rb_define_singleton_method(jm_Module, "remove_macro", M_remove_macro, 1); rb_define_singleton_method(jm_Module, "refresh_cache_all", M_refresh_cache_all, 0); /* rb_define_singleton_method(jm_Module, "create_blank_image", M_create_blank, 3); */ /** aliases; must be made on singleton class because we're using class methods **/ rb_define_method(jm_Module, "box", m_rect, -1); rb_define_method(jm_Module, "colour", m_color, -1); rb_define_method(jm_Module, "composite", m_splice, -1); rb_define_method(jm_Module, "set_pixel", m_pixel, -1); rb_define_method(jm_Module, "[]", m_getpixel, -1); rb_define_method(jm_Module, "cache", m_cache_refresh, 0); /** end of aliases **/ /** basic setup **/ /* seed the random number generator */ srand(time(NULL)); monkey_patch_gosu(); /** end basic setup **/ }