Exemplo n.º 1
0
  Font * Fonts::load(XML_Element_c &xml_element, const std::string &/*name*/, const std::string &/*filename*/) {
    const std::string filepath = xml_element["filepath"].to_string();
    const float height = xml_element["height"].to_float();
    const bool bold = xml_element["bold"].to_bool();
    const bool italics = xml_element["italics"].to_bool();

    const float screen_height = float(get_Video().get_screen_height());
    float virtual_screen_height = screen_height;
    XML_Element_c virtual_screen = xml_element["virtual_screen"];
    if(virtual_screen.good()) {
      XML_Element_c vsw = virtual_screen["width"];
      XML_Element_c vsh = virtual_screen["height"];

      if(vsw.good()) {
        const float vsw_ratio = vsw.to_float() / get_Video().get_screen_width();

        if(vsh.good()) {
          virtual_screen_height = vsh.to_float();

          if(vsw_ratio > virtual_screen_height / screen_height)
            virtual_screen_height = vsw_ratio * screen_height;
        }
        else
          virtual_screen_height = vsw_ratio * screen_height;
      }
      else if(vsh.good())
        virtual_screen_height = vsh.to_float();
    }

    return get_Video().create_Font(filepath, bold, italics, height, virtual_screen_height);
  }
Exemplo n.º 2
0
  bool Video::revert() {
    File_Ops &fo = get_File_Ops();

    const String appdata_path = fo.get_appdata_path();

    const String user_normal = appdata_path + "config/zenilib.xml";
    const String user_backup = user_normal + ".bak";
    const String local_normal = "config/zenilib.xml";
    const String local_backup = local_normal + ".bak";

    bool reverted = false;

    try {
      preinit_from_file(user_normal);
      get_Video();
      reverted = true;
    }
    catch(Video_Init_Failure &) {
    }

    if(!reverted && fo.copy_file(user_backup, user_normal) && fo.delete_file(user_backup)) {
      std::cerr << '\'' << user_normal << "' backup restored due to initialization failure.\n";
      try {
        Video::preinit_from_file(user_normal);
        get_Video();
        reverted = true;
      }
      catch(Video_Init_Failure &) {
      }
    }

    if(!reverted && fo.copy_file(local_backup, local_normal) && fo.delete_file(local_backup)) {
      std::cerr << '\'' << local_normal << "' backup restored due to initialization failure.\n";
      try {
        Video::preinit_from_file(local_normal);
        get_Video();
        reverted = true;
      }
      catch(Video_Init_Failure &) {
      }
    }

    if(!reverted) {
      std::cerr << '\'' << local_normal << "' backup restored due to initialization failure.\n";
      Video::set_failsafe_defaults();
      get_Video();
      reverted = true;
    }

    save(false);

    return true;
  }
Exemplo n.º 3
0
 Font_FT::Font_FT(const std::string &filepath,
                  const bool &bold, const bool &italic,
                  const float &glyph_height,
                  const float &virtual_screen_height)
   : Font(bold, italic, glyph_height,
          (virtual_screen_height < MINIMUM_VIRTUAL_SCREEN_HEIGHT ||
          virtual_screen_height > MAXIMUM_VIRTUAL_SCREEN_HEIGHT) ?
          float(get_Video().get_screen_height()) : virtual_screen_height,
          filepath),
   m_font_height(glyph_height),
   m_vratio(get_Video().get_screen_height() / get_virtual_screen_height())
 {
   init(filepath);
 }
  void Widget_Gamestate::render() {
    Video &vr = get_Video();

    vr.set_2d(m_virtual_window, m_fix_aspect_ratio);

    m_widgets.render();
  }
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);
}
Exemplo n.º 6
0
  Texture_DX9::Texture_DX9(const Point2i &size, const bool &repeat)
    : Texture(repeat),
    m_size(size),
    m_texture(0),
    m_render_to_surface(0)
  {
    Video_DX9 &vr = static_cast<Video_DX9 &>(get_Video());

    set_sampler_states(true);

    if(FAILED(Video_DX9::D3DXCreateTexture()(vr.get_d3d_device(),
                                             UINT(size.x), UINT(size.y),
                                             D3DX_DEFAULT,
                                             D3DUSAGE_RENDERTARGET | D3DUSAGE_AUTOGENMIPMAP,
                                             D3DFMT_A8R8G8B8,
                                             D3DPOOL_DEFAULT,
                                             &m_texture)))
    {
      throw Texture_Init_Failure();
    }

    if(FAILED(Video_DX9::D3DXCreateRenderToSurface()(vr.get_d3d_device(),
                                                     UINT(size.x), UINT(size.y),
                                                     D3DFMT_A8R8G8B8,
                                                     true,
                                                     D3DFMT_D16,
                                                     &m_render_to_surface)))
    {
      if(m_texture)
        m_texture->Release();

      throw Texture_Init_Failure();
    }
  }
