[oden] Color and position for text
This commit is contained in:
parent
079006acdc
commit
a08bc07cbb
6 changed files with 29 additions and 17 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { print } from "./graphics";
|
||||
import { color, print } from "./graphics";
|
||||
|
||||
const lines: string[] = [];
|
||||
|
||||
|
|
@ -8,8 +8,10 @@ export function log(...args: unknown[]) {
|
|||
}
|
||||
|
||||
export function draw_log() {
|
||||
color(1, 1, 1, 1);
|
||||
let line_y = 3;
|
||||
for (const line of lines) {
|
||||
print(line);
|
||||
break;
|
||||
print(3, line_y, line);
|
||||
line_y += 8;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,10 +44,12 @@ export function stroke(r: number, g: number, b: number, a: number = 1) {
|
|||
* separated by spaces. If you want them separated by something else,
|
||||
* format the string yourself.
|
||||
*
|
||||
* @param x - The x coordinate of the upper-left corner of the text
|
||||
* @param y - The y coordinate of the upper-left corner of the text
|
||||
* @param args - Arguments to print to the console.
|
||||
*/
|
||||
export function print(...args: unknown[]) {
|
||||
core.print(args.join(" "));
|
||||
export function print(x: number, y: number, ...args: unknown[]) {
|
||||
core.print(args.join(" "), x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1237,13 +1237,11 @@ impl<'a> FrameBuilder<'a> {
|
|||
|
||||
fn push_text(&mut self, pc: script::graphics::PrintCommand) {
|
||||
// println!("{}", pc.text);
|
||||
let mut cursor_x = 0.0;
|
||||
let cursor_y = 0.0;
|
||||
let mut cursor_x = pc.pos[0];
|
||||
let cursor_y = pc.pos[1];
|
||||
|
||||
let font_id: u32 = 0;
|
||||
|
||||
// self.mode = ; // ?
|
||||
|
||||
let font = self.state.fonts.get_mut(&font_id).unwrap();
|
||||
let mut glyphs = vec![];
|
||||
for char in pc.text.chars() {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use std::sync::Arc;
|
|||
#[derive(Debug)]
|
||||
pub struct PrintCommand {
|
||||
pub text: String,
|
||||
pub pos: [f32; 2],
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -63,10 +64,10 @@ impl GraphicsImpl {
|
|||
}
|
||||
}
|
||||
|
||||
fn print(&self, text: String) -> () {
|
||||
fn print(&self, text: String, x: f32, y: f32) -> () {
|
||||
let _ = self
|
||||
.sender
|
||||
.send(GraphicsCommand::Print(PrintCommand { text }));
|
||||
.send(GraphicsCommand::Print(PrintCommand { text, pos: [x, y] }));
|
||||
}
|
||||
|
||||
fn cls(&self, r: f64, g: f64, b: f64) -> () {
|
||||
|
|
@ -168,7 +169,7 @@ impl GraphicsAPI {
|
|||
let gfx = gfx.clone();
|
||||
builder.export(
|
||||
"print",
|
||||
ctx.new_fn(move |_: &ContextRef, t: String| gfx.print(t))?,
|
||||
ctx.new_fn(move |_: &ContextRef, t: String, x: f32, y: f32| gfx.print(t, x, y))?,
|
||||
)?;
|
||||
}
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,16 +12,19 @@ struct InstanceInput {
|
|||
@location(6) src_dims: vec2<f32>,
|
||||
@location(7) dest_top_left: vec2<f32>,
|
||||
@location(8) dest_dims: vec2<f32>,
|
||||
@location(9) color: vec4<f32>,
|
||||
};
|
||||
|
||||
struct VertexOutput {
|
||||
@builtin(position) clip_position : vec4<f32>,
|
||||
@location(0) tex_coords : vec2<f32>,
|
||||
@location(1) color: vec4<f32>,
|
||||
};
|
||||
|
||||
@vertex fn vs_main(vertex : VertexInput, instance : InstanceInput)->VertexOutput {
|
||||
var out : VertexOutput;
|
||||
out.tex_coords = instance.src_top_left + (vertex.tex_coords * instance.src_dims);
|
||||
out.color = instance.color;
|
||||
|
||||
let in_pos = instance.dest_top_left + (vec2f(vertex.position.x, vertex.position.y) * instance.dest_dims);
|
||||
|
||||
|
|
@ -38,16 +41,22 @@ struct VertexOutput {
|
|||
@group(1) @binding(1) var s_diffuse : sampler;
|
||||
|
||||
@fragment fn fs_main(in : VertexOutput)->@location(0) vec4<f32> {
|
||||
// TODO: Should we be sampling here for the shader?
|
||||
|
||||
let tc = vec2(u32(in.tex_coords.x), u32(in.tex_coords.y));
|
||||
let c = textureLoad(t_diffuse, tc, 0);
|
||||
|
||||
// If we were going to run this through the sampler it would look like
|
||||
// this... but I don't know if that'w what we should do? Right now the
|
||||
// direct load looks better?
|
||||
//
|
||||
// let tc = in.tex_coords / vec2<f32>(textureDimensions(t_diffuse));
|
||||
// let c = textureSample(t_diffuse, s_diffuse, tc);
|
||||
|
||||
|
||||
return vec4<f32>(c.r,c.r,c.r,c.r);
|
||||
return vec4<f32>(
|
||||
c.r * in.color.x,
|
||||
c.r * in.color.y,
|
||||
c.r * in.color.z,
|
||||
c.r * in.color.a
|
||||
);
|
||||
//return vec4<f32>(1.0,1.0,1.0,1.0);
|
||||
}
|
||||
|
||||
|
|
|
|||
2
types/graphics-core.d.ts
vendored
2
types/graphics-core.d.ts
vendored
|
|
@ -2,7 +2,7 @@
|
|||
//
|
||||
export function cls(r: number, g: number, b: number);
|
||||
|
||||
export function print(msg: string);
|
||||
export function print(msg: string, x: number, y: number);
|
||||
|
||||
export function color(r: number, g: number, b: number, a: number);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue