Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flowers OOP with raylib/examples/models/resources/skybox.png #6

Merged
merged 6 commits into from
Nov 17, 2024

Conversation

coderextreme
Copy link
Contributor

Example with skybox and object oriented programming. Also intended to show reflection and prismatic effects (chromatic dispersion) with shaders, but I'm really unsure about if my skybox works right. The skybox in this pull request is pulled from raylib/examples/models/resources/skybox.png. I drew inspiration from the skybox example in raylib/examples, but it's not a complete port.

A good skybox image should show reflection, refraction and chromatic dispersion. Here's one with a skybox from Paul Debevec:
image

@coderextreme
Copy link
Contributor Author

I got different results by calling reset. I'm not sure what's up.

@coderextreme
Copy link
Contributor Author

Also, does not compile to JS:

$ nim js flowers_oop.nim
Hint: used config file 'C:\Users\jcarl\Downloads\nim-2.2.0\config\nim.cfg' [Conf]
Hint: used config file 'C:\Users\jcarl\Downloads\nim-2.2.0\config\config.nims' [Conf]
Hint: used config file 'C:\Users\jcarl\raylib-examples\config.nims' [Conf]
...........................................................................
C:\Users\jcarl.nimble\pkgs2\naylib-24.44.1-3eb3b966739400237ccd37c0bc84b410f21496f4\raylib.nim(1708, 1) Error: signature for '=destroy' must be proc[T: object](x: var T)

I am not sure what's up, I'll try to upgrade naylib

models/flowers_oop.nim Outdated Show resolved Hide resolved
# Zero out source to prevent double-free
#source.cubemap.id = 0
#source.modelShader.id = 0
#source.model.meshCount = 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these destructor hooks should be removed. The raylib library handles destructors for you. (If you need to attach a destructor to an object that has other managed resources you call them explicitly on the fields).

Copy link
Contributor Author

@coderextreme coderextreme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed explicit destructors except those on Flower instances (deferred)

@coderextreme
Copy link
Contributor Author

Ready to review again. JS transpiling still doesn't work. I don't know how to solve it, I don't think claude.ai does eitther, at least not in my code.

@planetis-m
Copy link
Owner

Ready to review again. JS transpiling still doesn't work. I don't know how to solve it, I don't think claude.ai does eitther, at least not in my code.

Naylib doesn't support the js platform since raylib is written in C. But you can compile it with emscripten. I have sent you a link on discord.


var image = loadImage("resources/skybox.png") # TODO Replace with your texture path
if image.data == nil:
raise newException(IOError, "Failed to load skybox.png texture")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw these functions have error checking, so you don't need to do that explicitly. Apparently only loadShaderFromMemory is missing a isShaderValid call. Will investigate why.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't put the checking in myself (I'm kind of bad that way), so I'm glad the library handles it!

@planetis-m planetis-m merged commit 1454b4a into planetis-m:main Nov 17, 2024
1 check passed
@planetis-m
Copy link
Owner

Merging anyway. Thank you!

@coderextreme
Copy link
Contributor Author

Ready to review again. JS transpiling still doesn't work. I don't know how to solve it, I don't think claude.ai does eitther, at least not in my code.

Naylib doesn't support the js platform since raylib is written in C. But you can compile it with emscripten. I have sent you a link on discord.

What I did was use claude.ai to translate the code to Three.js. It got too aggressive with the normal in my shader though. See: https://coderextreme.net/assetmanager/ The translation worked well, and even helped fix the skybox issues. I just had to specify 6 images instead of 1. I don't know if naylib supports 6 images or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants