SyntaxBomb - Indie Coders

Languages & Coding => Others => Topic started by: Pakz on April 05, 2020, 17:50:57

Title: Starting with Raylib
Post by: Pakz on April 05, 2020, 17:50:57
I watched a youtube video on Raylib and decided to download the windows installer for that. I was surpised how easy it was to get started and most of the examples just worked. The installer, I had chosen the notepad++ and gcc compiler version, went without hickups. You can start straight away and compiling time is like in the b3d days.

I spend the day trying to get familiar. Mostly by running the examples and starting my own example repo(see link) I had not tried the C language before so this takes a little time to get to know.

I have started a bit of 3d just yet. There is a build in FPS controls camera. The 3d layer is quite light. There is no mesh creation for custom meshes. So no voxel worlds for now. This might be added later though. You draw the 3d primitives every frame like they were sprites. Adding textures or texture atlas is present. I had a 30x10x30 hollow box made of textured cubes running at 60fps.

You compile and run a file by pressing F6 in notepad++ There is a minimal amount of lines needed for a hello world.

I think I might spend quite some time with this one!

The official raylib site:
https://www.raylib.com/ (https://www.raylib.com/)

My own example repo :
https://github.com/Pakz001/Raylib-Examples (https://github.com/Pakz001/Raylib-Examples)
Title: Re: Starting with Raylib
Post by: round157 on April 06, 2020, 00:04:46
I was curious and therefore I tried to look for games made with Raylib.

I found several interesting games.... 
:)
https://joeld42.itch.io/racer4cc

https://kellermartins.itch.io/pacman-remake-pds2

https://fabslab.itch.io/death-race

https://kodraan.itch.io/clutter-dungeon
Title: Re: Starting with Raylib
Post by: Brucey on April 06, 2020, 20:23:49
I've created a BlitzMax language binding for raylib (https://github.com/bmx-ng/ray.mod) which attempts to follow the API and structures as closely as possible.
Most of the example have been ported - requiring very little in the way of changes from the originals - so it's easy to follow C-based raylib tutorials in BlitzMax, for example.
Title: Re: Starting with Raylib
Post by: guest7581 on April 18, 2020, 11:59:24
You can use Raylib with plenty of languages - here is the list with available bindings (https://github.com/raysan5/raylib/blob/master/BINDINGS.md). Some of them works better tan others. The easiest to use is this lua binding (https://github.com/TSnake41/raylib-lua). The ones for Ruby, OpenEuphoria, Go also work fine. I've had less luck with bindings for Nim and D.
Title: Re: Starting with Raylib
Post by: Aurel on April 18, 2020, 14:54:22
@pakz

you don't say which version of reylib you use 3.0 or older 2.6 ?

also on download page i simply don't know which one is a version with Notepad++ ?

I also download whole pack from your github page and no one of them work with my version of Mingw compiler
i receive whole set of errors including strange about for loop?
reylib is a wrapper for openGL and short a coding a lot ..so i will try again. ;D
Title: Re: Starting with Raylib
Post by: guest7581 on April 18, 2020, 15:31:46
you don't say which version of reylib you use 3.0 or older 2.6 ?

also on download page i simply don't know which one is a version with Notepad++ ?

I don't think there is a special Notepad++ version. You're using Notepad++ to write C code and with C you can use any version of Raylib. When using bindings for other languages you should use the same version of Raylib that the one the bindings have been made for or your programs may not work properly.

I also download whole pack from your github page and no one of them work with my version of Mingw compiler
i receive whole set of errors including strange about for loop?

Raylib has nothing to do with for loop. Are you sure that the error is not about something that is inside the loop?
Title: Re: Starting with Raylib
Post by: Aurel on April 18, 2020, 15:46:40
Who knows...maybe he use tcc,,,because i get really whole bunch of errors with his code.
Title: Re: Starting with Raylib
Post by: guest7581 on April 18, 2020, 15:57:02
In the first post you can read that Pakz is using GCC. Aurel, post some errors. Do the examples compile but don't run or you can't compile anything?
Title: Re: Starting with Raylib
Post by: Pakz on April 18, 2020, 16:00:25
@aurel.

https://raysan5.itch.io/raylib

The version I am using is the 3.0 installer with mingw. This version does have that false positive right now!

I just tested a example from my raylib repo by loading it from the unzipped download folder. It compiled and ran with no errors. I am not sure what the problem might be.

edit:If you copy a example to the clipboard and paste it into a new file and run that? Do the official examples work? Maybe there is a windows admin problem where there is no file access allowed at the location where you want to run the example?

edit2:Installing raylib installer 3.0 with mingw with a windows security message(false positive) can be done by temporary turning of the windows defender. That is what I read on the raylib discord channel. The message is apearantly because mingw its software signature was expired.

edit3:The raylib installer comes with notepad++. I had to do nothing but install that raylib 3.0 mingw version and I could use notepad++ with raylib.
Title: Re: Starting with Raylib
Post by: guest7581 on April 18, 2020, 16:02:53
Aurel, did you download from https://github.com/raysan5/raylib/releases (https://github.com/raysan5/raylib/releases)?
Title: Re: Starting with Raylib
Post by: Aurel on April 18, 2020, 19:22:33
@pakz
I don't have any problems with false positive or similar security things
It simply throw out with lots of errors,what is so damn strange...
Also i don't see any notepad++....
i can try another installer again...

tomek
yes from that link...
Title: Re: Starting with Raylib
Post by: Aurel on April 18, 2020, 19:28:42
raylib-3.0.0-Win32-mingw
this one not work ,or not compile your examples from
Raylib-Exemples-master from github

so i am going to try raylib_installer_v300.exe
I hope that one will work with your examples  ;)
Title: Re: Starting with Raylib
Post by: Aurel on April 18, 2020, 20:03:47
ok
Installer ,install directly into C creating portable folder 478MB size plus this Notepad++
well is not small but ok
version of mingw is newer than i have with other two IDEs
anyway i open this Niotepad++ then he jump with one example ,i say ok
then i looking into this freakin Npp i there is only a RUN F5 ,so i click run then i get stupid dialog frame
what to run...gee...well i never liked this Npp very much ,but hello where is a command Compile or something
similar ... ???
Now i am really pissed off,i will try use my own AurelEditC..i think that i still have it somewhere.

