Skip to content

Commit

Permalink
Cleanup some old comments/code.
Browse files Browse the repository at this point in the history
  • Loading branch information
thebracket committed Nov 21, 2019
1 parent ae6c640 commit efee85c
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/hal/native/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ pub fn init_raw<S: ToString>(
shader_strings::SCANLINES_VS,
shader_strings::SCANLINES_FS,
));
shaders.push(Shader::new(
&gl,
shader_strings::TEST_VS,
shader_strings::TEST_FS,
));

// Build the backing frame-buffer
let backing_fbo = Framebuffer::build_fbo(&gl, width_pixels as i32, height_pixels as i32);
Expand Down
84 changes: 84 additions & 0 deletions src/hal/native/shader_strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,87 @@ void main()
gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0);
}
"#;

pub static TEST_VS : &str = r#"#version 330 core
precision mediump float;
layout(location = 0) in vec2 vertexPosition_modelspace;
layout(location = 1) in vec2 aTex;
out vec2 TexCoords;
uniform vec3 offset;
uniform vec3 font;
void main(){
gl_Position = vec4(vertexPosition_modelspace + floor(offset.rg * font.rg), 0.0, 1.0);
TexCoords = aTex;
}
"#;

pub static TEST_FS : &str = r#"#version 330 core
precision mediump float;
in vec2 TexCoords;
out vec4 FragColor;
uniform sampler2D texture1;
uniform sampler2D glyphBuffer;
uniform sampler2D bgBuffer;
uniform vec3 font;
uniform vec3 screenSize;
uniform bool screenBurn;
uniform bool showScanLines;
uniform bool hasBackground;
void main(){
float consoleX = gl_FragCoord.x / font.r;
float consoleY = gl_FragCoord.y / font.g;
float conX = floor(consoleX);
float conY = floor(consoleY);
// Obtain the 0..1 range within each character
float spriteX = fract(consoleX);
float spriteY = fract(consoleY);
// Figure out where we are on the sprite sheet
mediump float glyphSizeX = 1.0f / 16.0f;
mediump float glyphSizeY = 1.0f / 16.0f;
vec4 glyphLookup = texture(glyphBuffer, TexCoords);
mediump float glyph = glyphLookup.r * 255.0f;
mediump float glyphX = mod(glyph, 16.0f);
mediump float glyphY = 16.0f - floor(glyph / 16.0f);
// So now we have it in 0..16 , 0..16.
vec3 rgb = glyphLookup.gba;
vec2 fontcoords;
fontcoords.r = (glyphX + spriteX) * glyphSizeX;
fontcoords.g = (glyphY - (1.0f - spriteY)) * glyphSizeY;
vec3 color = texture(texture1, fontcoords).rgb * rgb;
// Set the background color
bool applyScan = true;
if (color.r < 0.1 && color.g < 0.1 && color.b < 0.1) {
if (!hasBackground) discard;
vec3 bg = texture(bgBuffer, TexCoords).rgb;
if (bg.r < 0.1 && bg.g < 0.1 && bg.b < 0.1) {
if (screenBurn) {
float dist = (1.0 - distance(vec2(gl_FragCoord.x / screenSize.x, gl_FragCoord.y / screenSize.y), vec2(0.5,0.5))) * 0.2;
color = vec3(0.0, dist, dist);
applyScan = false;
} else {
color = vec3(0.0, 0.0, 0.0);
}
} else {
color = bg;
}
}
// Scan lines
float scanLine = mod(gl_FragCoord.y, 2.0) * 0.25;
vec3 scanColor = showScanLines ? (color.rgb - scanLine) : color;
FragColor = applyScan ? vec4(scanColor.rgb, 1.0) : vec4(color, 1.0);
}
"#;
3 changes: 0 additions & 3 deletions src/hal/wasm/mainloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ fn tock<GS: GameState>(
rltk.backend.gl.clear(glow::COLOR_BUFFER_BIT);
}

// First principles debugging - can we draw a triangle?

let gl = &rltk.backend.gl;

unsafe {
Expand All @@ -97,7 +95,6 @@ fn tock<GS: GameState>(
&rltk.shaders[0].setVec3(gl, "font", 8.0, 8.0, 0.0);

gl.bind_vertex_array(Some(rltk.backend.platform.quad_vao));
//gl.draw_arrays(glow::TRIANGLES, 0, 6);
}

// Tell each console to draw itself
Expand Down

0 comments on commit efee85c

Please sign in to comment.