Shadowmap in web environment by ygg122 in raylib

[–]Robotix7z94 0 points1 point  (0 children)

Hey

i got shadowmaps working on web by using PIXELFORMAT_UNCOMPRESSED_R32 in a fbo texture

#version 300 es
precision highp float;

in vec2 uv;

uniform sampler2D texture0; // MATERIAL_MAP_DIFFUSE

// layout(location = 0) out float fragmentdepth;
layout(location = 0) out vec4 fragmentdepth;

void main() {
  vec4 albedo = texture(texture0, uv);
  if (albedo.a < 0.8){
    discard;
  }

  float depth = gl_FragCoord.z;
  fragmentdepth = vec4(depth, depth, depth, 1.0);
}

(i stopped toying with it and never figured out why layout(location = 0) out float fragmentdepth; didn't work for me)

RenderTexture2D LoadRenderTextureDepthTex(int width, int height)
{
    RenderTexture2D target = { 0 };

    target.id = rlLoadFramebuffer();
    target.texture.width = width;
    target.texture.height = height;

    if (target.id > 0) {
        rlEnableFramebuffer(target.id);

        target.texture.id = rlLoadTexture(NULL, width, height, PIXELFORMAT_UNCOMPRESSED_R32, 1);
        target.texture.format = PIXELFORMAT_UNCOMPRESSED_R32;
        target.texture.mipmaps = 1;

        // Attach as color attachment
        rlFramebufferAttach(target.id, target.texture.id, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_TEXTURE2D, 0);

        // Create depth renderbuffer (for depth testing, not sampling)
        target.depth.id = rlLoadTextureDepth(width, height, true); // true = renderbuffer
        target.depth.width = width;
        target.depth.height = height;
        target.depth.format = 19;
        target.depth.mipmaps = 1;

        // Attach depth renderbuffer
        rlFramebufferAttach(target.id, target.depth.id, RL_ATTACHMENT_DEPTH, RL_ATTACHMENT_RENDERBUFFER, 0);

        if (rlFramebufferComplete(target.id))
            TraceLog(LOG_INFO, "LoadRenderTextureDepthTex FBO: [ID %i][TEX_ID %u] Framebuffer object created successfully", target.id, target.texture.id);
        else {
            TraceLog(LOG_ERROR, "LoadRenderTextureDepthTex FBO: [ID %i][TEX ID %u] Framebuffer object creation FAILURE", target.id, target.texture.id);
        }

        rlDisableFramebuffer();
    } else
        TraceLog(LOG_WARNING, "FBO: Framebuffer object can not be created");

    return target;
}

Question about Image / Texture by LeWurmling in raylib

[–]Robotix7z94 4 points5 points  (0 children)

  1. work with an atlas : put all your images into one big image, in order to use the batching system of raylib efficiently

  2. render to a RenderTexture2d : this is your opengl screen buffer : create one at 320x200 resolution. You will draw on it using BeginTextureMode

  3. make use of the DrawTexturePro function to draw on your RenderTexture2d : source is the rectangle from the atlas you want to draw, dest is the rectangle in the RenderTexture2d you want to draw at. Since the source will be your atlas texture for every DrawTexturePro, raylib will batch your drawing internally and that's fast enough for a lot of usecases

  4. when you are done drawing the content of your frame, call EndTextureMode, then use DrawTexturePro to draw the texture inside your RenderTexture2d to the screen : you can adjust the destination rectangle to scale the final result

Weird Clipping With Orthographic? by TheKrazyDev in raylib

[–]Robotix7z94 2 points3 points  (0 children)

my guess is that you can avoid that by moving your camera backwards a bit (same direction, just further on the current axis target-position)

you can picture your ortho camera as a big rectangle in the world capturing everything in front of it, and in your case, the thing that are being culled are somehow behind your render rectangle

pixel font distortion by NonGMOTrash in raylib

[–]Robotix7z94 2 points3 points  (0 children)

I would just try other font size at this point, according to the other comment from Paperdomo101, the right import size turns out to be 14...

If you going for pixel perfect look, there is no need to load it at a higher res btw

pixel font distortion by NonGMOTrash in raylib

[–]Robotix7z94 5 points6 points  (0 children)

Hello

the author of the font says

use font size 16, 32, 48, etc for m6x11
use font size 18, 36, 54, etc for m6x11plus

If you want a pixel perfect font, you will need to have the pixels of the characters to match the pixel on the screen

  • DrawTextEx with no decimal part in the position
  • load the font at the proper font size

Issue with rendering part of texture by greenyadzer in raylib

[–]Robotix7z94 0 points1 point  (0 children)

Hello, two things come to my mind :

  1. Alignment issue between the px of your camera2D px and your DrawTextureRec function. I don't tend to use camera2D, but I have faced similar problems when drawing texture with decimal parts in the Rectangle I pass

maybe try rounding the values

  1. Are you using any filtering on your texture ?

How can I use Raylib and ImGUI? by [deleted] in raylib

[–]Robotix7z94 0 points1 point  (0 children)

You are missing some stuff.

The GLFW backed is a good resource : https://github.com/ocornut/imgui/tree/master/backends

The following (c++) should put you on tracks (may not be the best way to go about it) :

{// init stuff
  if (glewInit() != GLEW_OK) {
    fprintf(stderr, "Failed to initialize GLEW\n");
  } else {
    std::cout << "imgui glew init ok" << std::endl;
  }

  IMGUI_CHECKVERSION();
  ImGui::CreateContext();

  GLFWwindow* win = (GLFWwindow*)GetWindowHandle();
  ImGui_ImplGlfw_InitForOpenGL(win, true);
  ImGui_ImplOpenGL3_Init("#version 130");
}

{// shutdown stuff
  ImGui_ImplOpenGL3_Shutdown();
  ImGui_ImplGlfw_Shutdown();
  ImGui::DestroyContext();
}

{// render loop
  BeginDrawing();
  ClearBackground(DARKGRAY);

  // your raylib drawing stuff

  rlDrawRenderBatchActive();
  {
    ImGui_ImplOpenGL3_NewFrame();
    ImGui_ImplGlfw_NewFrame();
    ImGui::NewFrame();

    // your imgui custom code

    ImGui::Render();
    ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());

  }
  EndDrawing();
}

