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

Author Topic: SFML + Awesomium integration  (Read 5832 times)

0 Members and 1 Guest are viewing this topic.

ScoreX

  • Newbie
  • *
  • Posts: 6
    • View Profile
SFML + Awesomium integration
« on: October 16, 2011, 09:26:13 pm »
Hi guys,


long time lurker first time poster. I'm trying to integrate Awesomium with SFML but i'm running into a small issue.

I'm trying to save the renderbuffer of Awesomium to a sf::Texture using the LoadFromMemory function, but the function always returns false. I'm hoping someone can help me fix the problem or let me know a better way of doing it. Thanks.

Code: [Select]

if(awe_webview_is_loading_page(webView))
{
awe_webcore_update();
}
else
{
awe_webcore_update();

renderBuffer = awe_webview_render(webView);

if(renderBuffer != NULL)
{
if(t.LoadFromMemory(awe_renderbuffer_get_buffer(renderBuffer), sizeof(awe_renderbuffer_get_buffer(renderBuffer)))) // This returns false
{
text.SetString("Passed");
window.Draw(text);
}
else
{
text.SetString("Failed");
window.Draw(text);
}
}
}

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
SFML + Awesomium integration
« Reply #1 on: October 16, 2011, 09:40:13 pm »
sizeof is a compiletime C++ operator which returns the size of the type or object it is applied on.
Code: [Select]
int* ptr = new int[7];
sizeof(ptr) == sizeof(int*) // completely independent of the 7 elements

You have to pass the actual size of the buffer in bytes to sf::Texture::LoadFromMemory(). I don't know Awesomium (funny name by the way :)), but there must be a possibility.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

ScoreX

  • Newbie
  • *
  • Posts: 6
    • View Profile
SFML + Awesomium integration
« Reply #2 on: October 16, 2011, 09:47:15 pm »
Ah! I see. Thanks for the speedy reply. I can see my C++ skills need to be dusted off a bit more for getting sizeof wrong.

It it is a pretty funny name indeed, and hopefully will live up to it once I can get it working  :)

ScoreX

  • Newbie
  • *
  • Posts: 6
    • View Profile
SFML + Awesomium integration
« Reply #3 on: October 16, 2011, 10:19:11 pm »
Right, i'm one step closer. Found out how to get the buffer size ( buffer width * buffer rowspan - for anyone else who is wondering how ).

LoadFromMemory is still returning false however.

Code: [Select]

if(awe_webview_is_loading_page(webView))
{
awe_webcore_update();
}
else
{
awe_webcore_update();

renderBuffer = awe_webview_render(webView);

if(renderBuffer != NULL)
{

size_t bufferSize = awe_renderbuffer_get_rowspan(renderBuffer) * awe_renderbuffer_get_height(renderBuffer);

if(t.LoadFromMemory(awe_renderbuffer_get_buffer(renderBuffer), bufferSize))
{
sf::Sprite s(t);
window.Draw(s);
}
else
{
text.SetString("Failed");
window.Draw(text);
}


}
}

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
SFML + Awesomium integration
« Reply #4 on: October 16, 2011, 10:30:44 pm »
Is there a message on the standard error output (i.e. the console)? Or can you track with the debugger why LoadFromMemory() returns false?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

ScoreX

  • Newbie
  • *
  • Posts: 6
    • View Profile
SFML + Awesomium integration
« Reply #5 on: October 16, 2011, 10:44:16 pm »
No messages are output to the console, it just fails gracefully. Try catch doesnt catch an error either.


If I step into the code at LoadFromMemory, it takes me to

Code: [Select]

template <typename T>
Rect<T>::Rect() :
Left  (0),
Top   (0),
Width (0),
Height(0)
{

}


and then returns.

**EDIT**

Ok, have it working now, but not entirely as I would like.

Code: [Select]

if(awe_webview_is_loading_page(webView))
{
awe_webcore_update();
}
else
{
awe_webcore_update();

renderBuffer = awe_webview_render(webView);

if(renderBuffer != NULL)
{
size_t bufferSize = awe_renderbuffer_get_height(renderBuffer) * awe_renderbuffer_get_rowspan(renderBuffer);

std::vector<sf::Uint8> charBuffer;
charBuffer.resize(bufferSize);

sf::Uint8* charPtr = &charBuffer[0];

awe_renderbuffer_copy_to(renderBuffer, charPtr, awe_renderbuffer_get_rowspan(renderBuffer), 4, true, false);

image.Create(1024, 768, charPtr);

texture.LoadFromImage(image);

sprite.SetTexture(texture);

window.Draw(sprite);
}
}


Using the Create function in sf::Image I can pass the pixel buffer and it works perfectly. But it'd be nice to remove that step and just grab it straight from memory.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML + Awesomium integration
« Reply #6 on: October 17, 2011, 07:58:29 am »
Code: [Select]
// at init time
sf::Texture texture;
texture.Create(1024, 768);

// at render time
texture.Update(charPtr);

You should also declare your sprite and vector once at init time rather than constructing them again and again every time the page is refreshed. This is especially important with the vector, since you're allocating a big amount of memory.
Laurent Gomila - SFML developer

ScoreX

  • Newbie
  • *
  • Posts: 6
    • View Profile
SFML + Awesomium integration
« Reply #7 on: October 17, 2011, 01:30:23 pm »
That works perfectly Laurent, thank you.

Yeah in my actual code I have the variables initialized outside the update loop, but to keep the amount of code I had to show you small I put them in there.

Thanks again, and great library by the way  :D

frostwork

  • Newbie
  • *
  • Posts: 6
    • View Profile
    • http://www.frostworx.de/
SFML + Awesomium integration
« Reply #8 on: October 23, 2011, 11:16:09 am »
Awesomium no longer is opensource
(apart from the last ancient snapshot oc).
In case you don't know it yet there's also
berkelium which is opensource and under active development:
http://berkelium.org
it worked quiet fine in my own program btw , but I dropped it as building berkelium is time consuming. chromium really should have its core functions in a shared lib :}

 

anything