Exemplo n.º 7
0
  void Crate_State::render() {
    Video &vr = get_Video();

    vr.set_3d(m_player.get_camera());

    m_crate.render();
	other_crate.render();
  }
Exemplo n.º 8
0
Play_State_Base::Play_State_Base(vector<Player_info*> *player_info_, Zeni::String level_,
			bool isLocalGame_, bool isServer_, RakNet::SystemAddress server_addr)	:
	player_info(player_info_), level(level_),
	m_prev_clear_color(get_Video().get_clear_Color()),	
	isLocal(isLocalGame_), isServer(isServer_), host_addr(server_addr)
{		
		set_pausable(false);
}
Exemplo n.º 9
0
  Fonts::Fonts()
    : Database<Font>("config/fonts.xml", "Fonts")
  {
    Video &vr = get_Video();

    Database<Font>::init();

    vr.lend_pre_uninit(&g_lose);
    vr.lend_post_reinit(&g_unlose);
  }
  void Widget_Gamestate::on_pop() {
    Video &vr = get_Video();

    vr.set_clear_color(m_clear_color);

    if(m_hide_cursor)
      vr.mouse_hide(true);

    if(m_grab_input)
      vr.mouse_grab(true);
  }
Exemplo n.º 11
0
  void Font_FT::render_text(const String &text, const Point2f &position, const Color &color, const JUSTIFY &justify) const {
    Video &vr = get_Video();
    const float &x = position.x;
    const float &y = position.y;

    const Color previous_color = vr.get_Color();

    vr.set_Color(color);
    vr.apply_Texture(*m_texture);

    float cx, x_diff, cy = y;
    size_t i = 0u;

NEXT_LINE:

    cx = x;
    x_diff = 0.0f;

    if(justify != ZENI_LEFT) {
      for(size_t j = i; j < text.size(); ++j) {
        if(text[j] == '\r' || text[j] == '\n' ||
          !m_glyph[int(text[j])])
          break;

        x_diff -= m_glyph[int(text[j])]->get_glyph_width();
      }

      if(justify == ZENI_CENTER)
        cx += x_diff / 2u;
      else if(justify == ZENI_RIGHT)
        cx += x_diff;
    }

    for(; i < text.size(); ++i) {
      if(text[i] == '\r' && i+1 < text.size() && text[i+1] == '\n')
        ++i;

      if(text[i] == '\r' || text[i] == '\n') {
        ++i;
        cy += m_font_height;
        goto NEXT_LINE;
      }
      else if(m_glyph[int(text[i])]) {
        m_glyph[int(text[i])]->render(vr, Point2f(cx, cy), m_vratio);
        cx += m_glyph[int(text[i])]->get_glyph_width();
      }
    }

    vr.unapply_Texture();

    vr.set_Color(previous_color);
  }
Exemplo n.º 12
0
  void Widget_Gamestate::on_pop() {
    get_Video().set_clear_Color(m_clear_color);

#ifndef ANDROID
    Window &wr = get_Window();

    if(m_hide_cursor)
      wr.mouse_hide(true);

    if(m_grab_input)
      wr.mouse_grab(true);
#endif
  }
