Initial?? Commit

This commit is contained in:
Hazel Layne Aranda 2021-03-02 04:55:27 -05:00
commit 82adc16b97
Signed by: hazelra
GPG key ID: 09213F100E5E4E67
16 changed files with 2485 additions and 0 deletions

22
.cargo/config.toml Normal file
View file

@ -0,0 +1,22 @@
# Rename this file to `config.toml` to enable "fast build" configuration. Please read the notes below.
# NOTE: For maximum performance, build using a nightly compiler
# If you are using rust stable, remove the "-Zshare-generics=y" below.
[target.x86_64-unknown-linux-gnu]
linker = "/usr/bin/clang"
rustflags = ["-Clink-arg=-fuse-ld=lld", "-Zshare-generics=y"]
# NOTE: you must manually install https://github.com/michaeleisel/zld on mac. you can easily do this with the "brew" package manager:
# `brew install michaeleisel/zld/zld`
[target.x86_64-apple-darwin]
rustflags = ["-C", "link-arg=-fuse-ld=/usr/local/bin/zld", "-Zshare-generics=y", "-Zrun-dsymutil=no"]
[target.x86_64-pc-windows-msvc]
linker = "rust-lld.exe"
rustflags = ["-Zshare-generics=y"]
# Optional: Uncommenting the following improves compile times, but reduces the amount of debug info to 'line number tables only'
# In most cases the gains are negligible, but if you are on macos and have slow compile times you should see significant gains.
#[profile.dev]
#debug = 1

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

1704
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

29
Cargo.toml Normal file
View file

@ -0,0 +1,29 @@
[package]
name = "digging"
version = "0.1.0"
authors = ["Hazel Snider <hazelra@disroot.org>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[profile.dev.package.'*']
opt-level = 3
[dependencies]
log = "0.4.14"
simplelog = "0.9.0"
glob = "0.3.0"
anymap = "0.12.1"
glium = "0.29.0"
cgmath = "0.18.0"
crunch = "0.3.2"
glium-glyph = "0.10.0"
hecs = "0.3.1"
[dependencies.image]
version = "0.23.13"
default-features = false
features = ["png"]

View file

@ -0,0 +1,187 @@
Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.
Glyphs imported from Arev fonts are (c) Tavmjong Bah (see below)
Bitstream Vera Fonts Copyright
------------------------------
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is
a trademark of Bitstream, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of the fonts accompanying this license ("Fonts") and associated
documentation files (the "Font Software"), to reproduce and distribute the
Font Software, including without limitation the rights to use, copy, merge,
publish, distribute, and/or sell copies of the Font Software, and to permit
persons to whom the Font Software is furnished to do so, subject to the
following conditions:
The above copyright and trademark notices and this permission notice shall
be included in all copies of one or more of the Font Software typefaces.
The Font Software may be modified, altered, or added to, and in particular
the designs of glyphs or characters in the Fonts may be modified and
additional glyphs or characters may be added to the Fonts, only if the fonts
are renamed to names not containing either the words "Bitstream" or the word
"Vera".
This License becomes null and void to the extent applicable to Fonts or Font
Software that has been modified and is distributed under the "Bitstream
Vera" names.
The Font Software may be sold as part of a larger software package but no
copy of one or more of the Font Software typefaces may be sold by itself.
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING
ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE
FONT SOFTWARE.
Except as contained in this notice, the names of Gnome, the Gnome
Foundation, and Bitstream Inc., shall not be used in advertising or
otherwise to promote the sale, use or other dealings in this Font Software
without prior written authorization from the Gnome Foundation or Bitstream
Inc., respectively. For further information, contact: fonts at gnome dot
org.
Arev Fonts Copyright
------------------------------
Copyright (c) 2006 by Tavmjong Bah. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining
a copy of the fonts accompanying this license ("Fonts") and
associated documentation files (the "Font Software"), to reproduce
and distribute the modifications to the Bitstream Vera Font Software,
including without limitation the rights to use, copy, merge, publish,
distribute, and/or sell copies of the Font Software, and to permit
persons to whom the Font Software is furnished to do so, subject to
the following conditions:
The above copyright and trademark notices and this permission notice
shall be included in all copies of one or more of the Font Software
typefaces.
The Font Software may be modified, altered, or added to, and in
particular the designs of glyphs or characters in the Fonts may be
modified and additional glyphs or characters may be added to the
Fonts, only if the fonts are renamed to names not containing either
the words "Tavmjong Bah" or the word "Arev".
This License becomes null and void to the extent applicable to Fonts
or Font Software that has been modified and is distributed under the
"Tavmjong Bah Arev" names.
The Font Software may be sold as part of a larger software package but
no copy of one or more of the Font Software typefaces may be sold by
itself.
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL
TAVMJONG BAH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
Except as contained in this notice, the name of Tavmjong Bah shall not
be used in advertising or otherwise to promote the sale, use or other
dealings in this Font Software without prior written authorization
from Tavmjong Bah. For further information, contact: tavmjong @ free
. fr.
TeX Gyre DJV Math
-----------------
Fonts are (c) Bitstream (see below). DejaVu changes are in public domain.
Math extensions done by B. Jackowski, P. Strzelczyk and P. Pianowski
(on behalf of TeX users groups) are in public domain.
Letters imported from Euler Fraktur from AMSfonts are (c) American
Mathematical Society (see below).
Bitstream Vera Fonts Copyright
Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera
is a trademark of Bitstream, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy
of the fonts accompanying this license (“Fonts”) and associated
documentation
files (the “Font Software”), to reproduce and distribute the Font Software,
including without limitation the rights to use, copy, merge, publish,
distribute,
and/or sell copies of the Font Software, and to permit persons to whom
the Font Software is furnished to do so, subject to the following
conditions:
The above copyright and trademark notices and this permission notice
shall be
included in all copies of one or more of the Font Software typefaces.
The Font Software may be modified, altered, or added to, and in particular
the designs of glyphs or characters in the Fonts may be modified and
additional
glyphs or characters may be added to the Fonts, only if the fonts are
renamed
to names not containing either the words “Bitstream” or the word “Vera”.
This License becomes null and void to the extent applicable to Fonts or
Font Software
that has been modified and is distributed under the “Bitstream Vera”
names.
The Font Software may be sold as part of a larger software package but
no copy
of one or more of the Font Software typefaces may be sold by itself.
THE FONT SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
FOUNDATION
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING ANY GENERAL,
SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WHETHER IN AN
ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR
INABILITY TO USE
THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.
Except as contained in this notice, the names of GNOME, the GNOME
Foundation,
and Bitstream Inc., shall not be used in advertising or otherwise to promote
the sale, use or other dealings in this Font Software without prior written
authorization from the GNOME Foundation or Bitstream Inc., respectively.
For further information, contact: fonts at gnome dot org.
AMSFonts (v. 2.2) copyright
The PostScript Type 1 implementation of the AMSFonts produced by and
previously distributed by Blue Sky Research and Y&Y, Inc. are now freely
available for general use. This has been accomplished through the
cooperation
of a consortium of scientific publishers with Blue Sky Research and Y&Y.
Members of this consortium include:
Elsevier Science IBM Corporation Society for Industrial and Applied
Mathematics (SIAM) Springer-Verlag American Mathematical Society (AMS)
In order to assure the authenticity of these fonts, copyright will be
held by
the American Mathematical Society. This is not meant to restrict in any way
the legitimate use of the fonts, such as (but not limited to) electronic
distribution of documents containing these fonts, inclusion of these fonts
into other public domain or commercial font collections or computer
applications, use of the outline data to create derivative fonts and/or
faces, etc. However, the AMS does require that the AMS copyright notice be
removed from any derivative versions of the fonts which have been altered in
any way. In addition, to ensure the fidelity of TeX documents using Computer
Modern fonts, Professor Donald Knuth, creator of the Computer Modern faces,
has requested that any alterations which yield different font metrics be
given a different name.
$Id$

BIN
assets/fonts/DejaVuSans.ttf Normal file

Binary file not shown.

View file

@ -0,0 +1,12 @@
#version 330 core
precision lowp float;
in vec2 v_tex_coords;
uniform sampler2D texture;
out vec4 f_color;
void main() {
f_color = vec4(texture2D(texture, v_tex_coords).rgb, 1.0);
}

View file

@ -0,0 +1,13 @@
#version 330 core
uniform mat3 matrix;
in vec2 position;
in vec2 tex_coords;
out lowp vec2 v_tex_coords;
void main() {
gl_Position = vec4(matrix * vec3(position, 1.0), 1.0);
v_tex_coords = tex_coords;
}

View file

@ -0,0 +1,46 @@
#version 330 core
precision lowp float;
in vec2 v_tex_coords;
uniform sampler2D texture;
uniform vec2 screen_resolution;
uniform vec2 curvature = vec2(3.0, 3.0);
uniform vec2 scanline_opacity = vec2(1.0, 1.0);
uniform float brightness = 3.0;
out vec4 f_color;
const float PI = 3.14159;
vec2 curve_uv(vec2 uv) {
uv = uv * 2.0 - 1.0;
vec2 offset = abs(uv.yx) / vec2(curvature.x, curvature.y);
uv = uv + uv * offset * offset;
uv = uv * 0.5 + 0.5;
return uv;
}
vec3 scanline_intensity(float uv, float resolution, float opacity) {
float intensity = sin(uv * resolution * PI * 2.0);
intensity = ((0.5 * intensity) + 0.5) * 0.9 + 0.1;
return vec3(pow(intensity, opacity));
}
void main() {
vec2 curved_uv = curve_uv(v_tex_coords);
vec3 base_color = texture2D(texture, curved_uv).rgb;
base_color += vec3(1.0/256.0);
base_color *= scanline_intensity(curved_uv.x, screen_resolution.y, scanline_opacity.x);
base_color *= scanline_intensity(curved_uv.y, screen_resolution.x, scanline_opacity.y);
base_color *= vec3(brightness);
if (curved_uv.x < 0.0 || curved_uv.y < 0.0 || curved_uv.x > 1.0 || curved_uv.y > 1.0) {
f_color = vec4(0.0, 0.0, 0.0, 1.0);
} else {
f_color = vec4(base_color, 1.0);
}
}

View file

@ -0,0 +1,14 @@
#version 330 core
uniform mat3 matrix;
in vec2 position;
in vec2 tex_coords;
out lowp vec2 v_tex_coords;
void main() {
gl_Position = vec4(matrix * vec3(position, 1.0), 1.0);
v_tex_coords = tex_coords;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 694 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 729 B

262
src/main.rs Normal file
View file

@ -0,0 +1,262 @@
use std::time::{Duration, Instant};
use anymap::AnyMap;
use cgmath::Matrix3;
use glium::{
glutin, index::PrimitiveType, texture::Texture2d, uniform, Display, Frame, IndexBuffer,
Surface, VertexBuffer,
};
use glium_glyph::{glyph_brush::Section, GlyphBrush};
use glutin::{
event::{Event, WindowEvent},
event_loop::ControlFlow,
};
use resources::Shaders;
use simplelog::{TermLogger, TerminalMode};
use state::GameState;
pub mod resources;
pub mod state;
const TIMESTEP: f32 = 1.0 / 20.0;
const SCREEN_WIDTH: f32 = 320.0;
const SCREEN_HEIGHT: f32 = 240.0;
#[derive(Clone, Copy)]
struct Vertex {
position: [f32; 2],
tex_coords: [f32; 2],
}
glium::implement_vertex!(Vertex, position, tex_coords);
// Where overall state is kept.
struct State {
current_fps: u32,
render_texture: Texture2d,
render_vertices: VertexBuffer<Vertex>,
screen_scale: (f32, f32),
current_state: Box<dyn GameState>,
next_state: Option<Box<dyn GameState>>,
resources: AnyMap,
}
impl State {
fn new(display: &Display) -> State {
// FPS thingies
let current_fps = 0;
let render_texture =
Texture2d::empty(display, SCREEN_WIDTH as u32, SCREEN_HEIGHT as u32).unwrap();
let render_vertices = VertexBuffer::new(
display,
&[
Vertex {
position: [-1.0, -1.0],
tex_coords: [0.0, 0.0],
},
Vertex {
position: [-1.0, 1.0],
tex_coords: [0.0, 1.0],
},
Vertex {
position: [1.0, 1.0],
tex_coords: [1.0, 1.0],
},
Vertex {
position: [1.0, -1.0],
tex_coords: [1.0, 0.0],
},
],
)
.unwrap();
let screen_scale = {
let size = display.gl_window().window().inner_size();
(
size.height as f32 / SCREEN_HEIGHT * SCREEN_WIDTH / size.width as f32,
size.width as f32 / SCREEN_WIDTH * SCREEN_HEIGHT / size.height as f32,
)
};
// Set initial state
let current_state = Box::new(state::TestState);
let next_state = None;
// The resources map
let mut resources = AnyMap::new();
resources::load_resources(display, &mut resources);
// Package it all together UwU
State {
current_fps,
render_texture,
render_vertices,
screen_scale,
current_state,
next_state,
resources,
}
}
fn input(&mut self, event: &Event<()>) {
self.current_state.input(&mut self.resources, event);
}
fn update(&mut self, dt: f32) {
// Swap state if new one is present
let mut next_state = None;
std::mem::swap(&mut next_state, &mut self.next_state);
if let Some(state) = next_state {
self.current_state = state;
}
// Run current state's update
self.next_state = self.current_state.update(&mut self.resources, dt);
}
fn render(&mut self, display: &Display, target: &mut Frame) {
{
let mut texture_target = self.render_texture.as_surface();
texture_target.clear_color_srgb(0.0, 0.0, 0.0, 1.0);
self.current_state
.render(&mut self.resources, display, &mut texture_target);
}
let render_indices =
IndexBuffer::new(display, PrimitiveType::TriangleStrip, &[1, 2, 0, 3 as u16]).unwrap();
let program = self.resources.get::<Shaders>().unwrap().get("crt").unwrap();
let mut scale = (1.0, 1.0);
if self.screen_scale.0 < self.screen_scale.1 {
scale.0 = self.screen_scale.0;
} else {
scale.1 = self.screen_scale.1;
}
let scale_matrix = Matrix3::from_nonuniform_scale(scale.0, scale.1);
let uniforms = uniform! {
matrix: cgmath::conv::array3x3(scale_matrix),
texture: self.render_texture.sampled().magnify_filter(glium::uniforms::MagnifySamplerFilter::Nearest),
screen_resolution: [SCREEN_WIDTH, SCREEN_HEIGHT],
/*curvature: [3.0, 3.0 as f32],
scanline_opacity: [0.5, 0.5 as f32],
brightness: 2.0 as f32,*/
};
target
.draw(
&self.render_vertices,
&render_indices,
program,
&uniforms,
&Default::default(),
)
.unwrap();
}
}
// It is the entrypoint, duh.
fn main() {
// Set up the logger
TermLogger::init(
log::LevelFilter::Info,
simplelog::Config::default(),
TerminalMode::Mixed,
)
.unwrap();
log::info!("Logger is set up!");
// Set up windowing and graphics context
let event_loop = glutin::event_loop::EventLoop::new();
let display = {
let wb = glutin::window::WindowBuilder::new();
let cb = glutin::ContextBuilder::new().with_vsync(true);
Display::new(wb, cb, &event_loop).unwrap()
};
// The main state of program or whatever
let mut state = State::new(&display);
// Timing stuff
let mut last_update = Instant::now();
let mut update_accumulator = 0.0;
let mut next_fps_check = Instant::now() + Duration::from_secs(1);
let mut frame_counter: u32 = 0;
// Run the main event loop
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;
match event {
// Stuff to happen every frame.
Event::MainEventsCleared => {
// Game timestep and state update stuff.
update_accumulator += last_update.elapsed().as_secs_f32();
last_update = Instant::now();
while update_accumulator >= TIMESTEP {
update_accumulator -= TIMESTEP;
state.update(TIMESTEP);
}
// Measure framerate
let now = Instant::now();
frame_counter += 1;
if now >= next_fps_check {
state.current_fps = frame_counter;
frame_counter = 0;
next_fps_check = now + Duration::from_secs(1);
}
// Let us render some shit!
let mut target = display.draw();
target.clear_color_srgb(0.0, 0.0, 0.0, 1.0);
state.render(&display, &mut target);
// Draw the FPS Indicator
let glyph_brush = state.resources.get_mut::<GlyphBrush>().unwrap();
glyph_brush.queue(Section {
text: &format!("FPS: {:?}", state.current_fps),
screen_position: (0.0, 0.0),
color: [1.0, 1.0, 1.0, 1.0],
..Default::default()
});
glyph_brush.draw_queued(&display, &mut target);
target.finish().unwrap();
}
Event::WindowEvent {
event: WindowEvent::Resized(size),
..
} => {
state.screen_scale = (
size.height as f32 / SCREEN_HEIGHT * SCREEN_WIDTH / size.width as f32,
size.width as f32 / SCREEN_WIDTH * SCREEN_HEIGHT / size.height as f32,
);
}
// Quit if window wants to be closed
// TODO: Check state to see if allowed to exit.
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => {
*control_flow = ControlFlow::Exit;
}
// Cleanup here
Event::LoopDestroyed => {}
event => {
state.input(&event);
}
}
});
}

