Skip to content
2 changes: 1 addition & 1 deletion examples/blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl Stage {

let bindings = Bindings {
vertex_buffers: vec![vertex_buffer],
index_buffer: index_buffer,
index_buffer,
images: vec![],
};

Expand Down
58 changes: 58 additions & 0 deletions examples/drag_drop_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
use miniquad::*;

struct Stage {
ctx: GlContext,
dropped_files: Vec<String>,
}

impl EventHandler for Stage {
fn update(&mut self) {}

fn draw(&mut self) {
// Clear the screen with a dark blue color
self.ctx.clear(Some((0.1, 0.1, 0.3, 1.0)), None, None);

// Note: miniquad doesn't have built-in text rendering
// In a real application, you would use a text rendering library
// For now, this just clears the screen and responds to file drops
}

fn files_dropped_event(&mut self) {
println!("Files dropped!");
self.dropped_files.clear();

let count = window::dropped_file_count();
println!("Number of dropped files: {count}");

for i in 0..count {
if let Some(path) = window::dropped_file_path(i) {
let path_str = path.to_string_lossy().to_string();
println!("Dropped file {i}: {path_str}");
self.dropped_files.push(path_str);

if let Some(bytes) = window::dropped_file_bytes(i) {
println!(" Size: {} bytes", bytes.len());
}
}
}

println!("Check the console output above to see the dropped files!");
}
}

fn main() {
miniquad::start(
conf::Conf {
window_title: "Drag and Drop Test".to_string(),
window_width: 800,
window_height: 600,
..Default::default()
},
|| {
Box::new(Stage {
ctx: GlContext::new(),
dropped_files: Vec::new(),
})
},
);
}
6 changes: 3 additions & 3 deletions examples/instancing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl Stage {
let geometry_vertex_buffer = ctx.new_buffer(
BufferType::VertexBuffer,
BufferUsage::Immutable,
BufferSource::slice(&vertices),
BufferSource::slice(vertices),
);

#[rustfmt::skip]
Expand All @@ -46,7 +46,7 @@ impl Stage {
let index_buffer = ctx.new_buffer(
BufferType::IndexBuffer,
BufferUsage::Immutable,
BufferSource::slice(&indices),
BufferSource::slice(indices),
);

// empty, dynamic instance data vertex buffer
Expand All @@ -58,7 +58,7 @@ impl Stage {

let bindings = Bindings {
vertex_buffers: vec![geometry_vertex_buffer, positions_vertex_buffer],
index_buffer: index_buffer,
index_buffer,
images: vec![],
};

Expand Down
69 changes: 69 additions & 0 deletions examples/monitor_metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
use miniquad::*;

struct Stage {
ctx: GlContext,
}

impl EventHandler for Stage {
fn update(&mut self) {}

fn draw(&mut self) {
self.ctx.clear(Some((0.0, 0.0, 0.0, 1.0)), None, None);

// Print monitor information every 60 frames (approximately once per second at 60fps)
static mut FRAME_COUNT: u32 = 0;
unsafe {
FRAME_COUNT += 1;
if FRAME_COUNT % 60 == 0 {
println!("=== Monitor Information ===");

// Primary monitor
let primary = window::primary_monitor();
println!("Primary Monitor:");
println!(" Name: {:?}", primary.name);
println!(" Size: {}x{}", primary.width, primary.height);
println!(" Position: {:?}", primary.position);
println!(" DPI Scale: {}", primary.dpi_scale);
println!(" Refresh Rate: {:?}", primary.refresh_rate);

// Current monitor (where the window is displayed)
let current = window::current_monitor();
println!("\nCurrent Monitor (where window is displayed):");
println!(" Name: {:?}", current.name);
println!(" Size: {}x{}", current.width, current.height);
println!(" Position: {:?}", current.position);
println!(" DPI Scale: {}", current.dpi_scale);
println!(" Refresh Rate: {:?}", current.refresh_rate);

// All monitors
let monitors = window::monitors();
println!("\nAll Monitors ({} total):", monitors.len());
for (i, monitor) in monitors.iter().enumerate() {
println!(" Monitor {}:", i + 1);
println!(" Name: {:?}", monitor.name);
println!(" Size: {}x{}", monitor.width, monitor.height);
println!(" Position: {:?}", monitor.position);
println!(" DPI Scale: {}", monitor.dpi_scale);
println!(" Refresh Rate: {:?}", monitor.refresh_rate);
}

// Compare with window metrics
let window_metrics = window::screen_metrics();
println!("\nWindow Metrics (for comparison):");
println!(" Size: {}x{}", window_metrics.width, window_metrics.height);
println!(" Position: {:?}", window_metrics.position);
println!(" DPI Scale: {}", window_metrics.dpi_scale);
println!(" High DPI: {}", window_metrics.high_dpi);
println!("---");
}
}
}
}

fn main() {
miniquad::start(conf::Conf::default(), || {
Box::new(Stage {
ctx: GlContext::new(),
})
});
}
12 changes: 6 additions & 6 deletions examples/msaa_render_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Stage {
let vertex_buffer = ctx.new_buffer(
BufferType::VertexBuffer,
BufferUsage::Immutable,
BufferSource::slice(&vertices),
BufferSource::slice(vertices),
);

#[rustfmt::skip]
Expand All @@ -100,12 +100,12 @@ impl Stage {
let index_buffer = ctx.new_buffer(
BufferType::IndexBuffer,
BufferUsage::Immutable,
BufferSource::slice(&indices),
BufferSource::slice(indices),
);

let offscreen_bind = Bindings {
vertex_buffers: vec![vertex_buffer.clone()],
index_buffer: index_buffer.clone(),
vertex_buffers: vec![vertex_buffer],
index_buffer: index_buffer,
images: vec![],
};

Expand All @@ -120,7 +120,7 @@ impl Stage {
let vertex_buffer = ctx.new_buffer(
BufferType::VertexBuffer,
BufferUsage::Immutable,
BufferSource::slice(&vertices),
BufferSource::slice(vertices),
);
let indices: [u16; 6] = [0, 1, 2, 0, 2, 3];
let index_buffer = ctx.new_buffer(
Expand All @@ -130,7 +130,7 @@ impl Stage {
);
Bindings {
vertex_buffers: vec![vertex_buffer],
index_buffer: index_buffer,
index_buffer,
images: vec![color_resolve_img],
}
};
Expand Down
10 changes: 5 additions & 5 deletions examples/offscreen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Stage {
let vertex_buffer = ctx.new_buffer(
BufferType::VertexBuffer,
BufferUsage::Immutable,
BufferSource::slice(&vertices),
BufferSource::slice(vertices),
);

#[rustfmt::skip]
Expand All @@ -85,18 +85,18 @@ impl Stage {
let index_buffer = ctx.new_buffer(
BufferType::IndexBuffer,
BufferUsage::Immutable,
BufferSource::slice(&indices),
BufferSource::slice(indices),
);

let offscreen_bind = Bindings {
vertex_buffers: vec![vertex_buffer.clone()],
index_buffer: index_buffer.clone(),
vertex_buffers: vec![vertex_buffer],
index_buffer: index_buffer,
images: vec![],
};

let display_bind = Bindings {
vertex_buffers: vec![vertex_buffer],
index_buffer: index_buffer,
index_buffer,
images: vec![color_img],
};

Expand Down
14 changes: 7 additions & 7 deletions examples/post_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Stage {
let vertex_buffer = ctx.new_buffer(
BufferType::VertexBuffer,
BufferUsage::Immutable,
BufferSource::slice(&vertices),
BufferSource::slice(vertices),
);

#[rustfmt::skip]
Expand All @@ -86,12 +86,12 @@ impl Stage {
let index_buffer = ctx.new_buffer(
BufferType::IndexBuffer,
BufferUsage::Immutable,
BufferSource::slice(&indices),
BufferSource::slice(indices),
);

let offscreen_bind = Bindings {
vertex_buffers: vec![vertex_buffer.clone()],
index_buffer: index_buffer.clone(),
vertex_buffers: vec![vertex_buffer],
index_buffer: index_buffer,
images: vec![],
};

Expand All @@ -107,20 +107,20 @@ impl Stage {
let vertex_buffer = ctx.new_buffer(
BufferType::VertexBuffer,
BufferUsage::Immutable,
BufferSource::slice(&vertices),
BufferSource::slice(vertices),
);

let indices: &[u16] = &[0, 1, 2, 0, 2, 3];

let index_buffer = ctx.new_buffer(
BufferType::IndexBuffer,
BufferUsage::Immutable,
BufferSource::slice(&indices),
BufferSource::slice(indices),
);

let post_processing_bind = Bindings {
vertex_buffers: vec![vertex_buffer],
index_buffer: index_buffer,
index_buffer,
images: vec![color_img],
};

Expand Down
2 changes: 1 addition & 1 deletion examples/quad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl Stage {

let bindings = Bindings {
vertex_buffers: vec![vertex_buffer],
index_buffer: index_buffer,
index_buffer,
images: vec![texture],
};

Expand Down
44 changes: 44 additions & 0 deletions examples/screen_metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use miniquad::*;

struct Stage {
ctx: GlContext,
}

impl EventHandler for Stage {
fn update(&mut self) {}

fn draw(&mut self) {
self.ctx.clear(Some((0.2, 0.2, 0.2, 1.0)), None, None);

let metrics = window::screen_metrics();
println!("Screen Metrics:");
println!(" Size: {}x{}", metrics.width, metrics.height);
println!(" Position: {:?}", metrics.position);
println!(" DPI Scale: {}", metrics.dpi_scale);
println!(" High DPI: {}", metrics.high_dpi);

let (width, height) = window::screen_size();
println!("Screen Size (legacy): {}x{}", width, height);

println!("DPI Scale (legacy): {}", window::dpi_scale());
println!("High DPI (legacy): {}", window::high_dpi());
println!("---");
}
}

fn main() {
miniquad::start(
conf::Conf {
window_title: "Screen Metrics Demo".to_string(),
window_width: 800,
window_height: 600,
high_dpi: true,
..Default::default()
},
|| {
Box::new(Stage {
ctx: GlContext::new(),
})
},
);
}
2 changes: 1 addition & 1 deletion examples/triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Stage {

let bindings = Bindings {
vertex_buffers: vec![vertex_buffer],
index_buffer: index_buffer,
index_buffer,
images: vec![],
};

Expand Down
2 changes: 1 addition & 1 deletion examples/triangle_color4b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl Stage {

let bindings = Bindings {
vertex_buffers: vec![vertex_buffer],
index_buffer: index_buffer,
index_buffer,
images: vec![],
};

Expand Down
29 changes: 29 additions & 0 deletions examples/window_position_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use miniquad::*;

struct Stage {
ctx: GlContext,
}
impl EventHandler for Stage {
fn update(&mut self) {}

fn draw(&mut self) {
self.ctx.clear(Some((0.2, 0.7, 0.3, 1.0)), None, None);
}
}

fn main() {
miniquad::start(
conf::Conf {
window_title: "Desktop Center Test".to_string(),
window_width: 640,
window_height: 480,
desktop_center: true, // Center window on desktop
..Default::default()
},
|| {
Box::new(Stage {
ctx: GlContext::new(),
})
},
);
}
Loading
Loading