Ooops
September 23, 2021, 06:53:42

Author Topic: Starting with Raylib  (Read 2891 times)

guest7581

  • Guest
Re: Starting with Raylib
« Reply #15 on: April 20, 2020, 15:56:12 »
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"?

Online Aurel

  • Sr. Member
  • ****
  • Posts: 351
Re: Starting with Raylib
« Reply #16 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.
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;
}
« Last Edit: April 20, 2020, 16:17:59 by Aurel »
(Y)

guest7581

  • Guest
Re: Starting with Raylib
« Reply #17 on: April 20, 2020, 17:55: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.

Offline Hotshot

  • Jr. Member
  • **
  • Posts: 49
Re: Starting with Raylib
« Reply #18 on: June 03, 2021, 23:38:53 »
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.

Code: [Select]
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)
« Last Edit: June 03, 2021, 23:48:51 by Hotshot »

Offline Pakz

  • Full Member
  • ***
  • Posts: 220
    • My homepage
Re: Starting with Raylib
« Reply #19 on: June 04, 2021, 09:56:03 »
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.

Online Aurel

  • Sr. Member
  • ****
  • Posts: 351
Re: Starting with Raylib
« Reply #20 on: June 04, 2021, 17:52:45 »
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)

Offline Hotshot

  • Jr. Member
  • **
  • Posts: 49
Re: Starting with Raylib
« Reply #21 on: June 04, 2021, 22:03:21 »
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;


Offline Pakz

  • Full Member
  • ***
  • Posts: 220
    • My homepage
Re: Starting with Raylib
« Reply #22 on: June 05, 2021, 09:02:11 »
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.

 

Offline zelda64bit

  • Jr. Member
  • **
  • Posts: 54
Re: Starting with Raylib
« Reply #23 on: June 05, 2021, 15:52:00 »
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.

Offline Hotshot

  • Jr. Member
  • **
  • Posts: 49
Re: Starting with Raylib
« Reply #24 on: June 05, 2021, 16:11:10 »
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....
« Last Edit: June 05, 2021, 16:13:04 by Hotshot »

Offline Hotshot

  • Jr. Member
  • **
  • Posts: 49
Re: Starting with Raylib
« Reply #25 on: June 05, 2021, 16:15:01 »
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

« Last Edit: June 05, 2021, 16:19:43 by Hotshot »

Online Aurel

  • Sr. Member
  • ****
  • Posts: 351
Re: Starting with Raylib
« Reply #26 on: June 05, 2021, 20:20:40 »
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.
you need to use some better IDE and build project with your files..i mean add c and h files into project.
(Y)

Offline zelda64bit

  • Jr. Member
  • **
  • Posts: 54
Re: Starting with Raylib
« Reply #27 on: June 05, 2021, 20:38:21 »
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.
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.

Online Aurel

  • Sr. Member
  • ****
  • Posts: 351
Re: Starting with Raylib
« Reply #28 on: June 06, 2021, 00:39:13 »
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)

Online Aurel

  • Sr. Member
  • ****
  • Posts: 351
Re: Starting with Raylib
« Reply #29 on: June 06, 2021, 01:11:13 »
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)

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal