Giter VIP home page Giter VIP logo

macroquad's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

macroquad's Issues

Sound

Is there a macroquad-included way to play sound on all the given platforms, or is there a library that should be used that would work on all platforms with macroquad?

Clean up camera mess

  • set_default_camera and actual default camera are different. How to test: draw stuff without any set_whatever_camera calls and than add set_default_camera on top. The results should be the same

  • make it clear how to create Camera2D with exactly the same params as set_default_camera. Maybe just add the params of that Camera2D to docs of set_default_camera

Multi-Pass Rendering

Miniquad itself has RenderPasses for rendering to a texture for post-processing or other. I have thus far not been able to figure out any way to accomplish something like this with macroquad. Is there a way I have just overlooked, or is this simply not implemented yet?

Failed to compile version 0.1.4

Compiling miniquad v0.2.53
error[E0425]: cannot find function glColorMask in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.2.53\src\graphics.rs:506:22
|
506 | unsafe { glColorMask(r as _, g as _, b as _, a as _) }
| ^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function glUniform1iv in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.2.53\src\graphics.rs:609:25
|
609 | glUniform1iv(uniform.gl_loc, 1, data_int);
| ^^^^^^^^^^^^ help: a function with a similar name exists: glUniform1fv
|
::: C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\sapp-windows-0.2.7\src\sokol_app_msvc.rs:42612:5
|
42612 | pub fn glUniform1fv(location: GLint, count: GLsizei, value: *const GLfloat);
| ---------------------------------------------------------------------------- similarly named function glUniform1fv defined here

error[E0425]: cannot find function glUniform2iv in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.2.53\src\graphics.rs:612:25
|
612 | glUniform2iv(uniform.gl_loc, 1, data_int);
| ^^^^^^^^^^^^ help: a function with a similar name exists: glUniform2fv
|
::: C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\sapp-windows-0.2.7\src\sokol_app_msvc.rs:41863:5
|
41863 | pub fn glUniform2fv(location: GLint, count: GLsizei, value: *const GLfloat);
| ---------------------------------------------------------------------------- similarly named function glUniform2fv defined here

error[E0425]: cannot find function glUniform3iv in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.2.53\src\graphics.rs:615:25
|
615 | glUniform3iv(uniform.gl_loc, 1, data_int);
| ^^^^^^^^^^^^ help: a function with a similar name exists: glUniform3fv
|
::: C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\sapp-windows-0.2.7\src\sokol_app_msvc.rs:42427:5
|
42427 | pub fn glUniform3fv(location: GLint, count: GLsizei, value: *const GLfloat);
| ---------------------------------------------------------------------------- similarly named function glUniform3fv defined here

error[E0425]: cannot find function glUniform4iv in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.2.53\src\graphics.rs:618:25
|
618 | glUniform4iv(uniform.gl_loc, 1, data_int);
| ^^^^^^^^^^^^ help: a function with a similar name exists: glUniform4fv
|
::: C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\sapp-windows-0.2.7\src\sokol_app_msvc.rs:41854:5
|
41854 | pub fn glUniform4fv(location: GLint, count: GLsizei, value: *const GLfloat);
| ---------------------------------------------------------------------------- similarly named function glUniform4fv defined here

error: aborting due to 5 previous errors

bug related to megaui

trying to run any example on latest master gives the following error:

error[E0061]: this function takes 4 arguments but 3 arguments were supplied
   --> profiler/src/lib.rs:247:30
    |
