Berkelium in M/Ogre

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
alamata
Gnoblar
Posts: 9
Joined: Wed Dec 18, 2013 2:40 am

Berkelium in M/Ogre

Post by alamata »

hey to all,...
i m a beginner user with mogre

my primary goal is to make possible to render flash in Mogre
i have try "makarui," but flash material cant be set,...

i have discover berkelium in ogre,...
it 's exactly what i need,...

but i would like use berkelium in Mogre,....

do you think it s possible,... :?:

i have beginning to play around compilation of possible MBerkelium.dll for Berkelium in Mogre
but with no result... :(

is it possible to create a MBerkelium.dll file to use Berkelium in Mogre,..... :?:

can somone help me to make that possible...??

i think it can be a good freature for mogre too,...

what do you think about?....
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Berkelium in M/Ogre

Post by frostbyte »

http://lmgtfy.com/?q=Berkelium+in+MOgre
i also know there is a berkelium in ogre demo in myGui gui lib, so if myGui is wrapped for mogre...
integration to ogre texture is the only concern of ogre forum( their is no real need for "mberkelium.dll" creation )
for a complete c# api port of berkelium i recommend to try the berkelium forum....
Last edited by frostbyte on Fri Oct 31, 2014 7:20 am, edited 1 time in total.
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
alamata
Gnoblar
Posts: 9
Joined: Wed Dec 18, 2013 2:40 am

Re: Berkelium in M/Ogre

Post by alamata »

hey,...

thx for your intervention,... :wink:

i will take a look for a c# api of berkelium,...

thx again for the research direction you has given to me,... ;)
....
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Berkelium in M/Ogre

Post by frostbyte »

mostly welcome - here to help if i can.... :wink:
any way i know google give diffrent results to diffrent persons so maybe you missed this link http://www.ogre3d.org/addonforums/viewt ... =8&t=12147
sounds like u want to use a flash plugin running in a browser but rendering to a c# port of a c++ rendering lib = does not compute....( if this is indeed the case...)
usual way of ogre interacting with external rendering is using rtt( render to texture ) = 2d, real 3d integration is a no go in worst case scenario and problematic/hard to acheive in the best case so...maybe youll'e be better off by just importing all of your assets from flash to ogre somehow...
you can integrate opengl and directx calls directly in ogre scene - but thats about it...never heard of any two 3d render libs mixing nicely together....
i've heard of hikari http://www.ogre3d.org/forums/viewtopic.php?f=11&t=41999- direct flash port( no browser ) to ogre - but again no 3d...
any way i don't have a precise answer so dont excpect one from me - just general directions - and my mastery in searching the ogre forum.... :)
good luck with your quest...
Last edited by frostbyte on Fri Oct 31, 2014 9:24 am, edited 4 times in total.
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
alamata
Gnoblar
Posts: 9
Joined: Wed Dec 18, 2013 2:40 am

Re: Berkelium in M/Ogre

Post by alamata »

frostbyte wrote:mostly welcome - here to help if i can.... :wink:
very good poitn of view,... ;)
frostbyte wrote: any way i know google give diffrent results to diffrent persons
indeed,...

frostbyte wrote: any way i don't have a precise answer so dont excpect one from me - just general directions - and my mastery in searching the ogre forum.... :)
good luck with your quest...
thx one more time for your kindness,...

but i will try with
frostbyte wrote: a flash plugin running in a browser but rendering to a c# port of a c++ rendering lib
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Berkelium in M/Ogre

Post by frostbyte »

:shock: lets us know if u have success on this one, you brave soul... :?
Edit: have you ever heard of haxe??? it basicaly can make flash run on c++,c#,java etc...i don't realy like flash( or haxe ) but if thats your'e thing...oh well...
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
alamata
Gnoblar
Posts: 9
Joined: Wed Dec 18, 2013 2:40 am

Re: Berkelium in M/Ogre

Post by alamata »

....

i come with news,...

because i hawe some issues with the port c# library of berkelium
finnally,

i have decided to try to make a wrapper to c# for Mogre from the functionnal example of Minimal Berkelium integation http://www.ogre3d.org/tikiwiki/tiki-ind ... ntegration

so i have made a DLL C++/CLI project form the functionnal example,...

this is the beginning

i have 4 files

Mberkelium.cpp
MBerkelium.h
OgreBrowserWindow.cpp
ObeBrowserWindow.h

here is the code,...

MBerkelium.h

Code: Select all

#pragma once


#ifndef MBERKELIUM_H
#define MBERKELIUM_H

#include "Stdafx.h"

#include <berkelium/Berkelium.hpp>
#include "berkelium/Context.hpp"
#include <berkelium/WindowDelegate.hpp>
#include <Ogre.h>
#include <string>



namespace MBerkelium

{

	public ref class MBrowser
	{
		bool  initMBerkelium();

		
		/*
		void browseToPage(Ogre::String url);
		void setTransparent(bool isTransparent);
		void setDelegate(WindowDelegate *delegate);
		bool mframeRenderingQueued(const Ogre::FrameEvent& evt);
		*/
	};


	public ref class MBrowserWindow
	{
	public:
		MBrowserWindow(long double materialName, int width, int height);
		
		
	};
			


};
#endif // MBERKELIUM_H

MBerkelium.cpp

Code: Select all

#include "Stdafx.h"
#include <Ogre.h>
#include "MBerkelium.h"
#include "OgreBrowserWindow.h"
#include <string>


namespace MBerkelium

{

	bool MBrowser::initMBerkelium()
	{

		return init(Berkelium::FileString::empty());

	}



	MBrowserWindow::MBrowserWindow(long double materialName, int width, int height)
	{
		
		
		BrowserWindow::BrowserWindow(materialName, width, height);

	}


	
};



OgeBrowserWindow.h

Code: Select all

#ifndef OGREBROWSERWINDOW_H
#define OGREBROWSERWINDOW_H

#include "Stdafx.h"
#include <berkelium/WindowDelegate.hpp>
#include <Ogre.h>
#include <string>

 
/**
  * Berkelium browser window that renders to a texture.
  **/
class BrowserWindow : public Berkelium::WindowDelegate
{
public:
    /**
      * Construct a new Berkelium browser window, which will render to a texture
      * with specified name (the name should not exist yet, as new texture will be created).
      * Width and height specify browser window size.
      * Only invoke this constructor after initializing Berkelium (Berkelium::init())!
      **/
	BrowserWindow(long double textureName, int width, int height);
    virtual ~BrowserWindow();
 
    /**
      * The name of getMaterial()
      **/
    virtual long double getMaterialName(void);
    /**
      * The name of getTexture()
      **/
    virtual long double getTextureName(void);
    /**
      * Standard material that contains the texture to which
      * this browser window is rendering.
      * Use it on a MovableObject or in an overlay to show it in the scene.
      **/
    virtual Ogre::MaterialPtr getMaterial(void);
    /**
      * The texture to which this browser window is rendering.
      **/
    virtual Ogre::TexturePtr getTexture(void);
    /**
      * Show the webpage with specified url in this browser window.
      **/
    virtual void browseToPage(Ogre::String url);
    /**
      * The URL of the page currently shown in this browser window.
      **/
    virtual Ogre::String getCurrentPage(void);
    /**
      * Sets the transparency flag for this Window.
      * Note that the buffer will be ARGB regardless of transparency, but if the window is not set as transparent,
      * the alpha channel should always be 1. Transparency defaults to false and must be enabled on each Window.
      * istrans determines whether to enable a transparent background.
      *
      * This applies to the window background (background of the body).
      * You can set other html elements to transparent by setting their alpha value to 0 using the CSS line:
      * background: rgba(255, 255, 255, 0);
      **/
    virtual void setTransparent(bool isTransparent);
    /**
      * Conversion between Berkelium rectangles and Ogre boxes.
      **/
    static inline Ogre::Box rectToBox(Berkelium::Rect rect);
    /**
      * Callback for Berkelium to update this browser window.
      **/
    virtual void onPaint(
        Berkelium::Window *win,
        const unsigned char *sourceBuffer,
        const Berkelium::Rect &sourceBufferRect,
        size_t numCopyRects,
        const Berkelium::Rect *copyRects,
        int dx, int dy,
        const Berkelium::Rect &scrollRect);
 
protected:
    long double mTextureName;
    long double mMaterialName;
    Ogre::TexturePtr mTexture;
    Ogre::String mUrl;
    int mWidth;
    int mHeight;
 
    Berkelium::Window *mWindow;

};
 
/**
  * Ogre framelistener you can register for easily updating
  * Berkelium in your render loop.
  **/
class BerkeliumUpdater : public Ogre::FrameListener
{
public:
    virtual bool frameRenderingQueued(const Ogre::FrameEvent& evt);
};



 
#endif // OGREBROWSERWINDOW_H


OgeBrowserWindow.cpp

Code: Select all

#include "Stdafx.h"
#include "OgreBrowserWindow.h"
#include "berkelium/Context.hpp"
#include "berkelium/Berkelium.hpp"
#include <string>

 

BrowserWindow::BrowserWindow(long double materialName, int width, int height)
{
	
	
	mMaterialName = materialName;
	Ogre::String 	okmMaterialName = std::to_string(mMaterialName);
   
	mTextureName = materialName;

	Ogre::String  okmTextureName = std::to_string(mTextureName).append("_texture");
		
    // TODO assert size > 0
    mWidth = width;
    mHeight = height;
 
    // Create texture to render to
    mTexture = Ogre::TextureManager::getSingleton().createManual(
            okmTextureName,
            Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
            Ogre::TEX_TYPE_2D,
            width,
            height,
            0,  // no mipmaps
            Ogre::PF_BYTE_BGRA,
            Ogre::TU_DYNAMIC);
 
	

    // Prefill the RTT texture with initial pixel values (some graphics drivers leave uninitialized garbage in them)
    // Texture will remain like this until the web browser renders new pixels onto it (can usually take a few seconds)
    Ogre::HardwarePixelBufferSharedPtr buffer = mTexture->getBuffer(0,0);
    buffer->lock(Ogre::HardwareBuffer::HBL_DISCARD);    // lock buffer for writing
    const Ogre::PixelBox &pb = buffer->getCurrentLock();
	
	
    
	// Update the contents of pb
    // Image data starts at pb.data and has BYTE_BGRA (4 byte) format
    unsigned char *data = static_cast<unsigned char*>(pb.data);
    size_t length = pb.getHeight() * pb.getWidth() * 4;
    for(size_t i=0; i<length; i+=4)
    {
        // fill the buffer with white pixels and fully transparent alpha channel
        data[i]   = 255;    // Blue
        data[i+1] = 255;    // Green
        data[i+2] = 255;    // Red
        data[i+3] = 0;      // Alpha
    }
 
	

	
	
    buffer->unlock();   // Unlock the buffer again (frees it for use by the GPU)
	


	
    // Create a material using the texture
	Ogre::MaterialPtr mMaterial = Ogre::MaterialManager::getSingleton().create(okmMaterialName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
    mMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(okmTextureName);
 
    // Create new browser window in Berkelium


    Berkelium::Context * context = Berkelium::Context::create();
	


    mWindow = Berkelium::Window::create(context);

	
    delete context;
    mWindow->resize(width, height);
	
	
    
	// Listen to updates of the browser window to render them to the texture
    mWindow->setDelegate(this);
 
    // Browse to webpage
    browseToPage("file:///C:/Users/ALAMATA/Documents/Visual%20Studio%202010/Projects/BASE%20OK%20Berker_A/ok2Berker_A/2Berker_A%20-%20ok/Berker_A/media/bonas2.swf");
}
 
BrowserWindow::~BrowserWindow()
{
    mWindow->destroy();
}
 
 
void BrowserWindow::onPaint(
        Berkelium::Window *win,
        const unsigned char *sourceBuffer,
        const Berkelium::Rect &sourceBufferRect,
        size_t numCopyRects,
        const Berkelium::Rect *copyRects,
        int dx,
        int dy,
        const Berkelium::Rect &scrollRect)
{
    // Pixels to be written to texture
    const Ogre::PixelBox srcBox = Ogre::PixelBox(
           // Box that defines position of src buffer within complete browser window
       rectToBox(sourceBufferRect),
       Ogre::PF_BYTE_BGRA,
       const_cast<unsigned char*>(sourceBuffer)
    );
 
    // Update texture
    Ogre::HardwarePixelBufferSharedPtr pixelBuffer = mTexture->getBuffer();
    // There might be multiple areas of the texture to update
    for( int i =0; i<numCopyRects; i++) {
        // Box that defines area of texture that has to be updated)
        const Ogre::Box destBox = rectToBox(copyRects[i]);
 
        // Copy updated browser surface to texture (note: Don't lock the buffer yourself!! blitFromMemory does this)
        pixelBuffer->blitFromMemory(srcBox.getSubVolume(destBox), destBox);
    }
 
}
 
inline Ogre::Box BrowserWindow::rectToBox(Berkelium::Rect rect)
{
    return Ogre::Box(
            rect.left(),
            rect.top(),
            0,
            rect.right(),
            rect.bottom(),
            1);
}
 
long double BrowserWindow::getMaterialName()
{
    return mMaterialName;
}
 
long double BrowserWindow::getTextureName()
{
    return mTextureName;
}
 
Ogre::MaterialPtr BrowserWindow::getMaterial()
{
    return Ogre::MaterialManager::getSingletonPtr()->getByName(std::to_string(getMaterialName()));
}
 
Ogre::TexturePtr BrowserWindow::getTexture()
{
    return Ogre::TextureManager::getSingletonPtr()->getByName(std::to_string(getTextureName()));
}
 
void BrowserWindow::browseToPage(Ogre::String url)
{
    mUrl = url;
    mWindow->navigateTo(url.data(), url.length());
}
 
Ogre::String BrowserWindow::getCurrentPage()
{
    return mUrl;
}
 
void BrowserWindow::setTransparent(bool isTransparent)
{
    mWindow->setTransparent(isTransparent);
 
    if(isTransparent) {
        // This is the equivalent of setting "scene_blend alpha_blend" in a material file
        getMaterial()->getTechnique(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
        // Alternative method: this might be faster if you don't need blending (only transparency for alpha=0)
        //getMaterial()->getTechnique(0)->getPass(0)->setAlphaRejectSettings(Ogre::CMPF_GREATER,0);
    } else {
        // Disable alpha blending for material
        getMaterial()->getTechnique(0)->setSceneBlending(Ogre::SBT_REPLACE);
        // Equivalent for the alternative method
        //getMaterial()->getTechnique(0)->getPass(0)->setAlphaRejectSettings(Ogre::CMPF_ALWAYS_PASS,0);
    }
}
 
 
bool BerkeliumUpdater::frameRenderingQueued(const Ogre::FrameEvent &evt)
{
    Berkelium::update();
    return true;
}


for example in the c# program,...

Code: Select all

     MBerkelium.MBrowser initmbrowser = new MBrowser();

      Console.WriteLine(initmbrowser.ToString());
  

      MBerkelium.MBrowserWindow mBrowserwindow = new MBrowserWindow(1, 1024, 1024);

i can initalise the Berkelium ,...

but i cant create the mBrowserWindow,.... :?


first i have had a issue with the Ogre::String for the material name,...

indeed in the c# program it aske me a ""std::basic_string<char, std::char_traits<char>, std::allocator<char>> "" instead a string,... :roll:

so i have bypassed the issue byt put an long double for the materialname an convert it with std::to_string later in the code,...

actually i have a issue with the ""buffer->unlock"" in the OgreBrowserWindow,...


Why the c# asked me a //std::basic_string<char, std::char_traits<char>, std::allocator<char>> insteed simple string,...for the name material

my actual issue with the ""buffer-> unlock"" come perhaps from ""my"" format of the matialname (log double),..... ???


an idee to make that possible on Mogre,...

rem i can run functionnally my modified OgreBrowserWindow(with the long double format for the materialname) in c++ ogre app
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Berkelium in M/Ogre

Post by frostbyte »

Why the c# asked me a //std::basic_string<char, std::char_traits<char>, std::allocator<char>> insteed simple string,...
i dont know how you build the bindings but my guess is that you didn't wrap/bind Ogre::String template properly( if at all.. )

as for the buffer->unlock() issue( ??? ) there's not enough info - what's the issue???
long double - never used it for pointer conversion - try using plain long...double may be differently represented with c#( numerical value )
try using the same method/system mogre uses for creating bindings...
good luck...
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
alamata
Gnoblar
Posts: 9
Joined: Wed Dec 18, 2013 2:40 am

Re: Berkelium in M/Ogre

Post by alamata »

hey,...
frostbyte wrote:
Why the c# asked me a //std::basic_string<char, std::char_traits<char>, std::allocator<char>> insteed simple string,...
i dont know how you build the bindings but my guess is that you didn't wrap/bind Ogre::String template properly( if at all.. )
I dont know exactly what s means when you say that,... :roll:


""typedef _StringBase String "" is in OgrePrerequisites.H line 442
and this file is in the a folder linker to the project in visual studio
namespace Ogre
333 {
334 #if OGRE_STRING_USE_CUSTOM_MEMORY_ALLOCATOR
335 typedef std::basic_string<char, std::char_traits<char>, STLAllocator<char,GeneralAllocPolicy > > _StringBase;
336 typedef std::basic_stringstream<char,std::char_traits<char>,STLAllocator<char,GeneralAllocPolicy > > _StringStreamBase;
337
338 #define StdStringT(T) std::basic_string<T, std::char_traits<T>, std::allocator<T> >
339 #define CustomMemoryStringT(T) std::basic_string<T, std::char_traits<T>, STLAllocator<T,GeneralAllocPolicy> >
""OGRE_STRING_USE_CUSTOM_MEMORY_ALLOCATOR""
is an option in cmake gui and this checked box is uncheked in my configuration,...

when i try to checked this checkbox and try to build ogre i have got some errors,...

what can i do to escape from the error
Why the c# asked me a //std::basic_string<char, std::char_traits<char>, std::allocator<char>> insteed simple string,...
..................
frostbyte wrote: long double - never used it for pointer conversion - try using plain long...double may be differently represented with c#( numerical value )

finnally i have try with ""int""

cause int can be converted in system::string

Code: Select all

System::Convert::ToString(myint)
and int can be ocnverted in Ogre::String

Code: Select all

Ogre::String my_string = Ogre::StringConverter::toString(my_int);
alamata
Gnoblar
Posts: 9
Joined: Wed Dec 18, 2013 2:40 am

Re: Berkelium in M/Ogre

Post by alamata »

...
frostbyte wrote: try using the same method/system mogre uses for creating bindings...
...
i have coded that,...

Code: Select all


Mogre::TexturePtr ^mTextureok = Mogre::TextureManager::Singleton->CreateManual(mTextureNamestr, Mogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Mogre::TextureType::TEX_TYPE_2D, width, height, 0,Mogre::PixelFormat::PF_BYTE_BGRA, 2);

Mogre::HardwarePixelBufferSharedPtr ^buffer = mTextureok->GetBuffer(0,0);
buffer->Lock(Mogre::HardwareBuffer::LockOptions::HBL_DISCARD);    // lock buffer for writing
const Mogre::PixelBox pb = buffer->CurrentLock;


but i have an error ,.... with

Code: Select all


unsigned char *data = static_cast<unsigned char*>(pb.data);
	
	size_t length = 512 * 512 * 4;
	for (size_t i = 0; i<length; i += 4)
	{
		// fill the buffer with white pixels and fully transparent alpha channel
		data[i] = 255;    // Blue
		data[i + 1] = 255;    // Green
		data[i + 2] = 255;    // Red
		data[i + 3] = 0;      // Alpha
	}


the error,...
Erreurerror C2440: 'static_cast' : cannot convert from 'const System::IntPtr' to 'unsigned char *
an idea,....?
frostbyte
Orc Shaman
Posts: 737
Joined: Fri May 31, 2013 2:28 am
x 65

Re: Berkelium in M/Ogre

Post by frostbyte »

sorry, i was too tired when i read your post so i did'nt notice what you did...
someFunction( long mMaterialName)
{
//Ogre::String okmMaterialName = std::to_string(mMaterialName);
//this is not pointer conversion!!! ... this is used to get a text representation of what ever value you try to convert...
//System::Convert::ToString(myint) ...........this is not pointer conversion!!!
//Ogre::StringConverter::ToString(myint) ...........this is not pointer conversion!!!


//this is how you conver pointers from long/int....
Ogre::String *okmMaterialNamePointer = (Ogre::String*)mMaterialName;
Ogre::String okmMaterialName = (*okmMaterialNamePointer);
}

Tips...
you can stop using "Ogre::" by adding 'using namespace Ogre;' after ogre includes...
use logging to see what results you get...
Ogre::LogManager::getSingleton().logMessage( "material name is "+okmMaterialName );
read some material about using pointers/templates and casting/binding related to c++ and c# ...
this is not realy ogre related stuff....so good luck...
the woods are lovely dark and deep
but i have promises to keep
and miles to code before i sleep
and miles to code before i sleep..

coolest videos link( two minutes paper )...
https://www.youtube.com/user/keeroyz/videos
Post Reply