74
src/resources.rs Normal file
View file

@ -0,0 +1,74 @@
use std::collections::HashMap;
use anymap::AnyMap;
use glium::{texture::SrgbTexture2d, Display, Program};
use glium_glyph::{glyph_brush::rusttype::Font, GlyphBrush};
use glob::glob;
pub type Textures = HashMap<String, SrgbTexture2d>;
pub type Shaders = HashMap<String, Program>;
// Set up and load all global resources.
pub fn load_resources(display: &Display, resources: &mut AnyMap) {
// Load images
log::info!("Loading textures");
let mut textures: Textures = HashMap::new();
for entry in glob("assets/textures/**/*.png").unwrap() {
use image::io::Reader;
if let Ok(path) = entry {
let image = Reader::open(&path).unwrap().decode().unwrap().to_rgba8();
let image_dimensions = image.dimensions();
let image = glium::texture::RawImage2d::from_raw_rgba_reversed(
&image.into_raw(),
image_dimensions,
);
let texture = SrgbTexture2d::new(display, image).unwrap();
let name_path = path
.with_extension("")
.strip_prefix("assets/textures/")
.unwrap()
.to_owned();
let mut name = String::new();
for part in name_path.iter() {
name.push_str(part.to_str().unwrap());
name.push(':');
}
name.pop();
textures.insert(name.to_string(), texture);
log::info!("Loaded texture {:?} from {:?}.", name, path);
}
}
resources.insert(textures);
// Load shaders
log::info!("Loading shaders.");
let mut shaders: HashMap<String, Program> = HashMap::new();
for entry in glob("assets/shaders/*").unwrap() {
if let Ok(path) = entry {
// Operate only on directories
if path.is_file() {
continue;
}
let vert_source = std::fs::read_to_string(path.join("vert.glsl")).unwrap();
let frag_source = std::fs::read_to_string(path.join("frag.glsl")).unwrap();
let program = Program::from_source(display, &vert_source, &frag_source, None).unwrap();
let name = path.file_name().unwrap().to_str().unwrap().to_owned();
shaders.insert(name.to_string(), program);
log::info!("Loaded shader {:?} from {:?}.", name, path);
}
}
resources.insert(shaders);
// Set up font stuff
let dejavu = std::fs::read("assets/fonts/DejaVuSans.ttf").unwrap();
let fonts = vec![Font::from_bytes(dejavu).unwrap()];
let glyph_brush = GlyphBrush::new(display, fonts);
log::info!("Set up font.");
resources.insert(glyph_brush);
}

29
src/state.rs Normal file
View file

@ -0,0 +1,29 @@
use anymap::AnyMap;
use glium::{framebuffer::SimpleFrameBuffer, glutin::event::Event, Display, Frame, Surface};
mod test_state;
pub use test_state::TestState;
pub trait GameState {
fn input(&mut self, resources: &mut AnyMap, event: &Event<()>);
fn update(&mut self, resources: &mut AnyMap, dt: f32) -> Option<Box<dyn GameState>>;
fn render(&mut self, resources: &mut AnyMap, display: &Display, target: &mut SimpleFrameBuffer);
}
pub struct DummyState;
impl GameState for DummyState {
fn update(&mut self, _resourcess: &mut AnyMap, _dt: f32) -> Option<Box<dyn GameState>> {
None
}
fn input(&mut self, _resources: &mut AnyMap, _event: &Event<()>) {}
fn render(
&mut self,
_resources: &mut AnyMap,
_display: &Display,
_target: &mut SimpleFrameBuffer,
) {
}
}

92
src/state/test_state.rs Normal file
View file

@ -0,0 +1,92 @@
use glium::{
framebuffer::SimpleFrameBuffer, implement_vertex, index::PrimitiveType, uniform,
uniforms::Sampler, IndexBuffer, Surface, VertexBuffer,
};
use resources::Shaders;
use crate::resources::{self, Textures};
use super::GameState;
pub struct TestState;
impl GameState for TestState {
fn input(&mut self, resources: &mut anymap::AnyMap, event: &glium::glutin::event::Event<()>) {}
fn update(&mut self, resources: &mut anymap::AnyMap, dt: f32) -> Option<Box<dyn GameState>> {
None
}
fn render(
&mut self,
resources: &mut anymap::AnyMap,
display: &glium::Display,
target: &mut SimpleFrameBuffer,
) {
// Make vertex buffer
let vertex_buffer = {
#[derive(Clone, Copy)]
struct Vertex {
position: [f32; 2],
tex_coords: [f32; 2],
}
implement_vertex!(Vertex, position, tex_coords);
VertexBuffer::new(
display,
&[
Vertex {
position: [-1.0, -1.0],
tex_coords: [0.0, 0.0],
},
Vertex {
position: [-1.0, 1.0],
tex_coords: [0.0, 1.0],
},
Vertex {
position: [1.0, 1.0],
tex_coords: [1.0, 1.0],
},
Vertex {
position: [1.0, -1.0],
tex_coords: [1.0, 0.0],
},
],
)
.unwrap()
};
let index_buffer =
IndexBuffer::new(display, PrimitiveType::TriangleStrip, &[1 as u16, 2, 0, 3]).unwrap();
let program = resources.get::<Shaders>().unwrap().get("basic").unwrap();
let texture = resources
.get::<Textures>()
.unwrap()
.get("tiles:dirt")
.unwrap();
let uniforms = uniform! {
/*matrix: [
[1.0,0.0,0.0],
[0.0,1.0,0.0],
[0.0,0.0,1.0 as f32],
],*/
matrix: cgmath::conv::array3x3(cgmath::Matrix3::from_nonuniform_scale(1.0/crate::SCREEN_WIDTH*16.0, 1.0/crate::SCREEN_HEIGHT*16.0)),
texture: texture.sampled().magnify_filter(glium::uniforms::MagnifySamplerFilter::Nearest),
};
target
.draw(
&vertex_buffer,
&index_buffer,
program,
&uniforms,
&Default::default(),
)
.unwrap();
}
}