Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: rbSFML  (Read 142521 times)

0 Members and 1 Guest are viewing this topic.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #180 on: April 21, 2012, 06:01:42 pm »
I ment that you should copy the code in ruby as C++ completely. So they do the same thing. One of the things is that everything in Ruby is allocated dynamically so just putting it on the stack is not enough.

And Texture#loadFromImage does exist. I just checked it. Sure you didn't misspell?
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Lupinius

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: rbSFML
« Reply #181 on: April 21, 2012, 06:27:45 pm »
Thank you once again for your support and the binding. Ludum dare has so far been been a joy to code, regardless of the currently missing documentation. I'll show something once I have the first "complete" version.

I'm still having problems using vertices though. This is my test code:
require "sfml/graphics"

app = SFML::RenderWindow.new [800, 600], "Vertices Test"

vertices = Array.new(2) { SFML::Vertex.new }
vertices[0].position = [0, 0]
vertices[1].position = [1, 1]

state = SFML::RenderStates.new

app.draw vertices, 4, SFML::Lines, state # Variant 1
app.draw vertices, SFML::Lines, state # Variant 2
Variant 1 doesn't work because 1..3 parameters are expected. Looking at the source code, it appears that the vertex count the array provides is used. So I was guessing variant 2 would work, it leads to a segmentation fault tough. How do I use it correctly?

Also, another request: Also make Vector2 and Vector3 different number types.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #182 on: April 21, 2012, 06:53:16 pm »
The vector fix is done and I am locking into why the vertexes crashes.

When it comes to raw memory the API either uses an array or a string to handle it and you never have to give explicitly the size of the memory as Ruby knows it ;)
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #183 on: April 21, 2012, 06:55:55 pm »
Render target crash is now up and fixed as well. The problem was that I thought of it just like in C++ ^^ Like how you did from the beginning so I retrieved the length from argument 0 and the pointer from argument 1 which is VERY wrong.

I am interested in showing up rbSFML so other users see it. Would you mind having a rbSFML logo on your ludum dare project? =)
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

vivo

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
    • Email
Re: rbSFML
« Reply #184 on: April 21, 2012, 07:01:26 pm »
I ment that you should copy the code in ruby as C++ completely. So they do the same thing. One of the things is that everything in Ruby is allocated dynamically so just putting it on the stack is not enough.
Yes, i copied (translated) the code contemplating the same instructions

And Texture#loadFromImage does exist. I just checked it. Sure you didn't misspell?
Sure :S
I haven't updated my rbSFML copy. I have the one you suggested in your installation tutorial. Could it be the reason?

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #185 on: April 21, 2012, 07:08:36 pm »
Download the latest one from Github, and if this still doesn't work then something is wrong on my side... Ow yeah you aren't trying to use the loadFrom methods as class methods? I can add them as that as well as it makes sense. Though it would be more like newFromImage/new_from_image or something like that.

And how did it go with the linux fix branch? Did it make any difference?
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #186 on: April 21, 2012, 07:11:53 pm »
And for drawing vertices manually. That's pretty slow just so you know. I have to manually allocate memory equally big and convert the ruby objects to SFML objects for each draw call. Use the vertex array class that comes with SFML if you can. It will be much more efficient as no Ruby -> SFML conversion will have to be done.

Stuff like this will be covered in the documentation.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

vivo

  • Jr. Member
  • **
  • Posts: 50
    • View Profile
    • Email
Re: rbSFML
« Reply #187 on: April 21, 2012, 07:18:26 pm »
Download the latest one from Github, and if this still doesn't work then something is wrong on my side... Ow yeah you aren't trying to use the loadFrom methods as class methods? I can add them as that as well as it makes sense. Though it would be more like newFromImage/new_from_image or something like that.
Not really as a class method, I was invoking as an instance method. The code I posted was just for letting you know from wich class was I invoking, sorry for the missunderstanding.
I do:
tex = Texture.new
tex.loadFromFile("file.jpg")
 
And how did it go with the linux fix branch? Did it make any difference?
[/quote]
Don't know yet :P, i'll try tomorrow (Barça-Madrid is waiting for me)

Lupinius

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: rbSFML
« Reply #188 on: April 21, 2012, 07:53:07 pm »
I am interested in showing up rbSFML so other users see it. Would you mind having a rbSFML logo on your ludum dare project? =)
I'd love to! Where can I find one? I remember there being some in the "A new logo for SFML" thread (like this one).

I am having a problem compiling the latest version though:
Code: [Select]
Compiling ext/Graphics/RenderTarget.cpp
ext/Graphics/RenderTarget.cpp: In function 'VALUE rbRenderTarget::Draw(int, VALUE*, VALUE)':
ext/Graphics/RenderTarget.cpp:288: error: invalid conversion from 'void*' to 'sf::Vertex*'
rake aborted!
Command failed with status (1): [g++  -O3 -fno-omit-frame-pointer -g -Wextr...]

And i can't find a VertexArray class in rbSFML:
Code: [Select]
irb(main):015:0> puts SFML.constants.sort
BINDING_VERSION
BlendAdd
[...]
Vector2
Vector3
Vertex
VideoMode
View
Window

Speed shouldn't matter that much in this case though, I just need vertices so I can stretch my images over distorted rectangles.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #189 on: April 21, 2012, 08:23:43 pm »
Alright fixed both. The vertex array thing was because I forgot to call the initiate function for the class xD

And you can use that logo yes :D
I don't know if SFML has switched logo yet but I might change later.
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #190 on: April 21, 2012, 08:42:51 pm »
I put up a blog post with the logo so there is one central way to always find it and download it. It will be up 24/7.

http://groogy.se/mainsite/2012/04/21/rbsfml-logo/
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Lupinius

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: rbSFML
« Reply #191 on: April 21, 2012, 10:05:48 pm »
There are still problems. This code paints "img.png" to the screen:
#include <SFML/Graphics.hpp>

int main() {
        sf::RenderWindow app(sf::VideoMode(800, 600), "Vertices Test");
       
        sf::Texture tex;
        tex.loadFromFile("img.png");
       
        while (true) {
                sf::Vertex vertices[4];
               
                vertices[0].position = sf::Vector2f(0, 0);
                vertices[0].texCoords = sf::Vector2f(0, 0);
                vertices[1].position = sf::Vector2f(0, 100);
                vertices[1].texCoords = sf::Vector2f(0, 256);
                vertices[2].position = sf::Vector2f(100, 100);
                vertices[2].texCoords = sf::Vector2f(256, 256);
                vertices[3].position = sf::Vector2f(100, 0);
                vertices[3].texCoords = sf::Vector2f(256, 0);
               
                sf::RenderStates state;
                state.texture = &tex;
               
                app.clear();
                app.draw(vertices, 4, sf::Quads, state);
                app.display();
        }
}
The same in ruby draws a white rectangle:
require "sfml/graphics"

app = SFML::RenderWindow.new([800, 600], "Vertices Test")
       
tex = SFML::Texture.new
tex.loadFromFile("img.png")

while true
        vertices = Array.new(4) { SFML::Vertex.new }
       
        vertices[0].position = [0, 0]
        vertices[0].tex_coords = [0, 0]
        vertices[1].position = [0, 100]
        vertices[1].tex_coords = [0, 256]
        vertices[2].position = [100, 100]
        vertices[2].tex_coords = [256, 256]
        vertices[3].position = [100, 0]
        vertices[3].tex_coords = [256, 0]
       
        state = SFML::RenderStates.new
        state.texture = tex
       
        app.clear()
        app.draw(vertices, SFML::Quads, state)
        app.display()
end

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #192 on: April 21, 2012, 10:24:07 pm »
I am having a hard time finding what would be the source of the problem and I am not at a computer right now where I can test this. But I think... just think that there might be a problem with the vector. Can you try giving it float values instead? I think it might be a problem that the Ruby C API can't convert any kind of Numeric to C float/double and thus give me a weird number or even 0. The macro I use is NUM2DBL which should take any numeric and give me a double but documentation here is pretty limited. Though it doesn't say that it includes a type check so it might not even do that and just do a raw conversion.

If it still doesn't work try doing it manually with SFML::Vector2.new instead of array's just to be certain. I will fix this so that there is a better conversion layer between Ruby and SFML but that means conversions will be slower but I will stay with the principle of least surprise at least. Besides the interpreter will stand for most of the time anyway so think it's okay.

also attemt with doing the state as an array. [ tex ]

And to verify that the texture is still valid create a sprite which draws it on a position elsewhere on the window. This is just to find where the error is located. If it's in texture or if it's render states.
« Last Edit: April 21, 2012, 10:32:18 pm by Groogy »
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

Lupinius

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: rbSFML
« Reply #193 on: April 21, 2012, 10:54:58 pm »
Changing to floats or using vectors directly did not work. However, adding "sleep 1" or even some lower amount (down to ~0.05) to the end of the loop displays the graphic. Same thing seems to happen when the first few frames take a bit to show up.

I'm not sure what you mean with "doing the state as an array.". Trying to replace
app.draw(vertices, SFML::Quads, state)
with
app.draw(vertices, SFML::Quads, [tex])
does not work due to an conversion error.

Sprite seem to show the same behavior (not having a texture) in this example. They also seem to lose size information and get thin. However in my game sprites worked fine, the texture seemed to be.

Everything works when I declare the RenderState before the loop and only assign the texture once. The texture seems to be damaged when it is attached to a RenderState often.

Groogy

  • Hero Member
  • *****
  • Posts: 1469
    • MSN Messenger - groogy@groogy.se
    • View Profile
    • http://www.groogy.se
    • Email
Re: rbSFML
« Reply #194 on: April 21, 2012, 11:15:47 pm »
I think I know what the problem is now. I've done the garbage collection wrong so the texture get's garbage collected while it is still in use. I will put up a quick fix trough the github editor now.

Though problem will now be that it does not mimic C++ now.
state.texture->functionThatModifies(); // <- Doesn't work
state.texture.function_that_modifies() # <- Does work now
« Last Edit: April 21, 2012, 11:21:16 pm by Groogy »
Developer and Maker of rbSFML and Programmer at Paradox Development Studio

 

anything