我正在使用 SLD2 板条箱来创建一个简单的物理模拟/引擎。我想使用
"gfx"
功能来获取帧率和绘图图元。我知道我需要在 "SDL2_gfx.lib"
中包含 C:\Users\{Your Username}\.rustup\toolchains\{current toolchain}\lib\rustlib\{current toolchain}\lib
文件,就像 "SLD2.lib"
安装一样。问题是我找不到所需的"SDL2_gfx.lib"
文件。文档将我定向到这个 gfx 下载源。但是,我似乎无法在该文件夹中找到任何 ".lib"
文件。我尝试使用 Visual Studio Code 构建 "SLD2_gfx"
解决方案(位于所述文件夹中)以获取 ".lib"
文件,但由于缺少头文件而失败。我不熟悉 C/C++ 或 Visual Studio Code,所以我也无法修复解决方案。我怎样才能得到"SDL2_gfx.lib"
文件和/或相关的".dll"
文件?
这是我到目前为止的代码:
use sdl2::{pixels::Color, event::Event, keyboard::Keycode, rect::{Rect, Point}};
use sdl2::gfx::*;
const WIDTH: u32 = 1000;
const HEIGHT: u32 = 700;
const RECT_SIZE: u32 = 30;
pub fn main() {
let sdl_context = sdl2::init().unwrap();
let video_subsystem = sdl_context.video().unwrap();
let window = video_subsystem.window("Physics Sim", WIDTH, HEIGHT)
.position_centered()
.build()
.unwrap();
let width = window.size().0;
let height = window.size().1;
let mut canvas = window.into_canvas().build().unwrap();
canvas.set_draw_color(Color::RGB(0, 0, 0));
canvas.clear();
canvas.present();
let mut event_pump = sdl_context.event_pump().unwrap();
let mut i = 0;
let mut rect = Rect::from_center(Point::new(width as i32 / 4, height as i32 / 4), RECT_SIZE, RECT_SIZE);
let rect_border_width = 1;
'running: loop {
i = (i + 1) % 255;
canvas.set_draw_color(Color::RGB(0, 0, 0));
canvas.clear();
// Inside of rect
canvas.set_draw_color(Color::RGB(i, 64, 255 - i));
canvas.fill_rect(rect).unwrap();
// Border of rect
canvas.set_draw_color(Color::RGB(255, 255, 255));
canvas.draw_rect(rect).unwrap();
for event in event_pump.poll_iter() {
match event {
Event::Quit {..} |
Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
break 'running
},
_ => {}
}
}
// game loop
let rect_y = rect.y();
if rect_y + rect_border_width + RECT_SIZE as i32 <= height as i32 {
rect.set_y(rect_y);
}
canvas.present();
::std::thread::sleep(std::time::Duration::new(0, 1_000_000_000u32 / 60));
} }
Cargo.toml
:
[dependencies]
sdl2 = {version = "0.35.2", default-features = false, features = ["gfx"]}
我得到的错误:
note: LINK : fatal error LNK1181: cannot open input file 'SDL2_gfx.lib'