edit:
damn i find it under plugins...now work...oh man that Npp is not for me.

if you don't know how look here:
Title: Re: Starting with Raylib
Post by: TomToad on April 19, 2020, 00:30:10
Maybe try Code::Blocks (https://wiki.codeblocks.org/), what I used before switching to Visual Studio.
Title: Re: Starting with Raylib
Post by: Aurel on April 20, 2020, 12:54:19
Well ,after i compile and tried all examples i can say that i am not impressed with reylib wrapper.
It looks to me that old HGE.dll work far better and far more smooth and soft than this one.
Title: Re: Starting with Raylib
Post by: guest7581 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"?
Title: Re: Starting with Raylib
Post by: 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.
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;
}
Title: Re: Starting with Raylib
Post by: guest7581 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.
Title: Re: Starting with Raylib
Post by: Hotshot 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)
Title: Re: Starting with Raylib
Post by: Pakz 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.
Title: Re: Starting with Raylib
Post by: Aurel 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?
Title: Re: Starting with Raylib
Post by: Hotshot 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;

Title: Re: Starting with Raylib
Post by: Pakz 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.

 
Title: Re: Starting with Raylib
Post by: zelda64bit 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.
Title: Re: Starting with Raylib
Post by: Hotshot 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....
Title: Re: Starting with Raylib
Post by: Hotshot 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

Title: Re: Starting with Raylib
Post by: Aurel 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.
Title: Re: Starting with Raylib
Post by: zelda64bit 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.
Title: Re: Starting with Raylib
Post by: Aurel 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
Title: Re: Starting with Raylib
Post by: Aurel 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
Title: Re: Starting with Raylib
Post by: Aurel on June 06, 2021, 11:12:59
Ok zelda
I finaly figured how to properly configure linker in ZinjaI IDE...well i like it ...
it is fast and lightweigth ..so do you can compile this program :
Code: [Select]
#include <windows.h>
LRESULT CALLBACK windowProcedure( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
//TCHAR text[] = _T"Hello world Window!";
//auto WinMessageToString(UINT msg) -> std::string;


int WINAPI WinMain(
   // Handle to current application isntance
   HINSTANCE hInstance,
   HINSTANCE hPrevInstance,
   // Command line
   LPSTR     lpCmdLine,
   int       nCmdShow
   ){

OutputDebugString("Starting WinMain Application");
//std::puts("It will not print to Console - Starting WinMain Application");   

//Window class name must be unique
const char wincClassName [] = "NameOfWindow";

// Win32 Window class structure
WNDCLASSEX wc;
// Win32 message structure
MSG Msg;           

// Name to identify the class with.
wc.lpszClassName = wincClassName;
//Pointer to the window procedure for this window class.
wc.lpfnWndProc = windowProcedure;   
// 1 - Register Windows Size
wc.cbSize = sizeof(WNDCLASSEX);

wc.style  = 0;
//Amount of extra data allocated for this class in memory. Usually 0
wc.cbClsExtra = 0;
//Amount of extra data allocated in memory per window of this type. Usually 0.
wc.cbWndExtra = 0;
//Handle to application instance (that we got in the first parameter of WinMain()).
wc.hInstance = hInstance;
// Large (usually 32x32) icon shown when the user presses Alt+Tab.
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
// Cursor that will be displayed over our window.
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
// Background Brush to set the color of our window.
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); // (HBRUSH) CreateSolidBrush(RGB(10, 20, 30)); //
// Background Brush to set the color of our window.
wc.lpszMenuName = NULL;
// Small (usually 16x16) icon to show in the taskbar and in the top left corner of the window.
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); 

