Starting with Raylib

Started by Pakz, April 05, 2020, 17:50:57

Previous topic - Next topic

guest7581

Strange. Raylib works smooth on my laptop. Online examples work smooth on every device I've tried (Windows, Linux, Android). And what do you mean by "soft"?

Aurel [banned]

#16
When i catch some time i will show you openGL app created in Oxygenbasic where work far better and smooth than with raylib.
Anyway ..there is also another choice using SFML
Then I'd suggest programming something purely graphical (i.e. not Windows GUIs, just graphics - video games and stuff). You don't need to know anything about Win32 for that. Take a look at SFML. It's a general 2D/3D drawing API. It also offers useful functions for sound, timing, networking, maths, etc.
It'd be WAY more interesting and rewarding than trying to learn win32. It's clean, it's easy to use, it lets you do draw whatever you want however you want. It's not a good tool for designing GUIs, but designing GUIs in win32 is a pain in the butt.
-> this one is not true at all..my comment

To illustrate: here's a complete working C++ app that displays a sprite and allows you to move it around with the arrow keys and rotate it with +/-, using SFML. Doesn't that look fun?

////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>

////////////////////////////////////////////////////////////
/// Entry point of application
///
/// \return Application exit code
///
////////////////////////////////////////////////////////////
int main()
{
   // Create the main rendering window
   sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
   // Load the sprite image from a file
   sf::Image Image;
   if (!Image.LoadFromFile("sprite.tga"))
      return EXIT_FAILURE;
   // Create the sprite
   sf::Sprite Sprite(Image);
   // Change its properties
   Sprite.SetColor(sf::Color(0, 255, 255, 128));
   Sprite.SetPosition(200.f, 100.f);
   Sprite.SetScale(2.f, 2.f);
   // Start game loop
   while (App.IsOpened())
   {
      // Process events
      sf::Event Event;
      while (App.GetEvent(Event))
      {
         // Close window : exit
         if (Event.Type == sf::Event::Closed)
            App.Close();
      }
      // Get elapsed time
      float ElapsedTime = App.GetFrameTime();
      // Move the sprite
      if (App.GetInput().IsKeyDown(sf::Key::Left))  Sprite.Move(-100 * ElapsedTime, 0);
      if (App.GetInput().IsKeyDown(sf::Key::Right)) Sprite.Move( 100 * ElapsedTime, 0);
      if (App.GetInput().IsKeyDown(sf::Key::Up))   Sprite.Move(0, -100 * ElapsedTime);
      if (App.GetInput().IsKeyDown(sf::Key::Down))  Sprite.Move(0,  100 * ElapsedTime);
      // Rotate the sprite
      if (App.GetInput().IsKeyDown(sf::Key::Add))     Sprite.Rotate(- 100 * ElapsedTime);
      if (App.GetInput().IsKeyDown(sf::Key::Subtract)) Sprite.Rotate(+ 100 * ElapsedTime);
      // Clear screen
      App.Clear();
      // Display sprite in our window
      App.Draw(Sprite);
      // Display window contents on screen
      App.Display();
   }
   return EXIT_SUCCESS;
}
(Y)

guest7581

Quote from: Aurel on April 20, 2020, 16:16:13
When i catch some time i will show you openGL app created in Oxygenbasic where work far better and smooth than with raylib.

To show me the difference between Raylib and OxygenBasic you would have o make a video. I don't have Windows on my computer and can't be bother with installing anything and compiling on my sons' laptops, since I know there will be no difference. What happens on your machine is a different story, of course.

Hotshot

#18
I am doing Raylib too but got errors for some reasons!

I will be doing 7 Layers added on if I get the errors sort out first.


typedef struct Paralax_Layers
{
    Vector2 ScrollSpeed;
    Vector2 Scroll_Position;
    Texture ImageTexture;
             
} Paralax_Layers;

Paralax_Layers Layers[7];

int main(void)
{
    // Initialization   
    const int screenWidth = 800;
    const int screenHeight = 450;   
   
    InitWindow(screenWidth, screenHeight, "raylib [textures] example - background scrolling");

    Layers[0].ImageTexture = LoadTexture("resources/cyberpunk_street_background.png");
       
    SetTargetFPS(60);     
   
    float scrollingBack = 0.0f;
   
    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        scrollingBack -= 5.0f;
       
        // NOTE: Texture is scaled twice its size, so it sould be considered on scrolling       
        if (scrollingBack <= -background.width*2) scrollingBack = 0;         //  << Dunno why I got error there
               
        BeginDrawing();

            ClearBackground(GetColor(0x052c46ff));

            // Draw background image twice
            // NOTE: Texture is scaled twice its size
            DrawTextureEx(Layers[0].ImageTexture , (Vector2){scrollingBack, 20 }, 5.0f, 2.0f, WHITE);
            DrawTextureEx(Layers[0].ImageTexture , (Vector2){scrollingBack, 20 }, 5.0f, 2.0f, WHITE);
           
        EndDrawing();
    }
   
    // De-Initialization   
    UnloadTexture(Layers[0].ImageTexture );
   
    CloseWindow();   

    return 0;
}