Exemplo n.º 13
0
  void Console_State::render() {
    assert(m_child);

    m_child->render();

    Video &vr = get_Video();
    vr.clear_depth_buffer();
    vr.set_2d(m_virtual_screen);

    vr.render(m_bg);
    m_log.render();
    m_prompt.render();
  }
  void Widget_Gamestate::on_push() {
    Video &vr = get_Video();

    m_hide_cursor = vr.is_mouse_hidden();
    if(m_hide_cursor)
      vr.mouse_hide(false);

    m_grab_input = vr.is_mouse_grabbed();
    if(m_grab_input)
      vr.mouse_grab(false);

    m_clear_color = vr.get_clear_color();
  }
Exemplo n.º 15
0
  void Font_FT::render_text(const String &text, const Point3f &position, const Vector3f &right, const Vector3f &down, const Color &color, const JUSTIFY &justify) const {
    Video &vr = get_Video();

    const Color previous_color = vr.get_Color();

    vr.set_Color(color);
    vr.apply_Texture(*m_texture);

    Point3f pos, vertical_pos = position;
    float x_diff;
    size_t i = 0u;

NEXT_LINE_2:

    pos = vertical_pos;
    x_diff = 0.0f;

    if(justify != ZENI_LEFT) {
      for(size_t j = i; j < text.size(); ++j) {
        if(text[j] == '\r' || text[j] == '\n' ||
          !m_glyph[int(text[j])])
          break;

        x_diff -= m_glyph[int(text[j])]->get_glyph_width();
      }

      if(justify == ZENI_CENTER)
        pos += x_diff / 2.0f * right;
      else if(justify == ZENI_RIGHT)
        pos += x_diff * right;
    }

    for(; i < text.size(); ++i) {
      if(text[i] == '\r' && i+1 < text.size() && text[i+1] == '\n')
        ++i;

      if(text[i] == '\r' || text[i] == '\n') {
        ++i;
        vertical_pos += m_font_height * down;
        goto NEXT_LINE_2;
      }
      else if(m_glyph[int(text[i])]) {
        m_glyph[int(text[i])]->render(vr, pos, right, down);
        pos += m_glyph[int(text[i])]->get_glyph_width() * right;
      }
    }

    vr.unapply_Texture();

    vr.set_Color(previous_color);
  }
Exemplo n.º 16
0
  void Widget_Gamestate::on_push() {
#ifndef ANDROID
    Window &wr = get_Window();

    m_hide_cursor = wr.is_mouse_hidden();
    if(m_hide_cursor)
      wr.mouse_hide(false);

    m_grab_input = wr.is_mouse_grabbed();
    if(m_grab_input)
      wr.mouse_grab(false);
#endif

    m_clear_color = get_Video().get_clear_Color();
  }
