Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running _spinning-square_ only prints "Hello, world!" message #261

Open
trevisanj opened this issue Jun 27, 2023 · 2 comments
Open

Running _spinning-square_ only prints "Hello, world!" message #261

trevisanj opened this issue Jun 27, 2023 · 2 comments

Comments

@trevisanj
Copy link

trevisanj commented Jun 27, 2023

Project compiles seamlessly, but when I run I get no graphics and following message instead:

$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 2.92s
     Running `target/debug/spinning-square`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "Error compiling vertex shader: 0:1(10): error: GLSL 1.50 is not supported. Supported versions are: 1.00 ES, 3.00 ES, 3.10 ES, and 3.20 ES\n"', /media/j/maca/Programs/cargo/registry/src/index.crates.io-6f17d22bba15001f/piston2d-opengl_graphics-0.82.0/src/back_end.rs:81:71
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
@funtemple3000
Copy link

Can you show me the code please?

@trevisanj
Copy link
Author

trevisanj commented Jul 6, 2023

Sure! ... but also sorry, I am now getting a different error message (I updated it in the original message in this issue as well):

$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 2.92s
     Running `target/debug/spinning-square`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "Error compiling vertex shader: 0:1(10): error: GLSL 1.50 is not supported. Supported versions are: 1.00 ES, 3.00 ES, 3.10 ES, and 3.20 ES\n"', /media/j/maca/Programs/cargo/registry/src/index.crates.io-6f17d22bba15001f/piston2d-opengl_graphics-0.82.0/src/back_end.rs:81:71
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Code follows (spinning square):

extern crate glutin_window;
extern crate graphics;
extern crate opengl_graphics;
extern crate piston;

use glutin_window::GlutinWindow as Window;
use opengl_graphics::{GlGraphics, OpenGL};
use piston::event_loop::{EventSettings, Events};
use piston::input::{RenderArgs, RenderEvent, UpdateArgs, UpdateEvent};
use piston::window::WindowSettings;

pub struct App {
    gl: GlGraphics, // OpenGL drawing backend.
    rotation: f64,  // Rotation for the square.
}

impl App {
    fn render(&mut self, args: &RenderArgs) {
        use graphics::*;

        const GREEN: [f32; 4] = [0.0, 1.0, 0.0, 1.0];
        const RED: [f32; 4] = [1.0, 0.0, 0.0, 1.0];

        let square = rectangle::square(0.0, 0.0, 50.0);
        let rotation = self.rotation;
        let (x, y) = (args.window_size[0] / 2.0, args.window_size[1] / 2.0);

        self.gl.draw(args.viewport(), |c, gl| {
            // Clear the screen.
            clear(GREEN, gl);

            let transform = c
                .transform
                .trans(x, y)
                .rot_rad(rotation)
                .trans(-25.0, -25.0);

            // Draw a box rotating around the middle of the screen.
            rectangle(RED, square, transform, gl);
        });
    }

    fn update(&mut self, args: &UpdateArgs) {
        // Rotate 2 radians per second.
        self.rotation += 2.0 * args.dt;
    }
}

fn main() {
    // Change this to OpenGL::V2_1 if not working.
    let opengl = OpenGL::V3_2;

    // Create a Glutin window.
    let mut window: Window = WindowSettings::new("spinning-square", [200, 200])
        .graphics_api(opengl)
        .exit_on_esc(true)
        .build()
        .unwrap();

    // Create a new game and run it.
    let mut app = App {
        gl: GlGraphics::new(opengl),
        rotation: 0.0,
    };

    let mut events = Events::new(EventSettings::new());
    while let Some(e) = events.next(&mut window) {
        if let Some(args) = e.render_args() {
            app.render(&args);
        }

        if let Some(args) = e.update_args() {
            app.update(&args);
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants