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},
    core::{
        //   nalgebra::Point3,
        transform::{Transform, TransformBundle},
        Time,
    },
    ecs::{Read, System, Write},
    prelude::*,
    renderer::*,
    utils::application_root_dir,
};

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");
        debug_lines_resource.draw_direction(
            [0.0, 0.0, 0.5].into(),
            [0.0, 0.3, 0.0].into(),
            [0.5, 0.05, 0.65, 1.0].into(),
        );
    }
}

#[derive(Default)]
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
        data.world
            .add_resource(DebugLines::new().with_capacity(100));
        // Configure width of lines. Optional step
        data.world.add_resource(DebugLinesParams {
            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);
        debug_lines_component.add_direction(
            [0.0, 0.0001, 0.0].into(),
            [0.2, 0.0, 0.0].into(),
            [1.0, 0.0, 0.23, 1.0].into(),
        );

        data.world.register::<DebugLinesComponent>();
        data.world
            .create_entity()
            .with(debug_lines_component)
            .build();

        // Setup camera
        let mut local_transform = Transform::default();
        local_transform.set_position([0.0, 0.0, 0.0].into());
        data.world
            .create_entity()
            .with(FlyControlTag)
            .with(Camera::standard_2d())
            .with(local_transform)
            .build();
    }
}

fn main() -> amethyst::Result<()> {
    amethyst::start_logger(Default::default());

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

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

    let mesh_data = MeshData {};

    let fly_control_bundle = FlyControlBundle::<String, String>::new(
        Some(String::from("move_x")),
        Some(String::from("move_y")),
        Some(String::from("move_z")),
    )
    .with_sensitivity(0.1, 0.1);

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

    game.run();

    Ok(())
}

0 Likes

(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
0 Likes

(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.

0 Likes

(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:

0 Likes