My Error say

> Compile program
-----------------------
tcc -o textures_background_scrolling2.exe textures_background_scrolling2.c C:\raylib\raylib\src\raylib.rc.data -Os -std=c99 -Wall -Iexternal -DPLATFORM_DESKTOP -lmsvcrt -lraylib -lopengl32 -lgdi32 -lwinmm -lkernel32 -lshell32 -luser32 -Wl,-subsystem=gui
Process started (PID=7972) >>>
textures_background_scrolling2.c:47: error: 'background' undeclared
<<< Process finished (PID=7972). (Exit code 1)

Pakz

The background in your code. Is that supposed to be the layers[]? You try to get the width from that and you have not declared or loaded gfx into that.

Aurel [banned]

Hmm
I have tried several C++ IDE-s and even download mingw32-gcc7.3.0 and whole complete smfl pack
and constantly have errors..?
anyone can compile abouve example?
(Y)

Hotshot

Quote
The background in your code. Is that supposed to be the layers[]? You try to get the width from that and you have not declared or loaded gfx into that.

background texture is not defined and does it mean I have do this?

2D Texture  Background.width*2;


Pakz

From what I can see is that you want to scroll these background images. You need to know the width of a texture. I think you could try and use :

if (scrollingBack <= -Layers[0].ImageTexture.width*2) scrollingBack = 0; 

Not sure if this works though.

Maybe you could take apart your code and make more simpler variants. Make one listing where you load one texture and scroll this one. And one version where you read the width of a texture. Get to know raylib its system. When you have the individual parts working make the more complete version, that what you want to do now.


zelda64bit

Very good these examples, thanks for sharing them.

I have a problem with raylib's notepad ++. When I create multiple .c files and .h files and try to compile it I get an error. Is there any way to modify the compiler options so that it lets me use multiple files.

Another thing, you can't work with c ++ from notepad ++ either, some way to work with modern c ++ from notepad ++ by modifying the option settings when pressing f6.

Hotshot

#24
Quote
From what I can see is that you want to scroll these background images. You need to know the width of a texture. I think you
could try and use :

if (scrollingBack <= -Layers[0].ImageTexture.width*2) scrollingBack = 0;

Not sure if this works though.

work Great :)  Thanks  8)

Quote
Maybe you could take apart your code and make more simpler variants. Make one listing where you load one texture and scroll this one. And one version where you read the width of a texture. Get to know raylib its system. When you have the individual parts working make the more complete version, that what you want to do now.

I agree with that and I love using Struct....

Hotshot

#25
Quote
I have a problem with raylib's notepad ++. When I create multiple .c files and .h files and try to compile it I get an error. Is there any way to modify the compiler options so that it lets me use multiple files.

Another thing, you can't work with c ++ from notepad ++ either, some way to work with modern c ++ from notepad ++ by modifying the option settings when pressing f6.

I am not sure but you could join discord of Raylib to ask questions there and they are great help!

Raylib Discord is here  https://discord.com/invite/mzCY3wN


Aurel [banned]

QuoteI have a problem with raylib's notepad ++. When I create multiple .c files and .h files and try to compile it I get an error. Is there any way to modify the compiler options so that it lets me use multiple files.
you need to use some better IDE and build project with your files..i mean add c and h files into project.
(Y)

zelda64bit

Quote from: Aurel on June 05, 2021, 20:20:40
QuoteI have a problem with raylib's notepad ++. When I create multiple .c files and .h files and try to compile it I get an error. Is there any way to modify the compiler options so that it lets me use multiple files.
you need to use some better IDE and build project with your files..i mean add c and h files into project.

The ide I use to learn c / c ++ is zinjai, which is really good, but I have no idea how it can be used with raylib.

I tried the template for the code block but it gives me an error and is impossible to use.

Aurel [banned]

Let me check that one ..it looks that is on spanish ?
i have probčems with sfml...what i stupid lib ?
SDL looks to me 10 times better.sh** :o
(Y)

Aurel [banned]

In fact not look bad ..but have crazy toolbar icons  :o
well i see stupidity of C or C++ look on image in screenshot
he complain about TextOutA win32 api function ?
give me a  break, for exammple in Embarcadero C++ ide this one compil fine
(Y)