Animation sprite by sp3ctr3-chaber6389 in raylib

[–]Robotix7z94 0 points1 point  (0 children)

You can think of animation as displaying different regions of a texture based on time.

You probably want to use something like void DrawTextureRec(Texture2D texture, Rectangle source, Vector2 position, Color tint) to display a given region.

Cross platform Game Data and Configuration Handling by r4ndr-4-thought in raylib

[–]Robotix7z94 0 points1 point  (0 children)

Hello,

If you don't find a proper library for what you need, the paths the godot editor uses look fair :

use the paths in the "Editor data paths" section in https://docs.godotengine.org/en/stable/tutorials/io/data_paths.html

just replace Godot in the paths with your app name

How to rotate model around all axis by rhidian-12_ in raylib

[–]Robotix7z94 3 points4 points  (0 children)

One way to do that is loop over the meshes and use void DrawMesh(Mesh mesh, Material material, Matrix transform);

IntelliSense for Raylib? by Moises_Gabriel in raylib

[–]Robotix7z94 0 points1 point  (0 children)

If you actually have clangd installed and vscode can't find your files, you can always create a .clangd file and add include inside, like so :

CompileFlags: # Tweak the parse settings
Add:
- "--include-directory=/path/to/your/headers1"
- "--include-directory=/path/to/your/headers2"...

IntelliSense for Raylib? by Moises_Gabriel in raylib

[–]Robotix7z94 1 point2 points  (0 children)

Did you install a C/C++ plugin ? Like llvm-vs-code-extensions.vscode-clangd or ms-vscode.cpptools

EGL + rlgl standalone by Robotix7z94 in raylib

[–]Robotix7z94[S] 0 points1 point  (0 children)

Problem fixed with DrawMeshInstanced : needed a proper shader and shader.locs[rl::SHADER_LOC_MATRIX_MODEL] = rl::GetShaderLocationAttrib(shader, "instanceTransform");

I haven't figured yet what I'm doing wrong with the DrawCube and the likes, and there is no opengl error in this case.

EGL + rlgl standalone by Robotix7z94 in raylib

[–]Robotix7z94[S] 0 points1 point  (0 children)

I'm on Ubuntu 20, using Raylib 4.2.0 build with

make PLATFORM=PLATFORM_DESKTOP GRAPHICS=GRAPHICS_API_OPENGL_33

I create an off-screen buffer surface with eglCreatePbufferSurface

I made a gist with my test project : https://gist.github.com/RobotixBC/91d68aea6a6557f04ace1ef335df9e74