Exemplo n.º 17
0
void Play_State_Base::on_pop()	{
	get_Window().mouse_hide(false);
	get_Window().mouse_grab(false);
	get_Video().set_clear_Color(m_prev_clear_color);
	get_Game().joy_mouse.enabled = true;
	Game_Model::get().clean();

	for (int i = 0 ; i < player_info->size() ; i++)
		delete player_info->at(i);
	delete player_info;

	for(int i = 0; i < controllers.size() ; i++)	{
		delete controllers[i];
	}
}
Exemplo n.º 18
0
  void Level_1::render() {
    Video &vr = get_Video();

    vr.set_3d(m_player.get_camera());

	m_floor.render();
    m_crate.render();
	m_crate1.render();
	m_crate2.render();

	for(list<Bullet *>::const_iterator it = m_bullets.begin(); it != m_bullets.end(); ++it)
	  (*it)->render();

	//HUD elements, for testing purposes
	vr.set_2d();
	//Vector3f temp = m_player.get_camera().get_forward();
	Vector3f temp = m_crate.get_velocity();
	String idir, jdir,kdir, playerBot, crateCenter, crateZ;

	std::string a = std::to_string(temp.x);
	idir = a;
	std::string b = std::to_string(temp.y);
	jdir = b;
	std::string c = std::to_string(temp.z);
	kdir = c;
/*
	get_Fonts()["title"].render_text("x: " + idir, Point2f(0.0f, 0.0f), Color());
	get_Fonts()["title"].render_text("y: " + jdir, Point2f(0.0f, 100.0f), Color());
	get_Fonts()["title"].render_text("z: " + kdir, Point2f(0.0f, 200.0f), Color());*/

	//if (!m_bullets.empty()){
	//Bullet * tb = m_bullets.front();
	//Point3f temp = tb->bodypos();
	//m_player.get_body().get_end_point_b().z > m_crate.get_body().get_center().z + m_crate.get_body().get_edge_c().k

	std::string d = std::to_string(m_player.get_body().get_end_point_b().z);
	playerBot = d;
	std::string e = std::to_string(m_crate.get_body().get_point().z);
	crateCenter = e;
	std::string f = std::to_string(m_crate.get_body().get_edge_c().k);
	crateZ = f;
	
	/*get_Fonts()["title"].render_text("playerBot: " + playerBot, Point2f(0.0f, 0.0f), Color());
	get_Fonts()["title"].render_text("createCenter: " + crateCenter, Point2f(0.0f, 100.0f), Color());
	get_Fonts()["title"].render_text("crateZ: " + crateZ, Point2f(0.0f, 200.0f), Color());*/
	
  }
Exemplo n.º 19
0
void Play_State_Base::on_push()	{
		get_Window().mouse_hide(true);
		get_Window().mouse_grab(true);
		get_Video().set_clear_Color(Color(0,.1,.1,.1));
		get_Game().joy_mouse.enabled = false;

		Game_Model::get().change_level(create_level(level.std_str()));
		Game_Model::get().start_up(*player_info);

		if(!isLocal)
			Game_Model::get().initialize_peer(isServer, host_addr);
				
		for(int i = 0; i < Game_Model::get().num_players_here() ; i++)	{
			controllers.push_back(new Controls(false, i));
			if(player_info->at(i)->controls_ == 1)
				controllers[i]->set_inverted(true);
			controllers[i]->set_input_sensitivity(player_info->at(i)->sensitivities_);
		}
}
Exemplo n.º 20
0
  void Texture_DX9::apply_Texture() const {
    Video_DX9 &vdx = static_cast<Video_DX9 &>(get_Video());
    
    vdx.get_d3d_device()->SetSamplerState(0, D3DSAMP_ADDRESSU, m_repeat ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP);
    vdx.get_d3d_device()->SetSamplerState(0, D3DSAMP_ADDRESSV, m_repeat ? D3DTADDRESS_WRAP : D3DTADDRESS_CLAMP);

    vdx.get_d3d_device()->SetTexture(0, m_texture);

    if(vdx.get_lighting()) {
      vdx.get_d3d_device()->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
      vdx.get_d3d_device()->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
    }
    else {
      vdx.get_d3d_device()->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
      vdx.get_d3d_device()->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR);
    }

    vdx.get_d3d_device()->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
    vdx.get_d3d_device()->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
  }
Exemplo n.º 21
0
  void Console_State::render() {
    assert(m_child);

    m_child->render();

    Video &vr = get_Video();

    const bool ztest = vr.is_ztest_enabled();
    if(ztest)
      vr.set_ztest(false);

    vr.set_2d(m_virtual_screen);

    vr.render(m_bg);
    m_log.render();
    m_prompt.render();

    if(ztest)
      vr.set_ztest(true);
  }
