Another newbie question: No output from program

(Martin) #1

I’ve tried writing some Amethyst, but I don’t get any output on the screen. I have copied in a simplified version of my code below. Can anyone help?

extern crate amethyst;
extern crate nalgebra;
extern crate spade;
use std::default::Default;
//use std::error::Error;

use amethyst::{
    controls::{FlyControlBundle, FlyControlTag},
        //   nalgebra::Point3,
        transform::{Transform, TransformBundle},
    ecs::{Read, System, Write},

struct TestLinesSystem;
impl<'s> System<'s> for TestLinesSystem {
    type SystemData = (
        Write<'s, DebugLines>, // Request DebugLines resource
        Read<'s, Time>,
    fn run(&mut self, (mut debug_lines_resource, _time): Self::SystemData) {
        //   set up lines
        //    println!("run for test lines system");
            [0.0, 0.0, 0.5].into(),
            [0.0, 0.3, 0.0].into(),
            [0.5, 0.05, 0.65, 1.0].into(),

struct MeshData {}

impl SimpleState for MeshData {
    fn on_start(&mut self, data: StateData<'_, GameData<'_, '_>>) {
        println!("starting mesh data");
        // set up here

        // Setup debug lines as a resource
        // Configure width of lines. Optional step {
            line_width: 1.0 / 10.0,

        // Setup debug lines as a component and add lines to render axis&grid
        let mut debug_lines_component = DebugLinesComponent::new().with_capacity(100);
            [0.0, 0.0001, 0.0].into(),
            [0.2, 0.0, 0.0].into(),
            [1.0, 0.0, 0.23, 1.0].into(),

        // Setup camera
        let mut local_transform = Transform::default();
        local_transform.set_position([0.0, 0.0, 0.0].into());

fn main() -> amethyst::Result<()> {

    let path = format!("{}/resources/display_config.ron", application_root_dir());
    let config = DisplayConfig::load(&path);

    let pipe = Pipeline::build().with_stage(
            .clear_target(Rgba::WHITE, 1.0)
            //  .with_pass(DrawFlat::<PosNormTex>::new()),

    let mesh_data = MeshData {};

    let fly_control_bundle = FlyControlBundle::<String, String>::new(
    .with_sensitivity(0.1, 0.1);

    let game_data = GameDataBuilder::default()
        .with(TestLinesSystem, "test_lines_system", &[])
        .with_bundle(RenderBundle::new(pipe, Some(config)))?;
    let mut game = Application::new("./", mesh_data, game_data)?;;


(Azriel Hoh) #2

Hiya, can’t see anything odd with the code; when you say there’s no output, do you mean:

  • there’s no logging output and no println! output
  • there is logging output and no println! output
  • something else?

In any case:

  • How are you building / running the application?
  • Does it panic?
  • (if relevant) What happens if you export RUST_BACKTRACE=1

(Martin) #3

The program is displaying a white window. It should be displaying a white window with some red lines on it.

I am running the program using cargo run. It builds and displays println messages properly. It doesn’t panic.

I should add: I am trying to convert the debug_lines example to work in two dimensions. My objective is to display some of my data graphically, but I have removed that part from the code in this post.

(Azriel Hoh) #4

ah, thought you were trying to get text to output and it wasn’t.
I suspect it’s going to be to do with that Camera::standard2d() and the debug lines’ Z axis coordinates.

That sets up the camera to be:

pub fn standard_2d() -> Self {
    Self::from(Projection::orthographic(-1., 1., -1., 1.))

// and then
pub fn orthographic(l: f32, r: f32, b: f32, t: f32) -> Projection {
    Projection::Orthographic(Orthographic3::new(l, r, b, t, 0.1, 2000.0))

Can you try playing with the Z coordinates to be either all 0.5, or all 1.5? This is one of the more tedious things to troubleshoot, since it requires a recompile every time :gear: