Browse Source

Fix stuff (see details), bump version to 0.7.0

- Add face culling
- Switch from gl_generator to gl (turns out, there's not much
difference, except avoiding repeating yourself when interoperating with
other OpenGL codebases)
- Make glClear optional (to allow for rendering on top of other gl code)
master
Jens Pitkänen 5 months ago
parent
commit
c30c226d7c
5 changed files with 20 additions and 32 deletions
  1. +2
    -4
      Cargo.toml
  2. +0
    -17
      build.rs
  3. +3
    -2
      src/api/graphics_context.rs
  4. +1
    -5
      src/lib.rs
  5. +14
    -4
      src/renderer.rs

+ 2
- 4
Cargo.toml View File

@@ -1,6 +1,6 @@
[package]
name = "fae"
version = "0.6.0"
version = "0.7.0"
authors = ["Jens Pitkanen <jens@neon.moe>"]
edition = "2018"
description = "A simple and fast 2D rendering crate with optional window creation and text rendering functionality."
@@ -25,6 +25,7 @@ stb_truetype = { version = "^0.3.1", optional = true}

# Now, the normal [dependencies] section
log = "^0.4.8"
gl = "0.14.0"
fnv = { version = "^1.0.6", optional = true }
png = { version = "^0.15.3", optional = true }
font8x8 = { version = "^0.2.5", optional = true, default_features = false, features = ["std"] }
@@ -43,9 +44,6 @@ glutin = "^0.23.0"
sdl2 = { version = "^0.33.0", features = ["static-link", "bundled"] }
glfw = "^0.36.0"

[build-dependencies]
gl_generator = "^0.14.0"

[[example]]
name = "glutin"
required-features = ["text"]


+ 0
- 17
build.rs View File

@@ -1,17 +0,0 @@
extern crate gl_generator;

use gl_generator::{Api, Fallbacks, GlobalGenerator, Profile, Registry};
use std::env;
use std::fs::File;
use std::path::Path;

fn main() {
let dest = env::var("OUT_DIR").unwrap();
let mut file = File::create(&Path::new(&dest).join("gl_bindings.rs")).unwrap();
Registry::new(Api::Gl, (3, 3), Profile::Core, Fallbacks::All, [])
.write_bindings(GlobalGenerator, &mut file)
.unwrap();

// Only rebuild when this file is changed
println!("cargo:rerun-if-changed=build.rs");
}

+ 3
- 2
src/api/graphics_context.rs View File

@@ -117,7 +117,8 @@ impl Context {
/// `clear_color`.
///
/// The `clear_color` is defined between 0.0 and 1.0, and the
/// components are (red, green, blue, alpha).
/// components are (red, green, blue, alpha). None if you don't
/// want to clear the screen.
///
/// See
/// [`Context::start_frame`](struct.Context.html#method.start_frame)
@@ -127,7 +128,7 @@ impl Context {
/// This should generally be called after
/// [`GraphicsContext::finish_frame`](struct.GraphicsContext.html#method.finish_frame),
/// but can also be used to redraw the previous frame.
pub fn render(&mut self, width: f32, height: f32, clear_color: (f32, f32, f32, f32)) {
pub fn render(&mut self, width: f32, height: f32, clear_color: Option<(f32, f32, f32, f32)>) {
self.renderer.render(width, height, clear_color);
}
}


+ 1
- 5
src/lib.rs View File

@@ -4,11 +4,7 @@

#![warn(missing_docs)]

#[allow(missing_docs, unknown_lints, clippy::all)]
pub mod gl {
//! OpenGL functions and constants.
include!(concat!(env!("OUT_DIR"), "/gl_bindings.rs"));
}
pub use gl;

mod api;
mod error;


+ 14
- 4
src/renderer.rs View File

@@ -280,7 +280,12 @@ impl Renderer {
}

/// Renders the queued draws.
pub(crate) fn render(&mut self, width: f32, height: f32, clear_color: (f32, f32, f32, f32)) {
pub(crate) fn render(
&mut self,
width: f32,
height: f32,
clear_color: Option<(f32, f32, f32, f32)>,
) {
let m00 = 2.0 / width;
let m11 = -2.0 / height;
let matrix = [
@@ -291,9 +296,11 @@ impl Renderer {
gl::BindFramebuffer(gl::FRAMEBUFFER, 0);
}

unsafe {
gl::ClearColor(clear_color.0, clear_color.1, clear_color.2, clear_color.3);
gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT);
if let Some((r, g, b, a)) = clear_color {
unsafe {
gl::ClearColor(r, g, b, a);
gl::Clear(gl::COLOR_BUFFER_BIT | gl::DEPTH_BUFFER_BIT);
}
}

let legacy = self.legacy;
@@ -301,6 +308,9 @@ impl Renderer {
unsafe {
gl::Enable(gl::DEPTH_TEST);
gl::BlendFunc(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA);
gl::Enable(gl::CULL_FACE);
gl::FrontFace(gl::CW);
gl::CullFace(gl::BACK);
}

let mut call_indices: Vec<usize> = (0..self.calls.len()).collect();


Loading…
Cancel
Save