0

i tried drawing a texture but it didn't show anything:

#include "raylib.h"
#include "string"
int main()
{
    const int screenWidth = 800;
    const int screenHeight = 450;
    InitWindow(screenWidth, screenHeight, "Texture Location Example");

    
    Texture2D texture = LoadTexture("/Users/stavanmukherjee./Downloads/raylib-master 2/build/raylib-cpp/projects/VSCode/raylib-cpp-starter/src/triangle.png");

    Vector2 center = { static_cast<float>(texture.width / 2.0), static_cast<float>(texture.height / 2.0) };

    while (!WindowShouldClose())
    {
        BeginDrawing();

        ClearBackground(RAYWHITE);


        DrawTexturePro(texture, { 0.0f, 0.0f, static_cast<float>(texture.width), static_cast<float>(texture.height) }, 
            { screenWidth / 2.0f, screenHeight / 2.0f }, center, 0.0f, BLACK);

        std::string text = "Texture Location: (" + std::to_string(screenWidth / 2.0f - center.x) + ", " + std::to_string(screenHeight / 2.0f - center.y) + ")";
        DrawText(text.c_str(), 10, 10, 20, BLACK);

        EndDrawing();
    }

    UnloadTexture(texture);
    CloseWindow();

    return 0;
}

ps:(it showed the texture was rendering in the right place but it wasent showing. I am also using the raylib-cpp-starter library)

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Apr 04 '23 at 21:20

1 Answers1

0

I didn't quite test it, but as a suggestion, call DrawTexturePro as

DrawTexturePro(texture, { 0.0f, 0.0f, texture.width, texture.height }, 
        { screenWidth / 2.0f, screenHeight / 2.0f, texture.width, texture.height }, {texture.width / 2, texture.height / 2}, 0.0f, WHITE);

This could solve your problem, because

  • DrawTexturePro expects a destination Rect, you have given an x- and y- coordinate for the dst_rect, but no width/heigth (so the texture is rendered on the correct position but with no width or height)
  • tinting your texture BLACK will fill every color with black. If you want to display the "native" texture, use WHITE for tinting.
ge3X0
  • 1
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 21 '23 at 02:56