static void create_bitmap(running_machine &machine, int player) { int x, y; char filename[20]; rgb_t color = crosshair_colors[player]; /* if we have a bitmap and texture for this player, kill it */ if (global.bitmap[player] == NULL) global.bitmap[player] = global_alloc(bitmap_argb32); machine.render().texture_free(global.texture[player]); emu_file crossfile(machine.options().crosshair_path(), OPEN_FLAG_READ); if (global.name[player][0] != 0) { /* look for user specified file */ sprintf(filename, "%s.png", global.name[player]); render_load_png(*global.bitmap[player], crossfile, NULL, filename); } else { /* look for default cross?.png in crsshair\game dir */ sprintf(filename, "cross%d.png", player + 1); render_load_png(*global.bitmap[player], crossfile, machine.system().name, filename); /* look for default cross?.png in crsshair dir */ if (!global.bitmap[player]->valid()) render_load_png(*global.bitmap[player], crossfile, NULL, filename); } /* if that didn't work, use the built-in one */ if (!global.bitmap[player]->valid()) { /* allocate a blank bitmap to start with */ global.bitmap[player]->allocate(CROSSHAIR_RAW_SIZE, CROSSHAIR_RAW_SIZE); global.bitmap[player]->fill(MAKE_ARGB(0x00,0xff,0xff,0xff)); /* extract the raw source data to it */ for (y = 0; y < CROSSHAIR_RAW_SIZE / 2; y++) { /* assume it is mirrored vertically */ UINT32 *dest0 = &global.bitmap[player]->pix32(y); UINT32 *dest1 = &global.bitmap[player]->pix32(CROSSHAIR_RAW_SIZE - 1 - y); /* extract to two rows simultaneously */ for (x = 0; x < CROSSHAIR_RAW_SIZE; x++) if ((crosshair_raw_top[y * CROSSHAIR_RAW_ROWBYTES + x / 8] << (x % 8)) & 0x80) dest0[x] = dest1[x] = MAKE_ARGB(0xff,0x00,0x00,0x00) | color; } } /* create a texture to reference the bitmap */ global.texture[player] = machine.render().texture_alloc(render_texture::hq_scale); global.texture[player]->set_bitmap(*global.bitmap[player], global.bitmap[player]->cliprect(), TEXFORMAT_ARGB32); }
void render_crosshair::create_bitmap() { int x, y; rgb_t color = m_player < ARRAY_LENGTH(crosshair_colors) ? crosshair_colors[m_player] : rgb_t::white(); // if we have a bitmap and texture for this player, kill it if (m_bitmap == nullptr) { m_bitmap = std::make_unique<bitmap_argb32>(); m_texture = m_machine.render().texture_alloc(render_texture::hq_scale); } emu_file crossfile(m_machine.options().crosshair_path(), OPEN_FLAG_READ); if (!m_name.empty()) { // look for user specified file std::string filename = m_name + ".png"; render_load_png(*m_bitmap, crossfile, nullptr, filename.c_str()); } else { // look for default cross?.png in crsshair/game dir std::string filename = string_format("cross%d.png", m_player + 1); render_load_png(*m_bitmap, crossfile, m_machine.system().name, filename.c_str()); // look for default cross?.png in crsshair dir if (!m_bitmap->valid()) render_load_png(*m_bitmap, crossfile, nullptr, filename.c_str()); } /* if that didn't work, use the built-in one */ if (!m_bitmap->valid()) { /* allocate a blank bitmap to start with */ m_bitmap->allocate(CROSSHAIR_RAW_SIZE, CROSSHAIR_RAW_SIZE); m_bitmap->fill(rgb_t(0x00,0xff,0xff,0xff)); /* extract the raw source data to it */ for (y = 0; y < CROSSHAIR_RAW_SIZE / 2; y++) { /* assume it is mirrored vertically */ u32 *dest0 = &m_bitmap->pix32(y); u32 *dest1 = &m_bitmap->pix32(CROSSHAIR_RAW_SIZE - 1 - y); /* extract to two rows simultaneously */ for (x = 0; x < CROSSHAIR_RAW_SIZE; x++) if ((crosshair_raw_top[y * CROSSHAIR_RAW_ROWBYTES + x / 8] << (x % 8)) & 0x80) dest0[x] = dest1[x] = rgb_t(0xff,0x00,0x00,0x00) | color; } } /* reference the new bitmap */ m_texture->set_bitmap(*m_bitmap, m_bitmap->cliprect(), TEXFORMAT_ARGB32); }
static void create_bitmap(running_machine *machine, int player) { int x, y; char filename[20]; rgb_t color = crosshair_colors[player]; /* if we have a bitmap for this player, kill it */ if (global.bitmap[player] != NULL) bitmap_free(global.bitmap[player]); if (global.name[player][0] != 0) { /* look for user specified file */ sprintf(filename, "%s.png", global.name[player]); global.bitmap[player] = render_load_png(OPTION_CROSSHAIRPATH, NULL, filename, NULL, NULL); } else { /* look for default cross?.png in crsshair\game dir */ sprintf(filename, "cross%d.png", player + 1); global.bitmap[player] = render_load_png(OPTION_CROSSHAIRPATH, machine->gamedrv->name, filename, NULL, NULL); /* look for default cross?.png in crsshair dir */ if (global.bitmap[player] == NULL) global.bitmap[player] = render_load_png(OPTION_CROSSHAIRPATH, NULL, filename, NULL, NULL); } /* if that didn't work, use the built-in one */ if (global.bitmap[player] == NULL) { /* allocate a blank bitmap to start with */ global.bitmap[player] = bitmap_alloc(CROSSHAIR_RAW_SIZE, CROSSHAIR_RAW_SIZE, BITMAP_FORMAT_ARGB32); bitmap_fill(global.bitmap[player], NULL, MAKE_ARGB(0x00,0xff,0xff,0xff)); /* extract the raw source data to it */ for (y = 0; y < CROSSHAIR_RAW_SIZE / 2; y++) { /* assume it is mirrored vertically */ UINT32 *dest0 = BITMAP_ADDR32(global.bitmap[player], y, 0); UINT32 *dest1 = BITMAP_ADDR32(global.bitmap[player], CROSSHAIR_RAW_SIZE - 1 - y, 0); /* extract to two rows simultaneously */ for (x = 0; x < CROSSHAIR_RAW_SIZE; x++) if ((crosshair_raw_top[y * CROSSHAIR_RAW_ROWBYTES + x / 8] << (x % 8)) & 0x80) dest0[x] = dest1[x] = MAKE_ARGB(0xff,0x00,0x00,0x00) | color; } } /* create a texture to reference the bitmap */ global.texture[player] = render_texture_alloc(render_texture_hq_scale, NULL); render_texture_set_bitmap(global.texture[player], global.bitmap[player], NULL, TEXFORMAT_ARGB32, NULL); }
static void load_effect_overlay(const char *filename) { char *tempstr = malloc_or_die(strlen(filename) + 5); int scrnum; char *dest; // append a .PNG extension strcpy(tempstr, filename); dest = strrchr(tempstr, '.'); if (dest == NULL) dest = &tempstr[strlen(tempstr)]; strcpy(dest, ".png"); // load the file effect_bitmap = render_load_png(NULL, tempstr, NULL, NULL); if (effect_bitmap == NULL) { fprintf(stderr, "Unable to load PNG file '%s'\n", tempstr); free(tempstr); return; } // set the overlay on all screens for (scrnum = 0; scrnum < MAX_SCREENS; scrnum++) if (Machine->drv->screen[scrnum].tag != NULL) render_container_set_overlay(render_container_get_screen(scrnum), effect_bitmap); free(tempstr); }
bgfx_texture* texture_manager::create_png_texture(std::string path, std::string file_name, std::string texture_name, uint32_t flags, uint32_t screen) { bitmap_argb32 bitmap; emu_file file(path.c_str(), OPEN_FLAG_READ); render_load_png(bitmap, file, nullptr, file_name.c_str()); if (bitmap.width() == 0 || bitmap.height() == 0) { printf("Unable to load PNG '%s' from path '%s'\n", path.c_str(), file_name.c_str()); return nullptr; } uint8_t *data = new uint8_t[bitmap.width() * bitmap.height() * 4]; uint32_t *data32 = reinterpret_cast<uint32_t *>(data); const uint32_t width = bitmap.width(); const uint32_t height = bitmap.height(); const uint32_t rowpixels = bitmap.rowpixels(); uint32_t* base = reinterpret_cast<uint32_t *>(bitmap.raw_pixptr(0)); for (int y = 0; y < height; y++) { copy_util::copyline_argb32(data32 + y * width, base + y * rowpixels, width, nullptr); } if (screen >= 0) { texture_name += std::to_string(screen); } bgfx_texture* texture = create_texture(texture_name, bgfx::TextureFormat::RGBA8, width, height, data, flags); delete [] data; return texture; }
static void crosshair_init(void) { input_port_entry *ipt; int player; /* determine who needs crosshairs */ crosshair_needed = 0x00; for (ipt = Machine->input_ports; ipt->type != IPT_END; ipt++) if (ipt->analog.crossaxis != CROSSHAIR_AXIS_NONE) crosshair_needed |= 1 << ipt->player; /* all visible by default */ crosshair_visible = crosshair_needed; /* loop over each player and load or create a bitmap */ for (player = 0; player < MAX_PLAYERS; player++) if (crosshair_needed & (1 << player)) { char filename[20]; /* first try to load a bitmap for the crosshair */ sprintf(filename, "cross%d.png", player); crosshair_bitmap[player] = render_load_png(NULL, filename, NULL, NULL); /* if that didn't work, make one up */ if (crosshair_bitmap[player] == NULL) { rgb_t color = crosshair_colors[player]; int x, y; /* allocate a blank bitmap to start with */ crosshair_bitmap[player] = bitmap_alloc_format(CROSSHAIR_RAW_SIZE, CROSSHAIR_RAW_SIZE, BITMAP_FORMAT_ARGB32); fillbitmap(crosshair_bitmap[player], MAKE_ARGB(0x00,0xff,0xff,0xff), NULL); /* extract the raw source data to it */ for (y = 0; y < CROSSHAIR_RAW_SIZE / 2; y++) { /* assume it is mirrored vertically */ UINT32 *dest0 = BITMAP_ADDR32(crosshair_bitmap[player], y, 0); UINT32 *dest1 = BITMAP_ADDR32(crosshair_bitmap[player], CROSSHAIR_RAW_SIZE - 1 - y, 0); /* extract to two rows simultaneously */ for (x = 0; x < CROSSHAIR_RAW_SIZE; x++) if ((crosshair_raw_top[y * CROSSHAIR_RAW_ROWBYTES + x / 8] << (x % 8)) & 0x80) dest0[x] = dest1[x] = MAKE_ARGB(0xff,0x00,0x00,0x00) | color; } } /* create a texture to reference the bitmap */ crosshair_texture[player] = render_texture_alloc(crosshair_bitmap[player], NULL, 0, TEXFORMAT_ARGB32, render_texture_hq_scale, NULL); } }