Exemplo n.º 22
0
  void render_image(
    const std::string &image_name,
    const Point2f &upper_left,
    const Point2f &lower_right,
    const bool &horizontally_flipped,
    const Color &color_filter) {

      float
        tx0 = horizontally_flipped ? 1.0f : 0.0f,
        tx1 = 1.0f - tx0;

      Material material(image_name, color_filter);

      Quadrilateral<Vertex2f_Texture> q( (Vertex2f_Texture(Point2f(upper_left.x, upper_left.y), Point2f(tx0, 0.0f))) ,
                                         (Vertex2f_Texture(Point2f(upper_left.x, lower_right.y), Point2f(tx0, 1.0f))) ,
                                         (Vertex2f_Texture(Point2f(lower_right.x, lower_right.y), Point2f(tx1, 1.0f))) ,
                                         (Vertex2f_Texture(Point2f(lower_right.x, upper_left.y), Point2f(tx1, 0.0f))) );
      q.lend_Material(&material);

      get_Video().render(q);
  }
Exemplo n.º 23
0
  void Texture_DX9::set_sampler_states(const bool &disable_mipmapping) {
    Video_DX9 &vr = static_cast<Video_DX9 &>(get_Video());
    
    if(Textures::get_anisotropic_filtering()) {
      if(Textures::get_anisotropic_filtering() < 0 || Textures::get_anisotropic_filtering() > vr.get_maximum_anisotropy())
        Textures::set_texturing_mode(vr.get_maximum_anisotropy(), Textures::get_bilinear_filtering(), Textures::get_mipmapping());

      vr.get_d3d_device()->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_ANISOTROPIC);
      vr.get_d3d_device()->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);
      vr.get_d3d_device()->SetSamplerState(0, D3DSAMP_MAXANISOTROPY, DWORD(Textures::get_anisotropic_filtering()));
    }
    else if(Textures::get_bilinear_filtering()) {
      vr.get_d3d_device()->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
      vr.get_d3d_device()->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
    }
    else {
      vr.get_d3d_device()->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
      vr.get_d3d_device()->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
    }

    vr.get_d3d_device()->SetSamplerState(0, D3DSAMP_MIPFILTER, (!disable_mipmapping && Textures::get_mipmapping() ? D3DTEXF_LINEAR : D3DTEXF_NONE));
  }
Exemplo n.º 24
0
  void render_image(
    const std::string &image_name,
    const Point2f &upper_left,
    const Point2f &lower_right,
    const float &radians_ccw,
    const float &scaling_factor,
    const Point2f &about,
    const bool &horizontally_flipped,
    const Color &color_filter) {

      const Point3f about3 = Point3f(about);

      Vector3f 
        ulv = Point3f(upper_left) - about3,
        llv = Point3f(upper_left.x, lower_right.y, 0.0f) - about3,
        lrv = Point3f(lower_right) - about3,
        urv = Point3f(lower_right.x, upper_left.y, 0.0f) - about3;

      ulv.set_spherical(ulv.theta() - radians_ccw, ulv.phi(), ulv.magnitude() * scaling_factor);
      llv.set_spherical(llv.theta() - radians_ccw, llv.phi(), llv.magnitude() * scaling_factor);
      lrv.set_spherical(lrv.theta() - radians_ccw, lrv.phi(), lrv.magnitude() * scaling_factor);
      urv.set_spherical(urv.theta() - radians_ccw, urv.phi(), urv.magnitude() * scaling_factor);

      const float
        tx0 = horizontally_flipped ? 1.0f : 0.0f,
        tx1 = 1.0f - tx0;

      Material material(image_name, color_filter);

      Vertex2f_Texture vt;
      Quadrilateral<Vertex2f_Texture> q( (Vertex2f_Texture(Point2f(about3 + ulv), Point2f(tx0, 0.0f))) ,
                                         (Vertex2f_Texture(Point2f(about3 + llv), Point2f(tx0, 1.0f))) ,
                                         (Vertex2f_Texture(Point2f(about3 + lrv), Point2f(tx1, 1.0f))) ,
                                         (Vertex2f_Texture(Point2f(about3 + urv), Point2f(tx1, 0.0f))) );
      q.lend_Material(&material);

      get_Video().render(q);
  }