//OutputDebugString("Registered Window Class OK.");

if(!RegisterClassEx(&wc))
{
MessageBox( 0,
   "Window Registration Failed!",
   "Error!",
   MB_ICONEXCLAMATION | MB_OK);
//Error status code
return -1;
}

//std::cout << "Class Registered" << std::endl;

int width = 500, height = 400;
int pos_left = 400, pos_top = 100;

HWND hwnd = CreateWindowA(
  wc.lpszClassName,
  "Title of Window",
  WS_OVERLAPPEDWINDOW,
  pos_left,
  pos_top,
  width,
  height,
  0,
  0,
  hInstance,
  0
  ); 
OutputDebugString(" [INFO] Window created OK");

if(hwnd == NULL){
MessageBox(NULL,
   "Error: Failure to create Window",
   "Error Report",
   MB_ICONEXCLAMATION | MB_OK);
return -1;
}
ShowWindow(hwnd, nCmdShow);
//std::cout << "nCmdShow = " << nCmdShow << std::endl;
UpdateWindow(hwnd);

//---- Message Loop ----------//
while(GetMessage(&Msg, NULL, 0, 0) > 0 ){
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}

OutputDebugString(" [INFO] Exiting application. OK."); 
// Success status code
return 0;
}
// ------------ End of Main ------------------------- //


// Window Procedure - Process window messages or events
LRESULT CALLBACK windowProcedure (
  HWND   hwnd    // Window Handle (Window object)
  ,UINT   msg     // Window Message 
  ,WPARAM wParam  // Additional message information
  ,LPARAM lParam  // Additional message information
  )
// Ignore messages which can flood the logging
// if(msg != WM_MOUSEMOVE && msg != WM_NCMOUSEMOVE
//    && msg != WM_QUIT && msg != WM_NCHITTEST )
//if(ignored_messages.find(msg) == ignored_messages.end())
// OutputDebugString(WinMessageToString(msg).c_str());
{
// Process messages
switch(msg)
{
case WM_CREATE:
SetWindowTextA(hwnd, "Window Title - GDI draw by Aurel");       
// OutputDebugString(" [INFO] Window created. OK.");
break;
case WM_CLOSE:
//OutputDebugString(" [INFO] Window closed. OK.");
DestroyWindow(hwnd);
break;
case WM_DESTROY:
//OutputDebugString(" [INFO] Exiting application. OK.");
PostQuitMessage(0);
break;
case WM_MOVE:
//std::cerr << " [INFO] Move window." << std::endl;
break;
case WM_PAINT:
{
// GDI - Graphics Devices Interface Here
//--------------------------------------------
PAINTSTRUCT ps;
HDC hdc;
// std::cerr << " [INFO] Windown painting" << std::endl;
hdc = BeginPaint(hwnd, &ps);
//TCHAR greeting[] = _T("Hello, World!");
const char text[] = "Hello world Window!";       
TextOutA(hdc, 125, 200, text , 19);
Ellipse(hdc, 200, 200, 160, 160);
Rectangle(hdc, 100, 100, 160, 160);
EndPaint(hwnd, &ps);       
}
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}

return 0;
}


Title: Re: Starting with Raylib
Post by: zelda64bit on June 07, 2021, 09:33:52
Ok zelda
I finaly figured how to properly configure linker in ZinjaI IDE...well i like it ...
it is fast and lightweigth ..so do you can compile this program :
Code: [Select]
#include <windows.h>
LRESULT CALLBACK windowProcedure( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
//TCHAR text[] = _T"Hello world Window!";
//auto WinMessageToString(UINT msg) -> std::string;


int WINAPI WinMain(
   // Handle to current application isntance
   HINSTANCE hInstance,
   HINSTANCE hPrevInstance,
   // Command line
   LPSTR     lpCmdLine,
   int       nCmdShow
   ){

OutputDebugString("Starting WinMain Application");
//std::puts("It will not print to Console - Starting WinMain Application");   

//Window class name must be unique
const char wincClassName [] = "NameOfWindow";

// Win32 Window class structure
WNDCLASSEX wc;
// Win32 message structure
MSG Msg;           

// Name to identify the class with.
wc.lpszClassName = wincClassName;
//Pointer to the window procedure for this window class.
wc.lpfnWndProc = windowProcedure;   
// 1 - Register Windows Size
wc.cbSize = sizeof(WNDCLASSEX);

wc.style  = 0;
//Amount of extra data allocated for this class in memory. Usually 0
wc.cbClsExtra = 0;
//Amount of extra data allocated in memory per window of this type. Usually 0.
wc.cbWndExtra = 0;
//Handle to application instance (that we got in the first parameter of WinMain()).
wc.hInstance = hInstance;
// Large (usually 32x32) icon shown when the user presses Alt+Tab.
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
// Cursor that will be displayed over our window.
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
// Background Brush to set the color of our window.
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); // (HBRUSH) CreateSolidBrush(RGB(10, 20, 30)); //
// Background Brush to set the color of our window.
wc.lpszMenuName = NULL;
// Small (usually 16x16) icon to show in the taskbar and in the top left corner of the window.
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); 

