Texture Error Codes?

edited August 8 in raylib: textures
What I am doing wrong? All I did was trying make Variable for lands and clouds but I keep getting errors

#include "raylib.h"

int main()
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;

InitWindow(screenWidth, screenHeight, "raylib [textures] example - image loading");

// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)

Image lands = LoadImage("resources/foregrounds.png"); // Loaded in CPU memory (RAM)
Texture2D texture = LoadTextureFromImage(image); // The Grass Land.....


Image image = LoadImage("resources/Clouds1.png");
Texture2D clouds = LoadTextureFromImage(image);

UnloadImage(image); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM

//------------------------------------------------------------------------------------

// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
//----------------------------------------------------------------------------------

// Draw
//----------------------------------------------------------------------------------
BeginDrawing();

ClearBackground(RAYWHITE);

DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE);

DrawTexture(clouds, 50, 50, WHITE);

// DrawText("this IS a texture loaded from an image!", 300, 370, 10, GRAY);

EndDrawing();
//----------------------------------------------------------------------------------
}

// De-Initialization
//--------------------------------------------------------------------------------------
UnloadTexture(texture); // Texture unloading

CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------

return 0;
}

Comments


  • error: 'image' undeclared (first use in this function); did you mean 'Image'?
    Texture2D texture = LoadTextureFromImage(image); // The Grass Land.....
    ^~~~~
    Image
  • I did corrected it but still get errors thought.....

    So I decide do very basic image showing like this

    [code]
    #include "raylib.h"

    int main()
    {
    // Initialization
    //--------------------------------------------------------------------------------------
    int screenWidth = 800;
    int screenHeight = 450;

    InitWindow(screenWidth, screenHeight, "raylib [textures] example - image drawing");

    // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)

    Image grass = LoadImage("resources/block2.png"); // Load image in CPU memory (RAM)

    UnloadImage(grass); // Unload image from RA

    // SetTargetFPS(60);
    //---------------------------------------------------------------------------------------

    // Main game loop
    while (!WindowShouldClose()) // Detect window close button or ESC key
    {
    // Update
    //----------------------------------------------------------------------------------
    // TODO: Update your variables here
    //----------------------------------------------------------------------------------

    // Draw
    //----------------------------------------------------------------------------------
    BeginDrawing();

    ClearBackground(RAYWHITE);

    DrawTexture(grass, 0, 0, WHITE);

    EndDrawing();
    //----------------------------------------------------------------------------------
    }

    // De-Initialization
    //--------------------------------------------------------------------------------------
    UnloadTexture(grass); // Texture unloading

    CloseWindow(); // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
    }
    [/code]

    I still got error and can you correct it for me because it seem like I pulling my hair out lol
  • grass is an Image, it should be a Texture.

    Please, check raylib examples carefully.
Sign In or Register to comment.