Exemplo n.º 25
0
  IDirect3DTexture9 * Texture_DX9::build_from_Image(const Image &image) {
    Video_DX9 &vdx = dynamic_cast<Video_DX9 &>(get_Video());

    IDirect3DTexture9 * ppTexture;

    D3DFORMAT format;
    switch(image.color_space()) {
      case Image::Luminance:
        format = D3DFMT_L8;
        break;

      case Image::Luminance_Alpha:
        format = D3DFMT_A8B8G8R8;
        break;

      case Image::RGB:
        format = D3DFMT_A8B8G8R8;
        break;

      case Image::RGBA:
        format = D3DFMT_A8B8G8R8;
        break;

      default:
        format = D3DFMT_UNKNOWN;
        abort();
    }

    set_sampler_states();

    if(FAILED(Video_DX9::D3DXCreateTexture()(vdx.get_d3d_device(),
                                             UINT(image.width()), UINT(image.height()),
                                             D3DX_DEFAULT,
                                             0,
                                             format,
                                             D3DPOOL_MANAGED,
                                             &ppTexture)))
      throw Texture_Init_Failure();

    D3DLOCKED_RECT rect;
    if(FAILED(ppTexture->LockRect(0, &rect, 0, 0))) {
      ppTexture->Release();
      throw Texture_Init_Failure();
    }

    if(image.color_space() == Image::Luminance) {
      memcpy(rect.pBits, image.get_data(), image.width() * image.height());
    }
    else if(image.color_space() == Image::Luminance_Alpha) {
      Uint8 * dest = reinterpret_cast<Uint8 *>(rect.pBits);
      const Uint8 * src = image.get_data();
      for(Uint8 * const dest_end = dest + image.width() * image.height() * 4; dest != dest_end; dest += 4, src += 2) {
        dest[0] = src[0];
        dest[1] = src[0];
        dest[2] = src[0];
        dest[3] = src[1];
      }
    }
    else if(image.color_space() == Image::RGB) {
      Uint8 * dest = reinterpret_cast<Uint8 *>(rect.pBits);
      const Uint8 * src = image.get_data();
      for(Uint8 * const dest_end = dest + image.width() * image.height() * 4; dest != dest_end; dest += 4, src += 3) {
        dest[0] = src[2];
        dest[1] = src[1];
        dest[2] = src[0];
        dest[3] = 0xFF;
      }
    }
    else /*if(image.color_space() == Image::RGBA)*/ {
      Uint8 * dest = reinterpret_cast<Uint8 *>(rect.pBits);
      const Uint8 * src = image.get_data();
      for(Uint8 * const dest_end = dest + image.width() * image.height() * 4; dest != dest_end; dest += 4, src += 4) {
        dest[0] = src[2];
        dest[1] = src[1];
        dest[2] = src[0];
        dest[3] = src[3];
      }
    }

    if(FAILED(ppTexture->UnlockRect(0))) {
      ppTexture->Release();
      throw Texture_Init_Failure();
    }

    if(FAILED(Video_DX9::D3DXFilterTexture()(ppTexture, 0, D3DX_DEFAULT, D3DX_DEFAULT))) {
      ppTexture->Release();
      throw Texture_Init_Failure();
    }

    return ppTexture;
  }
Exemplo n.º 26
0
  GLuint Texture_GL::build_from_Image(const Image &image) {
    GLuint texture_id = 0;
    
    const GLenum format =
      image.color_space() == Image::Luminance ? GL_LUMINANCE :
      image.color_space() == Image::Luminance_Alpha ? GL_LUMINANCE_ALPHA :
      image.color_space() == Image::RGB ? GL_RGB :
      GL_RGBA;

    int bit_count = 0;
    for(int bit = 1; bit; bit <<= 1)
      bit_count += ((image.width() & bit) != 0) + ((image.height() & bit) != 0);
    if(bit_count != 2) {
      ZENI_LOGE("Dimensions of textures must be powers of 2.");
      throw Texture_Init_Failure();
    }

    glGenTextures(1, &texture_id);
    if(!texture_id) {
      ZENI_LOGE("glGenTextures(...) failed.");
      throw Texture_Init_Failure();
    }

    glBindTexture(GL_TEXTURE_2D, texture_id);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, image.tileable() ? GL_REPEAT : GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, image.tileable() ? GL_REPEAT : GL_CLAMP_TO_EDGE);

    if(glGetError() == GL_INVALID_ENUM) {
      static bool printed = false;
      if(!printed) {
        ZENI_LOGW("Quality Warning:  Your graphics card does not support GL_CLAMP_TO_EDGE in OpenGL.");
        printed = true;
      }
    }

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, Textures::get_bilinear_filtering() ? GL_LINEAR : GL_NEAREST);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
      Textures::get_mipmapping() ?
      (Textures::get_bilinear_filtering() ? GL_LINEAR_MIPMAP_LINEAR : GL_NEAREST_MIPMAP_NEAREST) :
      (Textures::get_bilinear_filtering() ? GL_LINEAR : GL_NEAREST));

#ifndef REQUIRE_GL_ES
    if(Textures::get_anisotropic_filtering()) {
      if(Textures::get_anisotropic_filtering() < 0 || Textures::get_anisotropic_filtering() > get_Video().get_maximum_anisotropy())
        Textures::set_texturing_mode(get_Video().get_maximum_anisotropy(), Textures::get_bilinear_filtering(), Textures::get_mipmapping());

      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, Textures::get_anisotropic_filtering());
    }
#endif

    /*
    glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
    glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
    glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
    glHint(GL_FOG_HINT, GL_NICEST);
    */
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

    if(
#ifndef REQUIRE_GL_ES
      GLEW_VERSION_1_4 &&
#endif
      Textures::get_mipmapping())
    {
      glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
    }
#ifndef REQUIRE_GL_ES
    if(GLEW_VERSION_1_4 || !Textures::get_mipmapping())
#endif
    {
      glTexImage2D(GL_TEXTURE_2D, 0, format, image.width(), image.height(), 0, format, GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(image.get_data()));
    }
#ifndef REQUIRE_GL_ES
    else {
      Zeni::gluBuild2DMipmaps(GL_TEXTURE_2D, format, image.width(), image.height(), format, GL_UNSIGNED_BYTE, static_cast<const GLvoid *>(image.get_data()));
    }
#endif

    return texture_id;
  }
Exemplo n.º 27
0
  Video * Video::create() {
    Video * video = 0;

    File_Ops &fo = get_File_Ops();

    const String appdata_path = fo.get_appdata_path();

    const String user_normal = appdata_path + "config/zenilib.xml";
    const String user_backup = user_normal + ".bak";
    const String local_normal = "config/zenilib.xml";
    const String local_backup = local_normal + ".bak";

    static bool last_resort_taken = false;

#ifndef ANDROID
    try
#endif
    {
      switch(Video::g_video_mode) {
      case Video::ZENI_VIDEO_ANY:
#ifndef DISABLE_DX9
      case Video::ZENI_VIDEO_DX9:
        video = new Video_DX9();
        break;
#endif
#ifndef DISABLE_GL
      case Video::ZENI_VIDEO_GL:
        video = new Video_GL();
        break;
#endif
      default:
        throw Video_Init_Failure();
      }
    }
#ifndef ANDROID
    catch(Video_Init_Failure &) {
      if(fo.copy_file(user_backup, user_normal) && fo.delete_file(user_backup)) {
        std::cerr << '\'' << user_normal << "' backup restored due to initialization failure.\n";
        Video::preinit_from_file(user_normal);
        get_Video();
      }
      else if(fo.copy_file(local_backup, local_normal) && fo.delete_file(local_backup)) {
        std::cerr << '\'' << local_normal << "' backup restored due to initialization failure.\n";
        Video::preinit_from_file(local_normal);
        get_Video();
      }
      else if(!last_resort_taken) {
        Video::set_failsafe_defaults();

        last_resort_taken = true;

        get_Video();
      }
      else
        throw;
    }
#endif

    last_resort_taken = false;

    return video;
  }
Exemplo n.º 28
0
  void Widget_Gamestate::perform_logic() {
    m_viewport = get_Video().calculate_viewport(m_virtual_window, std::make_pair(Point2i(), get_Window().get_size()), m_fix_aspect_ratio);
    m_projector = Projector2D(m_virtual_window, m_viewport);

    m_widgets.perform_logic();
  }
Exemplo n.º 29
0
  void Font_FT::init(const String &filepath) {
    TTF_Font *font = TTF_OpenFont(filepath.c_str(), int(get_text_height() * m_vratio + 0.5f));
    if(!font)
      throw Font_Init_Failure();

    /*** Set Style ***/

    if(is_bold() && is_italic())
      TTF_SetFontStyle(font, TTF_STYLE_BOLD | TTF_STYLE_ITALIC);
    else if(is_bold())
      TTF_SetFontStyle(font, TTF_STYLE_BOLD);
    else if(is_italic())
      TTF_SetFontStyle(font, TTF_STYLE_ITALIC);

    /*** Determine Width & Height ***/

    float font_width = 0;
    float font_height = 0;
    SDL_Color color2 = {0xFF, 0xFF, 0xFF, 0xFF};
    SDL_Surface *source[256] = {0};
    for(unsigned char c = 1; c; ++c) {
      Core::assert_no_error();
      //char t[2] = {c, '\0'};
      //source[c] = TTF_RenderText_Blended(font, t, color2);
      source[c] = TTF_RenderGlyph_Blended(font, c, color2);
      Core::print_error();
      font_width = std::max(font_width, float(source[c] ? source[c]->w : 0));
      font_height = std::max(font_height, float(source[c] ? source[c]->h : 0));
    }

    /*** Initialize Intermediate SDL Surface ***/

    const int 
      next_w = int(pow(2.0f, ceil(log(float(16 * font_width))/log(2.0f)))), 
      next_h = int(pow(2.0f, ceil(log(float(16 * font_height))/log(2.0f))));
  
    SDL_Surface *font_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, next_w, next_h, 32, source[END_OF_TIME]->format->Rmask, source[END_OF_TIME]->format->Gmask, source[END_OF_TIME]->format->Bmask, source[END_OF_TIME]->format->Amask);
    if(!font_surface) {
      for(unsigned char c = 1; c; ++c)
        SDL_FreeSurface(source[c]);
      TTF_CloseFont(font);

      if(next_h > 1024) {
        m_vratio /= 2.0f;
        init(filepath);
        return;
      }
      else
        throw Font_Init_Failure();
    }

    SDL_LockSurface(font_surface);
    SDL_FillRect(font_surface, 0, SDL_MapRGBA(font_surface->format, 0, 0, 0, SDL_ALPHA_TRANSPARENT));
    SDL_UnlockSurface(font_surface);

    /*** Initialize Glyphs ***/

    SDL_Rect dstrect = {0, 0, Uint16(font_width), Uint16(font_height)};
    m_glyph[0] = 0;
    for(unsigned char c = 1; c; ++c) {
      dstrect.x = Sint16((c % 16) * font_width);
      dstrect.y = Sint16((c / 16) * font_height);
      m_glyph[c] = new Glyph(font, c, source[c], font_surface, dstrect, next_w, next_h, m_vratio);
    }

    /*** Correct Transparency ***/

    const Uint32 transparent_white = font_surface->format->Rmask | font_surface->format->Gmask | font_surface->format->Bmask;
    for(int i = 0; i < font_surface->h; ++i)
      for(Uint32 * src = reinterpret_cast<Uint32 *>(font_surface->pixels) + i * font_surface->pitch / 4,
                 * src_end = src + font_surface->w;
          src != src_end;
          ++src)
        if(*src & font_surface->format->Rmask)
          *src = transparent_white | ((*src & font_surface->format->Rmask) >> font_surface->format->Rshift << font_surface->format->Ashift);

    /*** Initialize Final Texture ***/
    
    m_texture = get_Video().create_Texture(font_surface, false);

    TTF_CloseFont(font);
  }
 void Widget_Gamestate::perform_logic() {
   m_projector = Projector2D(m_virtual_window, get_Video().get_viewport());
 }