//OutputDebugString("Registered Window Class OK.");

if(!RegisterClassEx(&wc))
{
MessageBox( 0,
   "Window Registration Failed!",
   "Error!",
   MB_ICONEXCLAMATION | MB_OK);
//Error status code
return -1;
}

//std::cout << "Class Registered" << std::endl;

int width = 500, height = 400;
int pos_left = 400, pos_top = 100;

HWND hwnd = CreateWindowA(
  wc.lpszClassName,
  "Title of Window",
  WS_OVERLAPPEDWINDOW,
  pos_left,
  pos_top,
  width,
  height,
  0,
  0,
  hInstance,
  0
  ); 
OutputDebugString(" [INFO] Window created OK");

if(hwnd == NULL){
MessageBox(NULL,
   "Error: Failure to create Window",
   "Error Report",
   MB_ICONEXCLAMATION | MB_OK);
return -1;
}
ShowWindow(hwnd, nCmdShow);
//std::cout << "nCmdShow = " << nCmdShow << std::endl;
UpdateWindow(hwnd);

//---- Message Loop ----------//
while(GetMessage(&Msg, NULL, 0, 0) > 0 ){
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}

OutputDebugString(" [INFO] Exiting application. OK."); 
// Success status code
return 0;
}
// ------------ End of Main ------------------------- //


// Window Procedure - Process window messages or events
LRESULT CALLBACK windowProcedure (
  HWND   hwnd    // Window Handle (Window object)
  ,UINT   msg     // Window Message 
  ,WPARAM wParam  // Additional message information
  ,LPARAM lParam  // Additional message information
  )
// Ignore messages which can flood the logging
// if(msg != WM_MOUSEMOVE && msg != WM_NCMOUSEMOVE
//    && msg != WM_QUIT && msg != WM_NCHITTEST )
//if(ignored_messages.find(msg) == ignored_messages.end())
// OutputDebugString(WinMessageToString(msg).c_str());
{
// Process messages
switch(msg)
{
case WM_CREATE:
SetWindowTextA(hwnd, "Window Title - GDI draw by Aurel");       
// OutputDebugString(" [INFO] Window created. OK.");
break;
case WM_CLOSE:
//OutputDebugString(" [INFO] Window closed. OK.");
DestroyWindow(hwnd);
break;
case WM_DESTROY:
//OutputDebugString(" [INFO] Exiting application. OK.");
PostQuitMessage(0);
break;
case WM_MOVE:
//std::cerr << " [INFO] Move window." << std::endl;
break;
case WM_PAINT:
{
// GDI - Graphics Devices Interface Here
//--------------------------------------------
PAINTSTRUCT ps;
HDC hdc;
// std::cerr << " [INFO] Windown painting" << std::endl;
hdc = BeginPaint(hwnd, &ps);
//TCHAR greeting[] = _T("Hello, World!");
const char text[] = "Hello world Window!";       
TextOutA(hdc, 125, 200, text , 19);
Ellipse(hdc, 200, 200, 160, 160);
Rectangle(hdc, 100, 100, 160, 160);
EndPaint(hwnd, &ps);       
}
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}

return 0;
}



What is that code for?
Title: Re: Starting with Raylib
Post by: iWasAdam on June 07, 2021, 10:17:44
pretty standard c/c++ code for opening a window with a base message map.

What it really shows is that underneath all the nice basic 'OpenWindow' commands is some knarly low level stuff going on. you need window classes, icons, message loops, callbacks, etc
Title: Re: Starting with Raylib
Post by: Aurel on June 07, 2021, 10:54:40
yes it is small window C app it shows primitive GDI drawing
but instead primitive you can create sprites too.
SimplePortal 2.3.6 © 2008-2014, SimplePortal