247 |                 let tab = ui.tabbar(
    |                              ^^^^^^ expected 4 arguments
248 |                     hash!(),
    |                     -------
249 |                     megaui::Vector2::new(200.0, 20.0),
    |                     ---------------------------------
250 |                     &["profiler", "scene"],
    |                     ---------------------- supplied 3 arguments

3D Example Segmentation fault on Linux

I cloned repository and tried run 3d example with command:

cargo run --example 3d --release

After compile I got this error:

GLX: failed to create GL context
Segmentation fault (core dumped)

glxinfo render:

OpenGL vendor string: X.Org R300 Project
OpenGL renderer string: ATI RS480
OpenGL version string: 2.1 Mesa 20.0.8
OpenGL shading language version string: 1.20

How should I build a game for wasm

I feel like I must be doing something wrong.

Cargo refuses to build a binary with cargo build --target wasm32-unknown-unknown.

I can build as a library instead, then I get an error about main not being exported when I try to load the library in html.

I can fix that error by applying the following patch, which works fine, but I don't understand how anyone is using this library as-is. What might I be doing wrong/differently?

diff --git a/macroquad_macro/src/lib.rs b/macroquad_macro/src/lib.rs
index f8496a5..4b28673 100644
--- a/macroquad_macro/src/lib.rs
+++ b/macroquad_macro/src/lib.rs
@@ -36,6 +36,7 @@ pub fn main(_attr: TokenStream, item: TokenStream) -> TokenStream {
 
     let mut prelude: TokenStream = format!(
         "
+    #[cfg_attr(target_arch = \"wasm32\", no_mangle)]
     fn main() {{
         macroquad::Window::new(\"MACROQUAD\", amain());
     }}

draw_texture_rec uses UV coordinates instead of image coordinates.

From drawing.rs:215:

let vertices = [
            Vertex::new(x    , y    , 0., sx     , sy     , color),
            Vertex::new(x + w, y    , 0., sx + sw, sy     , color),
            Vertex::new(x + w, y + h, 0., sx + sw, sy + sh, color),
            Vertex::new(x    , y + h, 0., sx     , sy + sh, color),
        ];

For simplicity, let us say we are always drawing to location (0,0) from a source rectangle with origin also at (0,0). Our free parameters are 'w', 'h', 'sw', and 'sh'.

If we are drawing a 128x128 sample at 'real' size, we set w=128, h=128, sw=128, sh=128. Unfortunately, while the destination rectangle has the correct size (verts have 128 added for w and h), the source rectangle has UVs at (0,0), (128,0), (128, 128), (0, 128). Instead, we should divide the UVs by the texture width and texture height.

Call to request quit

Would be useful to have some call to request to quit the app (so close the program on desktops, exit application on mobile, stop processing on the web, etc...).

Constrain Mouse To Window (For First Person Camera infinite mouse scrolling)

I'm trying to get a first person 3D camera to work. Currently, I can successfully fly around the world and look using the mouse.

However, when the mouse reaches the edge of the screen, it hits the edge and no longer gives any mouse position information.

There are 2 ways to solve this that I can see:

  1. Keep sending mouse events when mouse is outside the window.
  2. Allow the user to set the mouse position so they can control wrapping the mouse when it goes outside the window.

I don't know if Sokol uses GLFW but in Raylib (GLFW), I have this same problem on Linux. Not quite sure how to solve it without a way to set the cursor position.

Note: I have used the ctx.set_cursor_grab(true) and ctx.show_mouse(false) functions and it doesn't change the above behavior.

Alternatively, if another 3D example could be created that tests the mouse look and screen border interaction that would be amazing.

Here is what I've got so far for reference:

use macroquad::prelude::*;
// use glam::vec3;

const MOVE_SPEED: f32 = 0.1;
const LOOK_SPEED: f32 = 0.1;


fn conf() -> Conf
{
    Conf {
        window_title: String::from("Macroquad"),
        window_width: 1260,
        window_height: 768,
        fullscreen: true,
        ..Default::default()
    }
}

#[macroquad::main(conf)]
async fn main() {
    let InternalGlContext { quad_context: ctx, ..} = unsafe { get_internal_gl() };

    ctx.show_mouse(false);
    ctx.set_cursor_grab(true);

    let dirt = load_texture("Dirt.png").await;
    dirt.set_filter(ctx, FilterMode::Nearest);

    let mut x = 0.0;
    let mut switch = false;
    let bounds = 8.0;


    let world_up = vec3(0.0, 1.0, 0.0);
    let mut yaw: f32 = 0.0;
    let mut pitch: f32 = 0.0;

    let mut facing = vec3(
        yaw.cos() * 1.0,
        0.0,
        yaw.sin() * 1.0
    ).normalize();

    let mut front = vec3(
        yaw.cos() * pitch.cos(),
        pitch.sin(),
        yaw.sin() * pitch.cos()
    ).normalize();
    let mut right = front.cross(world_up).normalize();
    let mut up;

    let mut position = vec3(0.0, 1.0, 0.0);
    let mut last_mouse_position: Vec2 = mouse_position().into();

    let mut own_mouse_position = vec2(0.0, 0.0);

    loop {
        let delta = get_frame_time();
        
        if is_key_pressed(KeyCode::Escape) { break; }

        if is_key_down(KeyCode::Up) { position += front * MOVE_SPEED; }
        if is_key_down(KeyCode::Down) { position -= front * MOVE_SPEED; }
        if is_key_down(KeyCode::Left) { position -= right * MOVE_SPEED; }
        if is_key_down(KeyCode::Right) { position += right * MOVE_SPEED; }

        let mouse_position: Vec2 = mouse_position().into();
        let mouse_delta = mouse_position - last_mouse_position;
        last_mouse_position = mouse_position;

        yaw += mouse_delta.x * delta * LOOK_SPEED;
        pitch += mouse_delta.y * delta * -LOOK_SPEED;

        pitch = if pitch > 1.5 { 1.5 } else { pitch };
        pitch = if pitch < -1.5 { -1.5 } else { pitch };

        facing = vec3(
            yaw.cos() * 1.0,
            0.0,
            yaw.sin() * 1.0
        ).normalize();
    
        front = vec3(
            yaw.cos() * pitch.cos(),
            pitch.sin(),
            yaw.sin() * pitch.cos()
        ).normalize();

        right = front.cross(world_up).normalize();
        up = right.cross(front).normalize();


        x += if switch { 0.04 } else { -0.04 };
        if x >= bounds || x <= -bounds { switch = !switch; }

        clear_background(Color::new(1.0, 0.7, 0.0, 1.0));

        // Going 3d!

        set_camera(Camera3D {
            position: position,
            up: up,
            target: position + front,
            ..Default::default()
        });

        draw_grid(20, 1.);

        draw_line_3d(vec3(x, 0.0, x), vec3(5.0, 5.0, 5.0), Color::new(1.0, 1.0, 0.0, 1.0));

        draw_cube_wires(vec3(0., 1., -6.), vec3(2., 2., 2.), DARKGREEN);
        draw_cube_wires(vec3(0., 1., 6.), vec3(2., 2., 2.), DARKBLUE);
        draw_cube_wires(vec3(2., 1., 2.), vec3(2., 2., 2.), YELLOW);

        draw_cube(vec3(x, 1., x), vec3(2., 2., 2.), dirt, WHITE);

        // Back to screen space, render some text

        set_default_camera();
        draw_text("WELCOME TO 3D WORLD", 10.0, 20.0, 30.0, BLACK);

        draw_text(format!("X: {} Y: {}", own_mouse_position.x, own_mouse_position.y).as_str(), 10.0, 48.0, 30.0, BLACK);
        draw_text(format!("X: {} Y: {}", mouse_position.x, mouse_position.y).as_str(), 10.0, 48.0 + 18.0, 30.0, BLACK);

        next_frame().await
    }
}

Question: Custom Geometry Rendering

Can an example be created or could someone point me in the right direction to be able to render a list of vertices/texcoords without a custom pipeline/shader? I'd like to use it like the other draw_...() functions if possible.

The goal here being to generate geometry in-game and then render it, but I don't need anything fancy (just textures).

How to Get Context In Macroquad

I'd like to set the filter mode for a texture:

texture.set_filter(&mut get_context(), FilterMode::Nearest);

Unfortunately, the get_context() function is private. How do I get the current context in order to use the functions that require it?

Window size

Сan i set the window size? and can i forbid changing it?

Design discussion: high-precision touch/mouse input

I really like the miniquad's event-based input with impl EventHandler for Stage because it allows the input to be independent from FPS. For example: input from touch can come 100 times per second even if draw happens at 30 FPS on mobile.

In macroquad's examples currently the input is polled on each frame (example: is_key_down), which makes the input rate tied to the framerate. This would be a problem for apps that rely on high-frequency input, example: painting apps or Fruit Ninja-like games, because the lines a person draws with their finger will miss some input data that changes in between frames. On phone, the input rate reported from the screen is typically 100 FPS, while games run at 30-60 FPS.

I propose to have a way to handle events in macroquad independent of the framerate in a similar way it's done in miniquad.

What is your opinion?

Arkanoid example glitched text

I just ran the Arkanoid example and saw that the "Press space to start" text wasn't working:

image

I have narrowed down the cause to be somewhere between 0.3.0-alpha.2 and 0.3.0-alpha.4:

  • 0.3.0-alpha.2: the example displays the text correctly
  • 0.3.0-alpha.3: the text is completely gone
  • 0.3.0-alpha.4 onward: the example looks like the above image

I compiled using rustc 1.49.0 on a Windows 10 laptop with an Intel UHD 620.

Can't run arkanoid example

$ cargo run --example arkanoid
Compiling macroquad v0.2.0-alpha.0 (E:\Projects\Rust\macroquad)
error[E0432]: unresolved imports macroquad::set_screen_coordinates, macroquad::ScreenCoordinates
--> examples\arkanoid.rs:3:5
|
3 | set_screen_coordinates, KeyCode, ScreenCoordinates,
| ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ no ScreenCoordinates in the root
| |
| no set_screen_coordinates in the root

error: aborting due to previous error

For more information about this error, try rustc --explain E0432.
error: could not compile macroquad.

can't run example

More examples with missed imports.
tree.rs
Compiling macroquad v0.2.0-alpha.0 (E:\Projects\Rust\macroquad)
error[E0433]: failed to resolve: use of undeclared type or module ScreenCoordinates
--> examples\tree.rs:31:28
|
31 | set_screen_coordinates(ScreenCoordinates::Fixed(-1., 1., -0.2, 1.4));
| ^^^^^^^^^^^^^^^^^ use of undeclared type or module ScreenCoordinates

error[E0425]: cannot find function set_screen_coordinates in this scope
--> examples\tree.rs:31:5
|
31 | set_screen_coordinates(ScreenCoordinates::Fixed(-1., 1., -0.2, 1.4));
| ^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

life.rs
Compiling macroquad v0.2.0-alpha.0 (E:\Projects\Rust\macroquad)
error[E0432]: unresolved imports macroquad::set_screen_coordinates, macroquad::ScreenCoordinates
--> examples\life.rs:3:19
|
3 | screen_width, set_screen_coordinates, update_texture, Image, ScreenCoordinates, BLACK, WHITE,
| ^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^ no ScreenCoordinates in the root
| |
| no set_screen_coordinates in the root

Build failed

$ cargo build
Compiling autocfg v1.0.0
Compiling byteorder v1.3.4
Compiling cfg-if v0.1.10
Compiling adler32 v1.0.4
Compiling cc v1.0.50
Compiling libc v0.2.68
Compiling crc32fast v1.2.0
Compiling bitflags v1.2.1
Compiling macroquad_macro v0.1.0 (E:\Projects\Rust\macroquad\macroquad_macro)
Compiling quad-rand v0.1.1
Compiling glam v0.8.6
Compiling num-traits v0.2.11
Compiling num-integer v0.1.42
Compiling num-rational v0.2.4
Compiling num-iter v0.1.40
Compiling inflate v0.4.5
Compiling sapp-windows v0.2.8
Compiling stb_truetype v0.3.1
Compiling deflate v0.7.20
Compiling ordered-float v1.0.2
Compiling approx v0.3.2
Compiling png v0.15.3
Compiling rusttype v0.8.3
Compiling miniquad v0.3.0-alpha.5
error[E0425]: cannot find function glPixelStorei in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics\texture.rs:151:13
|
151 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // miniquad always uses row alignment of 1
| ^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value GL_UNPACK_ALIGNMENT in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics\texture.rs:151:27
|
151 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // miniquad always uses row alignment of 1
| ^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value GL_TEXTURE_SWIZZLE_A in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics\texture.rs:158:52
|
158 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_RED as _);
| ^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value GL_TEXTURE_SWIZZLE_A in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics\texture.rs:161:52
|
161 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA as _);
| ^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value GL_ALPHA in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics\texture.rs:161:74
|
161 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA as _);
| ^^^^^^^^ help: a constant with a similar name exists: C1_ALPHA
|
::: C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\sapp-windows-0.2.8\src\sokol_app_msvc.rs:6775:1
|
6775 | pub const C1_ALPHA: u32 = 256;
| ------------------------------ similarly named constant C1_ALPHA defined here

error[E0425]: cannot find function glPixelStorei in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics\texture.rs:290:13
|
290 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // miniquad always uses row alignment of 1
| ^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value GL_UNPACK_ALIGNMENT in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics\texture.rs:290:27
|
290 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // miniquad always uses row alignment of 1
| ^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value GL_TEXTURE_SWIZZLE_A in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics\texture.rs:297:52
|
297 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_RED as _);
| ^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value GL_TEXTURE_SWIZZLE_A in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics\texture.rs:300:52
|
300 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA as _);
| ^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find value GL_ALPHA in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics\texture.rs:300:74
|
300 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ALPHA as _);
| ^^^^^^^^ help: a constant with a similar name exists: C1_ALPHA
|
::: C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\sapp-windows-0.2.8\src\sokol_app_msvc.rs:6775:1
|
6775 | pub const C1_ALPHA: u32 = 256;
| ------------------------------ similarly named constant C1_ALPHA defined here

error[E0425]: cannot find function glDeleteFramebuffers in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics.rs:568:18
|
568 | unsafe { glDeleteFramebuffers(1, &mut render_pass.gl_fb as *mut _) }
| ^^^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: glGenFramebuffers
|
::: C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\sapp-windows-0.2.8\src\sokol_app_msvc.rs:41804:5
|
41804 | pub fn glGenFramebuffers(n: GLsizei, framebuffers: *mut GLuint);
| ---------------------------------------------------------------- similarly named function glGenFramebuffers defined here

error[E0425]: cannot find function glFrontFace in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics.rs:669:21
|
669 | glFrontFace(GL_CW);
| ^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function glFrontFace in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics.rs:672:21
|
672 | glFrontFace(GL_CCW);
| ^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function glCullFace in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics.rs:698:17
|
698 | glCullFace(GL_FRONT);
| ^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function glCullFace in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics.rs:702:17
|
702 | glCullFace(GL_BACK);
| ^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function glStencilOpSeparate in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics.rs:773:17
|
773 | glStencilOpSeparate(
| ^^^^^^^^^^^^^^^^^^^ help: a static with a similar name exists: _sapp_glStencilOpSeparate
|
::: C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\sapp-windows-0.2.8\src\sokol_app_msvc.rs:41977:5
|
41977 | pub static mut _sapp_glStencilOpSeparate: PFN_glStencilOpSeparate;
| ------------------------------------------------------------------ similarly named static _sapp_glStencilOpSeparate defined here

error[E0425]: cannot find function glStencilFuncSeparate in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics.rs:779:17
|
779 | glStencilFuncSeparate(
| ^^^^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: glBlendFuncSeparate
|
::: C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\sapp-windows-0.2.8\src\sokol_app_msvc.rs:42468:5
|
42468 | / pub fn glBlendFuncSeparate(
42469 | | sfactorRGB: GLenum,
42470 | | dfactorRGB: GLenum,
42471 | | sfactorAlpha: GLenum,
42472 | | dfactorAlpha: GLenum,
42473 | | );
| |______- similarly named function glBlendFuncSeparate defined here

error[E0425]: cannot find function glStencilMaskSeparate in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics.rs:785:17
|
785 | glStencilMaskSeparate(GL_FRONT, front.write_mask);
| ^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function glStencilOpSeparate in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics.rs:788:17
|
788 | glStencilOpSeparate(
| ^^^^^^^^^^^^^^^^^^^ help: a static with a similar name exists: _sapp_glStencilOpSeparate
|
::: C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\sapp-windows-0.2.8\src\sokol_app_msvc.rs:41977:5
|
41977 | pub static mut _sapp_glStencilOpSeparate: PFN_glStencilOpSeparate;
| ------------------------------------------------------------------ similarly named static _sapp_glStencilOpSeparate defined here

error[E0425]: cannot find function glStencilFuncSeparate in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics.rs:794:17
|
794 | glStencilFuncSeparate(
| ^^^^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: glBlendFuncSeparate
|
::: C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\sapp-windows-0.2.8\src\sokol_app_msvc.rs:42468:5
|
42468 | / pub fn glBlendFuncSeparate(
42469 | | sfactorRGB: GLenum,
42470 | | dfactorRGB: GLenum,
42471 | | sfactorAlpha: GLenum,
42472 | | dfactorAlpha: GLenum,
42473 | | );
| |______- similarly named function glBlendFuncSeparate defined here

error[E0425]: cannot find function glStencilMaskSeparate in this scope
--> C:\Users\mam0nten0k.cargo\registry\src\github.com-1ecc6299db9ec823\miniquad-0.3.0-alpha.5\src\graphics.rs:800:17
|
800 | glStencilMaskSeparate(GL_BACK, back.write_mask);
| ^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error: aborting due to 21 previous errors

For more information about this error, try rustc --explain E0425.
error: could not compile miniquad.
warning: build failed, waiting for other jobs to finish...
error: build failed

Window size

Сan i set the window size? and can i forbid changing it?

Можно ли задать размеры окна и запретить пользователю ресайзить его?

Roadmap

I'm currently learning Macroquad while I finish a project started with a different library.

I'm actively interested in any new (even cutting edge) features of Macroquad.

Could a roadmap be appended to the README that just says what you're currently working toward feature-wise?

Example does not work without modifications

I got the docs from here: https://docs.rs/macroquad/0.3.0-alpha.14/macroquad/index.html I'm using Macroquad 0.2.9.

I am using Elive Linux 3.8.17. My Cargo.toml looks like this:

[package]
name = "musicmania"
version = "0.0.1"
authors = ["TheTechRobo"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
macroquad = "^0.2.9"
[profile.dev.package.'*']
opt-level = 3

Here is the error:

error[E0432]: unresolved import `macroquad::prelude`
 --> src/main.rs:1:16
  |
1 | use macroquad::prelude::*;
  |                ^^^^^^^ could not find `prelude` in `macroquad`

error[E0425]: cannot find function `clear_background` in this scope
 --> src/main.rs:6:21
  |
6 |                     clear_background(RED);
  |                     ^^^^^^^^^^^^^^^^ not found in this scope
  |
help: consider importing this function
  |
1 | use macroquad::clear_background;
  |
[...]

this is my code:

use macroquad::prelude::*;

#[macroquad::main("BasicShapes")]
async fn main() {
        loop {
                    clear_background(RED);

                            draw_line(40.0, 40.0, 100.0, 200.0, 15.0, BLUE);
                                    draw_rectangle(screen_width() / 2.0 - 60.0, 100.0, 120.0, 60.0, GREEN);
                                            draw_circle(screen_width() - 30.0, screen_height() - 30.0, 15.0, YELLOW);
                                                    draw_text("HELLO", 20.0, 20.0, 20.0, DARKGRAY);

                                                            next_frame().await
                                                                    }
}

Any help would be appreciated. I'm still new to Rust. I'll try changing the example code.

Notes on the time module

  • get_fps should probably return FPS over some period of time (or number of frames) - that way, it would report a stable 60 on 60 FPS screens if the game runs fast enough, otherwise it would show less and it would be obvious that frames are dropped. Note i tried several methods of calculating the average, some of them produce numbers like 59.9 or 60.1. I found that saving n timestamps, then using (first - last) / (n - 1) works well (e.g. https://github.com/martin-t/rec-wars/blob/6a04b5f5b7191bbc3ccea95c0a7886a05f761f04/src/timing.rs#L5).

  • I find the name get_frame_time misleading. I updated the docs (#133) but i think it should be renamed to get_frame_duration. Time to me implies a point in time, duration implies how long something took. I think this potential for confusion is even more apparent here: Context::start_time and Context::last_frame_time are points in time vs Context::frame_time is duration.

  • I would like a way to measure how much time was spent rendering. My understanding of macroquad is that the draw calls in main just queue up what's to be rendered but the actual rendering happens after calling next_frame().await. Is that correct? In that case there's no way to measure time spend rendering from game code.

Long labels don't render

Not sure if this is megaui or macroquad. If I make the label one character shorter, the text renders, otherwise it doesn't.

This is with web assembly and chrome.

use macroquad::{self as mq, hash};
use megaui::{self};

#[macroquad::main("TestWindow")]
async fn main() {
    loop {
        mq::clear_background(mq::BLACK);

        let window_params = mq::WindowParams {
            movable: false,
            close_button: false,
            titlebar: false,
            ..mq::WindowParams::default()
        };

        mq::set_ui_style(megaui::Style {
            window_background_focused: megaui::Color::from_rgb(0, 0, 0),
            window_background_inactive: megaui::Color::from_rgb(0, 0, 0),
            focused_text: megaui::Color::from_rgb(255, 255, 255),
            inactive_text: megaui::Color::from_rgb(255, 255, 255),
            ..megaui::Style::default()
        });

        let margin = 0.01;

        mq::draw_window(
            hash!(),
            mq::Vec2::new(mq::screen_width() * margin, mq::screen_height() * margin),
            mq::Vec2::new(
                mq::screen_width() * (1.0 - margin * 2.0),
                mq::screen_height() * 0.60,
            ),
            mq::WindowParams {
                label: "".into(),
                ..window_params
            },
            |ui| {
                ui.label(None, "what if this is really long and goes on for a long time and keeps filling up all of the room when the screen for text until no more will fitwhat if this is really long and goes on for a long time and keeps filling up all of the room when the screen for text until no more will fitwhat if this is really long and goes on for a long time and keeps filling up all of the room when the screen for text until no more will fitwhat if this is really long and goes on for a long time and keeps filling up all of the room when the screen for text until no more will fitwhat if this is really long and goes on fooooooooooooooooooooooooooooooooooooo eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee teeeeeeeeeeeeee teeeeeeeeeeeeee teeeeeeeeeeeeee teeeeeeeeeeeeee teeeeeeeeeeeeee teeeeeeeeeeeeee teeeeeeeeeeeeee teeeeeeeeeeeeee teeeeeeeeeeeeee teeeeeeeeeeeeee t");
            },
        );
        mq::next_frame().await
    }
}

Text in arkanoid example is invisible

At the start:

    // build camera with following coordinate system:
    // (0., 0)     .... (SCR_W, 0.)
    // (0., SCR_H) .... (SCR_W, SCR_H)
    set_camera(Camera2D {
        zoom: vec2(1. / SCR_W * 2., -1. / SCR_H * 2.),
        target: vec2(SCR_W / 2., SCR_H / 2.),
        ..Default::default()
    });

But then when text is drawn:

            draw_text(
                "Press space to start",
                screen_width() / 2. - 140.,
                screen_height() / 2.,
                30.,
                mq::BLACK,
            );

2 issues here:

  • draw_text appears to be respecting the camera coordinate system, so screen_width and screen_height are way out of bounds because they are almost always greater than 20
  • it also appears to be applying the coordinate transformation to the text size, not sure if this is intentional, so 30 is HUGE. I can see the text if I use:
        draw_text(
            "Press space to start",
            SCR_W / 2.,
            SCR_H / 2.,
            1.,
            mq::GREEN,
        );

I'm compiling to web assembly and viewing in Chrome in case that's relevant.

It would be nice if there was a way for me to draw text knowing that the text wouldn't be stretched or distorted at all, but I don't know how to choose the font size based on the camera parameters so that the original font pixels and the screen exactly line up?

shadertoy example

Could not run shadertoy example.
rustc spits out this

thread 'main' panicked at 'Not such texture: rust.png', src/texture.rs:20:50

But the error message is clear and reason is obvious, so I sorted it out.
But the question remains. Would not it be better to update paths to run from the root of the crate, without going under /examples?
Totally for you to decide.
The demo is AWESOME. Especially when I am learning shaders now and able to understand how it works.

How to include resources into apk?

I successfully created the apk for Android. But how can I include a png into it? When I compile the example "texture.rs" on my pc at runtime it finds "ferris.png", but on Android I need to include this image into the apk (in the right path).
Maybe this is not the right place to ask, so where can I learn the stuff about making the apk? Now I simply use this command:
$ docker run --rm -v $(pwd)":/root/src" -w /root/src notfl3/cargo-apk cargo apk build --example texture

Problem building WASM

Looking into using macroquad for a WASM prototype. For some reason the WASM build seems to be failing on a missing import.

image

Just following the documentation, and double checked everything. gl.js which is placed online maybe outdated?

Great work on the implementation, and fundamental choices.

How to use this library?

Sorry, I just began to use Rust for a short while. And I am trying to use your lib.
I work on Linux. I create a new project by "cargo new ... " command. I put "macroquad = "0.2.9" in the Cargo.toml. And I copied your example folder's code into mine. But from the very beginning, I received a lot of error by the compiler. Such as "can not find prelude", "can not find Conf" and etc.
I don't know what I should do. Thanks for help!

Artifacts on rectangle/texture edges

Issue:

When placed on non-integer coordinates both drawn rectangles (I suspect this applies to all shapes) and textures (in FiterMode::Nearest where it shouldn't be the case!) get visible artifacts.

Example for rectangle:
obraz
Example for a texture:
obraz
Correctly rendered texture by attaching a 1px transparent border to it:
obraz

Reproduction:

Bug can be reproduced by putting the following file in the examples folder and running cargo run --example filter_err:
https://paste.ofcode.org/MuS8ezGpuwvPg2BxM6FBRq
Additional instructions inside.
To test the version with file download these 2 additional images and put them in the examples folder:
(borderless.png)
borderless
(border.png)
border

Performed tests:

  • rounding to integer coordinates [fixes the issue, but not a valid solution with a zoom]
  • using draw_texture_ex to explicitly set the drawn area [doesn't work]
  • adding border to the image and always drawing the 1px border [fixes the issue, hints at possible off-by-one error in the source code and can't be used for rectangles and other provided shapes]

Specs:

Windows 10, newest version of stable Rust, branch 0.3 of macroquad

mouse_position() doesn't work on Android

On Desktop no problems. On the Android smartphone (touchscreen) mouse_position() gets updated only if you keep pressing your finger against the screen while moving it. If you just touch the screen without moving the position of your finger mouse_position() doesn't update, and gets the last value.
So you can't even click on a button. You can only do gestures. You can know whether you touched the screen (with is_mouse_button_down) but you don't know the position, if you just do a single tap.
But maybe I'm missing something.

Blurry text using `draw_text`

When using the draw_text method, the text drawn is blurry at higher font sizes. Doe this have to do with the fact that a picture is used as a font? Is there a way to get a better looking text at higher font sizes?

High CPU resources in Window 10.

When I run the texture example I get 17-19% CPU resources.
That's really high.

My machine:
Intel i7-8750H
NVIDIA GeForce GTX 1060

As reference in Discord I had a discussion about the issue and I had a report that in Linux it is around 2% and that sounds about right.

3d.exe example binary doesn't work

When I do cargo run --example 3d works fine, but when I try to run actuall 3d.exe from target dir, two windows pop up and instantly close.
At this moment I saw it only with 3d example, but I didn't tried all. Tree and asteroids are working fine.

Add multi-touch support on Android

Currently, you can only get the primary touch position using mouse_position().
However, most smartphones support multiple touch positions, and this feature is a must in most games.
As this feature already exists in microquad, it shouldn't be too hard to implement it in macroquad.

touch down/up do not update mouse position

since touches are translated into mouse events by default we should also update the mouse position in mouse_button_down_event and co. otherwise reading the mouse_position after is_mouse_button_down is outdated.

PR follows

Error handling for load_texture

Hi,

There's a few places where the code can panic:

.unwrap_or_else(|e| panic!("Error loading texture: {}", e));

Also in quad-gl:
https://github.com/not-fl3/quad-gl/blob/3e0bbc0e36fd960c4e99a611a1d94b5d4bb9523e/src/lib.rs#L573
https://github.com/not-fl3/quad-gl/blob/3e0bbc0e36fd960c4e99a611a1d94b5d4bb9523e/src/lib.rs#L577

Could it be possible to return a Result instead?
I believe there's not error type yet, so we'd need to define this first?

swap interval, how to set?

Is there any way to set the swap_interval to control vsync?
I would like to disable vsync - but found no way to do this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.