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

Triangle example using GLFW #1258

Merged
merged 8 commits into from
May 11, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,4 @@ image = "0.13"
winit = "0.6"

[target.x86_64-unknown-linux-gnu.dev-dependencies]
glfw = "0.12"
glfw = "0.14"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I don't know why it's even here? gfx_app doesn't use glfw or SDL anyway.
Let's remove it?

7 changes: 6 additions & 1 deletion src/window/glfw/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ documentation = "https://docs.rs/gfx_window_glfw"
name = "gfx_window_glfw"

[dependencies]
glfw = "0.13"
glfw = "0.14"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs a version bump for this crate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't 0.14 the latest version?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, we should bump the version of gfx_window_glfw to 0.15, given that dependency change

gfx = "0.15"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should go to [dev-dependencies]

gfx_core = { path = "../../core", version = "0.7" }
gfx_device_gl = { path = "../../backend/gl", version = "0.14" }

[[example]]
name = "window"
path = "examples/window/main.rs"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's simplify it by placing the example as examples/window.rs, so that you don't even need this path= line here

19 changes: 19 additions & 0 deletions src/window/glfw/examples/window/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!--
Copyright 2014 The Gfx-rs Developers.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

# Gfx-rs + GLFW Example

Basic window with glfw. For drawing code, refer to main triangle example.
53 changes: 53 additions & 0 deletions src/window/glfw/examples/window/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2015 The Gfx-rs Developers.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

extern crate gfx;
extern crate gfx_window_glfw;
extern crate glfw;

use glfw::{Action, Context, Key};

pub fn main() {
let mut glfw = glfw::init(glfw::FAIL_ON_ERRORS)
.ok()
.expect("Failed to initialize GLFW");

glfw.window_hint(glfw::WindowHint::ContextVersion(3, 2));
glfw.window_hint(glfw::WindowHint::OpenGlForwardCompat(true));
glfw.window_hint(glfw::WindowHint::OpenGlProfile(glfw::OpenGlProfileHint::Core));

let (mut window, events) = glfw.create_window(1024, 768, "Triangle example", glfw::WindowMode::Windowed)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's change the title here

.expect("Failed to create GLFW window.");

window.set_key_polling(true);
window.set_close_polling(true);
window.make_current();
glfw.set_error_callback(glfw::FAIL_ON_ERRORS);
let (_, _, _, _) = gfx_window_glfw::init(&mut window);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's add a //Note: actual drawing code is no different from the triangle example, or any other.

let mut running = true;
while running {
glfw.poll_events();

for (_, event) in glfw::flush_messages(&events) {
match event {
glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) => running = false,
glfw::WindowEvent::Close => running = false,
_ => {},
}
}

window.swap_buffers();
}
}