Raylib Wrapper Help - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Works in Progress (https://qb64phoenix.com/forum/forumdisplay.php?fid=9) +---- Thread: Raylib Wrapper Help (/showthread.php?tid=820) |
Raylib Wrapper Help - LeftyG - 08-27-2022 Hello all, I am currently working on a Raylib wrapper. However I can't get it to show a image on the screen. Every time I do, it crashes the program. Color issue is figured out. Need to figure out how to load and draw image functions aren't working properly. Full wrapper code: https://github.com/gAndy50/Qb64Wrappers/blob/master/raylib42.bi Wrapper code Code: (Select All) TYPE fImage Program Code Code: (Select All) REM $include: 'raylib42.bi' RE: Raylib Wrapper Help - SMcNeill - 08-27-2022 I don't know anything much about RayLib, but I can help with the color issue: Code: (Select All) 'R and G are backwards? In memory, color is *always* stored in Alpha, Red, Green, Blue format. It's easy to see with hex values: &HAARRGGBB &HFFFF0000 is bright red... 255 alpha, 255 red &HFF00FF00 is bright green... 255 alpha, 255 green &HFF0000FF is bright blue... 255 alpha, 255 blue Depending on how you're writing your data (little endian or big endian), it'll always be in either ARGB or BGRA format. Yours appears, from your comments, to be in BGRA format here. RE: Raylib Wrapper Help - LeftyG - 08-27-2022 Thanks. I have the color issue figured out. Its the loading image and drawing the image that I'm having issues with. RE: Raylib Wrapper Help - SpriggsySpriggs - 08-29-2022 I haven't read all of your code yet but I'd be willing to bet that some issues will arise from incorrect data types being used in your external function declarations. Every FUNCTION you've declared from the external libraries are set to use SINGLE as the return type. Also, according to the Wiki, C/C++ float is a SINGLE in QB64 so you will need to clean up a lot of TYPE and function declarations to use the proper data type. I see a lot of declarations using INTEGER. In C/C++, an int corresponds to a LONG in QB64. I'm not sure what the original declarations were but if they were int then they should be LONG. If they were int16 then you're fine. I haven't checked, but make sure any string passed to an external function is ended with a CHR$(0) so as to null-terminate the string. Before you move any further with the project, I'd check and fix the above to make sure these aren't hindering your progress. Good luck! P.S. I just noticed that you're passing the value from RGBA32 to your fColor argument. The DrawTexture function expects a struct of Color but you're passing an UNSIGNED LONG value. https://www.raylib.com/cheatsheet/cheatsheet.html P.P.S If I have free time and I don't forget, I might download your BI file and try running it myself. If I get real ambitious, I'll make any change that would make your code be consistent with how I'd declare libraries and see if it resolves your issues. No promises, though. P.P.P.S "Option Explicit" is your friend. Make sure you explicitly declare each and every variable you use. This might seem inconvenient for a BASIC language but it prevents many hiccups. I don't write any code without it and I declare every variable even if it's a temp variable that will be disposed in the very next line. P.P.P.P.S I see that your fColor struct declaration is using UNSIGNED LONG as the data type for its members. You should instead be using UNSIGNED BYTE as the min value would be zero and the max value should not exceed 255. Your struct, as it currently stands, is 4 times as large as it should be. RE: Raylib Wrapper Help - SpriggsySpriggs - 08-29-2022 Because I was tired and bored, I decided to take a dive into this. I think I'll have a new BI file to give to you by the end of the day. However, it will require you to rewrite any sample code you wrote to test what you have so far since the declarations will have drastically changed. RE: Raylib Wrapper Help - LeftyG - 08-29-2022 (08-29-2022, 07:13 PM)Spriggsy Wrote: Because I was tired and bored, I decided to take a dive into this. I think I'll have a new BI file to give to you by the end of the day. However, it will require you to rewrite any sample code you wrote to test what you have so far since the declarations will have drastically changed. Thanks so much. I did my best to try and make a wrapper for Raylib. The variable convertion and structs were kinda getting at me, but I tried to get it as QB as compatible as I thought it could be. RE: Raylib Wrapper Help - SpriggsySpriggs - 08-30-2022 I'm still working on building this BI. Can't guarantee that all functions will work since some return structs. I've declared these as returning offsets with the hope that we can use MEM to retrieve the struct that way. That will require me helping you with some of the functions when it comes time. I've got about 200 more lines in this header file to recreate in my BI file. I'll upload it here as soon as I'm done. By the way, I notice that Raylib uses UTF-8 encoding in some functions so you might need to use my UnicodeToAnsi library so you can convert to and from UTF-8 on the fly. RE: Raylib Wrapper Help - LeftyG - 08-30-2022 (08-30-2022, 02:43 AM)Spriggsy Wrote: I'm still working on building this BI. Can't guarantee that all functions will work since some return structs. I've declared these as returning offsets with the hope that we can use MEM to retrieve the struct that way. That will require me helping you with some of the functions when it comes time. I've got about 200 more lines in this header file to recreate in my BI file. I'll upload it here as soon as I'm done. Thanks again. Raylib is written in C99, so I didn't think it'd be super hard to wrap. I didn't have really any trouble when I made a wrapper for Sigil for QB64. Then again QB64 isn't my main programming language, but any programming is good for practice. RE: Raylib Wrapper Help - SpriggsySpriggs - 08-30-2022 Here is my version of the BI file. Took forever to make. Again, can't guarantee how much will actually work. There's just far too much to test. But you can revise your sample code and run it against my version and I do believe you'll get some better results. RE: Raylib Wrapper Help - TempodiBasic - 08-30-2022 my two cents Code: (Select All) DIM SHARED tex AS fTexture here I see 2 kind of variable with the same name... it is not a good practice to do this... 1 please use _Option Explicit, it saves your time and concentration at the price to declare every variables 2 correct the correlate data type as Spriggs pointed out (I fall often in this kind of misunderstandment because I use too few C language) 3 Does the raylib work like OpenGL (you must redraw everytime the screen)? Otherwise I should prefer to put out of the loop DO the calling for initialization and deallocation of resources OR to put a _LIMIT to the loop. Good luck |