Help with libRocket RenderInterface on Android?

Discussion of issues specific to mobile platforms such as iOS, Android, Symbian and Meego.
Post Reply
User avatar
Argosse
Gnoblar
Posts: 17
Joined: Wed Apr 27, 2011 9:43 pm

Help with libRocket RenderInterface on Android?

Post by Argosse » Mon Jan 27, 2014 8:24 pm

Im using the newest source of libRocket, the prebuilt OgreAndroidSDK_v1-9RC1 and Android to make my app. Ive prebuilt libRocket into a static library and linked ok. Ive also perused the forums and torn apart a couple code snippets to get libRocket up and going. Btw this is a completely native app(I think), appmanifest hasCode=false, but there is no java and everything starts back in my android_main function. Sorry ahead of time this seems like alot.
Everything seems to load ok, I get logcat info even saying the textures and pictures from libRocket have been loaded, compiled and rendered through the custom RenderInterfaceOgre3D, Absolutely nothing shows up on the screen except my ogre scene stuff and ogre overlay stuff. Please can someone tell me what Im doing wrong. Here is the functions I'm using to initialize libRocket. rocketfunctions.h

Code: Select all

#include "RocketOgreSystemInterface.h"
#include "MyGui.h"
class AndroidFileInterface;

//#define APPNAME "TEST"

static MyOgreSystem *m_pOgreSystem = NULL;//SystemInterfaceOgre3D *m_pOgreSystem;
static RenderInterfaceOgre3D *m_pOgreRenderer = NULL;

static Ogre::SceneManager* m_pSceneManager = NULL;
static Ogre::RenderWindow* m_pRenderWindow;

static Rocket::Core::Context *m_pMainContext = NULL;
//std::map<Ogre::String, Menu*> m_mMenus;

bool m_isInit;

// Builds an OpenGL-style orthographic projection matrix.
static void buildProjectionMatrix(Ogre::Matrix4& projection_matrix)
{
	float z_near = -1;
	float z_far = 1;

	projection_matrix = Ogre::Matrix4::ZERO;

	// Set up matrices.
	projection_matrix[0][0] = 2.0f / mViewport->getActualWidth();//
	projection_matrix[0][3]= -1.0000000f;
	projection_matrix[1][1]= -2.0f / mViewport->getActualHeight();//
	projection_matrix[1][3]= 1.0000000f;
	projection_matrix[2][2]= -2.0f / (z_far - z_near);
	projection_matrix[3][3]= 1.0000000f;
}

//^^^^****                 Call on window init or possibly re-init?                                ****^^^^//
static void configureRenderSystem()
{	//LOGD("Start of configureRenderSystem");
	Ogre::RenderSystem* render_system = mRoot->getRenderSystem();//Ogre::Root::getSingleton().getRenderSystem();

	// Set up the projection and view matrices.
	Ogre::Matrix4 projection_matrix;
	buildProjectionMatrix(projection_matrix);
	m_pOgreRenderer->setCustomProjectionMatrix( projection_matrix );
	//render_system->_setProjectionMatrix(projection_matrix);
	//render_system->_setViewMatrix(Ogre::Matrix4::IDENTITY);

	// Disable lighting, as all of Rocket's geometry is unlit.
	render_system->setLightingEnabled(false);
	// Disable depth-buffering; all of the geometry is already depth-sorted.
	render_system->_setDepthBufferParams(false, false);
	// Rocket generates anti-clockwise geometry, so enable clockwise-culling.
	render_system->_setCullingMode(Ogre::CULL_CLOCKWISE);
	// Disable fogging.
	render_system->_setFog(Ogre::FOG_NONE);
	// Enable writing to all four channels.
	render_system->_setColourBufferWriteEnabled(true, true, true, true);
	// Unbind any vertex or fragment programs bound previously by the application.
	render_system->unbindGpuProgram(Ogre::GPT_FRAGMENT_PROGRAM);
	render_system->unbindGpuProgram(Ogre::GPT_VERTEX_PROGRAM);

	// Set texture settings to clamp along both axes.
	Ogre::TextureUnitState::UVWAddressingMode addressing_mode;
	addressing_mode.u = Ogre::TextureUnitState::TAM_CLAMP;
	addressing_mode.v = Ogre::TextureUnitState::TAM_CLAMP;
	addressing_mode.w = Ogre::TextureUnitState::TAM_CLAMP;
	render_system->_setTextureAddressingMode(0, addressing_mode);

	// Set the texture coordinates for unit 0 to be read from unit 0.
	render_system->_setTextureCoordSet(0, 0);
	// Disable texture coordinate calculation.
	render_system->_setTextureCoordCalculation(0, Ogre::TEXCALC_NONE);
	// Enable linear filtering; images should be rendering 1 texel == 1 pixel, so point filtering could be used
	// except in the case of scaling tiled decorators.
	render_system->_setTextureUnitFiltering(0, Ogre::FO_LINEAR, Ogre::FO_LINEAR, Ogre::FO_POINT);
	// Disable texture coordinate transforms.
	render_system->_setTextureMatrix(0, Ogre::Matrix4::IDENTITY);
	// Reject pixels with an alpha of 0.
	render_system->_setAlphaRejectSettings(Ogre::CMPF_GREATER, 0, false);
	// Disable all texture units but the first.
	render_system->_disableTextureUnitsFrom(1);

	// Enable simple alpha blending.
	render_system->_setSceneBlending(Ogre::SBF_SOURCE_ALPHA, Ogre::SBF_ONE_MINUS_SOURCE_ALPHA);

	// Disable depth bias.
	render_system->_setDepthBias(0, 0);
};

static void fireRocketUp(void)
{
	m_pRenderWindow = mRenderWind;
	stringstream ss;
	ss << "mViewport actualWidth: " << mViewport->getActualWidth() << "pixels.\n";
	ss << "mViewport actualHeight: " << mViewport->getActualHeight() << "pixels.\n";
	ss << "mRenderWind Width: " << mRenderWind->getWidth() << "pixels.\n";
	ss << "mRenderWind Height: " << mRenderWind->getHeight() << "pixels.\n";
	LOGD(ss.str().c_str());
	ss.str("");
	ss.clear();

	mAndroidFileInterface = new AndroidFileInterface(mAssetMgr);

	m_pOgreRenderer = new RenderInterfaceOgre3D( mViewport->getActualWidth(), mViewport->getActualHeight() );
	Rocket::Core::SetRenderInterface( m_pOgreRenderer );

	m_pOgreSystem = new MyOgreSystem();
	Rocket::Core::SetSystemInterface( m_pOgreSystem );

	//m_pKeybinder = new RocketKeybinding();

	Rocket::Core::Initialise();
	Rocket::Controls::Initialise();
	Rocket::Core::Log::Initialise();

	Rocket::Core::SetFileInterface(mAndroidFileInterface);

	Rocket::Core::String font_names[4];
	font_names[0] = "Delicious-Roman.otf";
	font_names[1] = "Delicious-Italic.otf";
	font_names[2] = "Delicious-Bold.otf";
	font_names[3] = "Delicious-BoldItalic.otf";

	for (int i = 0; i < sizeof(font_names) / sizeof(Rocket::Core::String); i++)
	{
		Rocket::Core::FontDatabase::LoadFontFace(Rocket::Core::String("libRocket/") + font_names[i]);
	}

	font_names[0] = "DroidSerif.ttf";
	font_names[1] = "DroidSerif-Italic.ttf";
	font_names[2] = "DroidSerif-Bold.ttf";
	font_names[3] = "DroidSerif-BoldItalic.ttf";

	for (int i = 0; i < sizeof(font_names) / sizeof(Rocket::Core::String); i++)
	{
		Rocket::Core::FontDatabase::LoadFontFace(Rocket::Core::String("libRocket/") + font_names[i]);
	}

	m_pMainContext = Rocket::Core::CreateContext("Main", Rocket::Core::Vector2i( mViewport->getActualWidth(), mViewport->getActualHeight() ), m_pOgreRenderer );
	//Rocket::Debugger::Initialise( m_pMainContext );
	//m_pMainContext->AddEventListener( "click", this );

	//Rocket::Debugger::SetVisible(true);

	// mouse
	//path = Utility::getFullPath( "Rocket", "cursor.rml" );
	//if( path != "" )
	//{
		Rocket::Core::ElementDocument *cursor = m_pMainContext->LoadMouseCursor( "libRocket/cursor.rml" );
		if( cursor ) cursor->RemoveReference();
	//}

	configureRenderSystem();
	m_pMainContext->SetDimensions( Rocket::Core::Vector2i( mViewport->getActualWidth(),mViewport->getActualHeight()));// m_pRenderWindow->getWidth(), m_pRenderWindow->getHeight() ) );

	m_isInit = true;

};
static void resizeRocketWindow(void)
{	LOGD("RESIZING ROCKET WINDOWS");

	if( m_pMainContext && mRenderWind )
	{
		m_pMainContext->SetDimensions( Rocket::Core::Vector2i( mViewport->getActualWidth(),mViewport->getActualHeight()));// m_pRenderWindow->getWidth(), m_pRenderWindow->getHeight() ) );
	}

};

//^^^    CALL configureRenderSystem()   <---____*************FIRST*******___   ^^^//
static void updateRocketSys(void)
{	//LOGD("START OF UPDATEROCKETSYS");

	if ( m_isInit && mViewport->getOverlaysEnabled() )//Ogre::Root::getSingleton().getRenderSystem()->_getViewport()->getOverlaysEnabled() )
	{	LOGD("UPDATING ROCKETSYS");

		m_pMainContext->Update();
		configureRenderSystem();
		m_pMainContext->Render();
	}

};
Here is RenderInterfaceOgre3D.h that gets included in RocketOgreSystemInterface.h

Code: Select all

#ifndef RENDERINTERFACEOGRE3D_H
#define RENDERINTERFACEOGRE3D_H
#include <Rocket/Core/RenderInterface.h>
#include <Ogre.h>
#include "android/log.h"
static Ogre::Root* mRoot = NULL;
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "MyOgreGame", __VA_ARGS__)
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, "MyOgreGame", __VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, "MyOgreGame", __VA_ARGS__)
/**
	A sample render interface for Rocket into Ogre3D.

	@author Peter Curry

	Modified by Brett Didemus to work with programable pipeline
 */
class RenderInterfaceOgre3D : public Rocket::Core::RenderInterface
{
	public:
		RenderInterfaceOgre3D(unsigned int window_width, unsigned int window_height);
		virtual ~RenderInterfaceOgre3D();

		/// Called by Rocket when it wants to render geometry that it does not wish to optimise.
		virtual void RenderGeometry(Rocket::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rocket::Core::TextureHandle texture, const Rocket::Core::Vector2f& translation);

		/// Called by Rocket when it wants to compile geometry it believes will be static for the forseeable future.
		virtual Rocket::Core::CompiledGeometryHandle CompileGeometry(Rocket::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rocket::Core::TextureHandle texture);

		/// Called by Rocket when it wants to render application-compiled geometry.
		virtual void RenderCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry, const Rocket::Core::Vector2f& translation);
		/// Called by Rocket when it wants to release application-compiled geometry.
		virtual void ReleaseCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry);

		/// Called by Rocket when it wants to enable or disable scissoring to clip content.
		virtual void EnableScissorRegion(bool enable);
		/// Called by Rocket when it wants to change the scissor region.
		virtual void SetScissorRegion(int x, int y, int width, int height);

		/// Called by Rocket when a texture is required by the library.
		virtual bool LoadTexture(Rocket::Core::TextureHandle& texture_handle, Rocket::Core::Vector2i& texture_dimensions, const Rocket::Core::String& source);
		/// Called by Rocket when a texture is required to be built from an internally-generated sequence of pixels.
		virtual bool GenerateTexture(Rocket::Core::TextureHandle& texture_handle, const Rocket::Core::byte* source, const Rocket::Core::Vector2i& source_dimensions);
		/// Called by Rocket when a loaded texture is no longer required.
		virtual void ReleaseTexture(Rocket::Core::TextureHandle texture);

		/// Returns the native horizontal texel offset for the renderer.
		float GetHorizontalTexelOffset();
		/// Returns the native vertical texel offset for the renderer.
		float GetVerticalTexelOffset();

		void setCustomProjectionMatrix( Ogre::Matrix4 projMatrix );

	private:
		Ogre::RenderSystem* render_system;

		Ogre::LayerBlendModeEx colour_blend_mode;
		Ogre::LayerBlendModeEx alpha_blend_mode;

		Ogre::Matrix4 customProjectionMatrix;

		Ogre::TexturePtr m_blankTexture;

		bool scissor_enable;
		int scissor_left;
		int scissor_top;
		int scissor_right;
		int scissor_bottom;
};
Here is RenderInterfaceOgre3D.cpp

Code: Select all

#include "RenderInterfaceOgre3D.h"
//#include "OgreFramework.h"

struct RocketOgre3DVertex
{
	float x, y, z;
	Ogre::uint32 diffuse;
	float u, v;
};

// The structure created for each texture loaded by Rocket for Ogre.
struct RocketOgre3DTexture
{
	RocketOgre3DTexture(Ogre::TexturePtr texture) : texture(texture)
	{
	}

	Ogre::TexturePtr texture;
};

// The structure created for each set of geometry that Rocket compiles. It stores the vertex and index buffers and the
// texture associated with the geometry, if one was specified.
struct RocketOgre3DCompiledGeometry
{
	Ogre::RenderOperation render_operation;
	RocketOgre3DTexture* texture;
};

RenderInterfaceOgre3D::RenderInterfaceOgre3D(unsigned int window_width, unsigned int window_height)
{
	render_system = Ogre::Root::getSingleton().getRenderSystem();

	// Configure the colour blending mode.
	colour_blend_mode.blendType = Ogre::LBT_COLOUR;
	colour_blend_mode.source1 = Ogre::LBS_DIFFUSE;
	colour_blend_mode.source2 = Ogre::LBS_TEXTURE;
	colour_blend_mode.operation = Ogre::LBX_MODULATE;

	// Configure the alpha blending mode.
	alpha_blend_mode.blendType = Ogre::LBT_ALPHA;
	alpha_blend_mode.source1 = Ogre::LBS_DIFFUSE;
	alpha_blend_mode.source2 = Ogre::LBS_TEXTURE;
	alpha_blend_mode.operation = Ogre::LBX_MODULATE;

	scissor_enable = false;

	scissor_left = 0;
	scissor_top = 0;
	scissor_right = (int) window_width;
	scissor_bottom = (int) window_height;

	customProjectionMatrix = Ogre::Matrix4::IDENTITY;

	// Load the blank 1x1 texture used for colour pass through
	Ogre::TextureManager* texture_manager = Ogre::TextureManager::getSingletonPtr();
	m_blankTexture = texture_manager->load("BlankTex.png",
											"General",
											Ogre::TEX_TYPE_2D,
											0);
}

RenderInterfaceOgre3D::~RenderInterfaceOgre3D()
{
}

// Called by Rocket when it wants to render geometry that it does not wish to optimise.
void RenderInterfaceOgre3D::RenderGeometry(Rocket::Core::Vertex* ROCKET_UNUSED(vertices), int ROCKET_UNUSED(num_vertices), int* ROCKET_UNUSED(indices), int ROCKET_UNUSED(num_indices), Rocket::Core::TextureHandle ROCKET_UNUSED(texture), const Rocket::Core::Vector2f& ROCKET_UNUSED(translation))
{
	// We've chosen to not support non-compiled geometry in the Ogre3D renderer.
	LOGD("^*^*&^*^  Rendering non-compiled geometry. This should not be happening!!!!");
}

// Called by Rocket when it wants to compile geometry it believes will be static for the forseeable future.
Rocket::Core::CompiledGeometryHandle RenderInterfaceOgre3D::CompileGeometry(Rocket::Core::Vertex* vertices, int num_vertices, int* indices, int num_indices, Rocket::Core::TextureHandle texture)
{
	RocketOgre3DCompiledGeometry* geometry = new RocketOgre3DCompiledGeometry();
	geometry->texture = texture == NULL ? NULL : (RocketOgre3DTexture*) texture;

	geometry->render_operation.vertexData = new Ogre::VertexData();
	geometry->render_operation.vertexData->vertexStart = 0;
	geometry->render_operation.vertexData->vertexCount = num_vertices;

	geometry->render_operation.indexData = new Ogre::IndexData();
	geometry->render_operation.indexData->indexStart = 0;
	geometry->render_operation.indexData->indexCount = num_indices;

	geometry->render_operation.operationType = Ogre::RenderOperation::OT_TRIANGLE_LIST;


	// Set up the vertex declaration.
	Ogre::VertexDeclaration* vertex_declaration = geometry->render_operation.vertexData->vertexDeclaration;
	size_t element_offset = 0;
	vertex_declaration->addElement(0, element_offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
	element_offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
	vertex_declaration->addElement(0, element_offset, Ogre::VET_COLOUR, Ogre::VES_DIFFUSE);
	element_offset += Ogre::VertexElement::getTypeSize(Ogre::VET_COLOUR);
	vertex_declaration->addElement(0, element_offset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES);

	// Create the vertex buffer.
	Ogre::HardwareVertexBufferSharedPtr vertex_buffer = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(vertex_declaration->getVertexSize(0), num_vertices, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
	geometry->render_operation.vertexData->vertexBufferBinding->setBinding(0, vertex_buffer);

	// Fill the vertex buffer.
	RocketOgre3DVertex* ogre_vertices = (RocketOgre3DVertex*) vertex_buffer->lock(0, vertex_buffer->getSizeInBytes(), Ogre::HardwareBuffer::HBL_NORMAL);
	for (int i = 0; i < num_vertices; ++i)
	{
		ogre_vertices[i].x = vertices[i].position.x;
		ogre_vertices[i].y = vertices[i].position.y;
		ogre_vertices[i].z = 0;

		Ogre::ColourValue diffuse(vertices[i].colour.red / 255.0f, vertices[i].colour.green / 255.0f, vertices[i].colour.blue / 255.0f, vertices[i].colour.alpha / 255.0f);
		render_system->convertColourValue(diffuse, &ogre_vertices[i].diffuse);

		ogre_vertices[i].u = vertices[i].tex_coord[0];
		ogre_vertices[i].v = vertices[i].tex_coord[1];
	}
	vertex_buffer->unlock();

	Ogre::HardwareIndexBufferSharedPtr index_buffer = Ogre::HardwareBufferManager::getSingleton().createIndexBuffer(Ogre::HardwareIndexBuffer::IT_16BIT, num_indices, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);

	geometry->render_operation.indexData->indexBuffer = index_buffer;
	geometry->render_operation.useIndexes = true;

	// Fill the index buffer.
	short* ogre_indices = (short*)index_buffer->lock(0, index_buffer->getSizeInBytes(), Ogre::HardwareBuffer::HBL_NORMAL);
	for (int i = 0; i < num_indices; ++i)
    {
		ogre_indices[i] = indices[i];
	}

	index_buffer->unlock();

	Rocket::Core::CompiledGeometryHandle compiledGeometry = 0;
	compiledGeometry = reinterpret_cast<Rocket::Core::CompiledGeometryHandle>(geometry);
	if( !compiledGeometry )
	{
		Ogre::LogManager::getSingletonPtr()->logMessage( "libRocket: Failed to compile geometry -- Line 169 -- RenderInterfaceOgre3D.cpp" );
	}

	return compiledGeometry;
}

// Called by Rocket when it wants to render application-compiled geometry.
void RenderInterfaceOgre3D::RenderCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry, const Rocket::Core::Vector2f& translation)
{
	Ogre::Matrix4 transform;
	transform.makeTrans(translation.x, translation.y, 0);
	render_system->_setWorldMatrix(transform);

	render_system = Ogre::Root::getSingleton().getRenderSystem();
	RocketOgre3DCompiledGeometry* ogre3d_geometry = (RocketOgre3DCompiledGeometry*)geometry;

	if (ogre3d_geometry->texture != NULL)
	{
		render_system->_setTexture(0, true, ogre3d_geometry->texture->texture);

		// ADD THIS LINE:
		render_system->_setTextureUnitFiltering(0, Ogre::FO_LINEAR, Ogre::FO_LINEAR, Ogre::FO_POINT);
		// Ogre can change the blending modes when textures are disabled - so in case the last render had no texture,
		// we need to re-specify them.
		render_system->_setTextureBlendMode(0, colour_blend_mode);
		render_system->_setTextureBlendMode(0, alpha_blend_mode);
	}
	else
	{
        // ADD THIS LINE:
		render_system->_setTextureUnitFiltering(0, Ogre::FO_LINEAR, Ogre::FO_LINEAR, Ogre::FO_POINT);
		// render_system->_disableTextureUnit(0);

		// Background elements don't use textures, and just have a pure colour element. So, rather than creating a different shader
		// for colour pass-through, just have the fragment shader sample a 1x1 texture with colour values of ( 1.0, 1.0, 1.0, 1.0 )
		render_system->_setTexture( 0, true, m_blankTexture );
	}

	Ogre::GpuProgramPtr vpShader = Ogre::HighLevelGpuProgramManager::getSingletonPtr()->getByName( "mprog/RocketVP_GLSLES" );
	Ogre::GpuProgramPtr fpShader = Ogre::HighLevelGpuProgramManager::getSingletonPtr()->getByName( "mprog/RocketFP_GLSLES" );

	if( vpShader.isNull())
	{
		LOGD("vpShader IS NULL!");
	}
	else
	{
		//LOGD("vpShader IS NOT NULL!");
	}
	if( fpShader.isNull() )
	{
		LOGD("fpShader IS NULL!");
	}
	else
	{
		//LOGD("fpShader IS NOT NULL!");
	}

	Ogre::Matrix4 model;
	model.makeTrans(translation.x, translation.y, 0);

	Ogre::Matrix4 viewProjMatrix = customProjectionMatrix * model;

	Ogre::GpuProgramParametersSharedPtr params = vpShader->getDefaultParameters();
	params->setNamedConstant( "modelViewProj", &viewProjMatrix, 1 );

	Ogre::GpuProgram* vpBindingShader = vpShader->_getBindingDelegate();
	Ogre::GpuProgram* fpBindingShader = fpShader->_getBindingDelegate();

	render_system->bindGpuProgram( vpShader.get() );//vpBindingShader );
	render_system->bindGpuProgram( fpShader.get() );//fpBindingShader );

	render_system->bindGpuProgramParameters( Ogre::GPT_VERTEX_PROGRAM, params, Ogre::GPV_GLOBAL );

	render_system->_render( ogre3d_geometry->render_operation );
}

// Called by Rocket when it wants to release application-compiled geometry.
void RenderInterfaceOgre3D::ReleaseCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry)
{
	RocketOgre3DCompiledGeometry* ogre3d_geometry = reinterpret_cast<RocketOgre3DCompiledGeometry*>(geometry);
	delete ogre3d_geometry->render_operation.vertexData;
	delete ogre3d_geometry->render_operation.indexData;
	delete ogre3d_geometry;
}

// Called by Rocket when it wants to enable or disable scissoring to clip content.
void RenderInterfaceOgre3D::EnableScissorRegion(bool enable)
{
	scissor_enable = enable;

	if (!scissor_enable)
		render_system->setScissorTest(false);
	else
		render_system->setScissorTest(true, scissor_left, scissor_top, scissor_right, scissor_bottom);
}

// Called by Rocket when it wants to change the scissor region.
void RenderInterfaceOgre3D::SetScissorRegion(int x, int y, int width, int height)
{
	scissor_left = x;
	scissor_top = y;
	scissor_right = x + width;
	scissor_bottom = y + height;

	if (scissor_enable)
		render_system->setScissorTest(true, scissor_left, scissor_top, scissor_right, scissor_bottom);
}

// Called by Rocket when a texture is required by the library.
bool RenderInterfaceOgre3D::LoadTexture(Rocket::Core::TextureHandle& texture_handle, Rocket::Core::Vector2i& texture_dimensions, const Rocket::Core::String& source)
{
	Ogre::TextureManager* texture_manager = Ogre::TextureManager::getSingletonPtr();
	Ogre::TexturePtr ogre_texture = texture_manager->getByName(Ogre::String(source.CString()));
	if (ogre_texture.isNull())
	{
		Ogre::LogManager::getSingletonPtr()->logMessage( " loading rocket texture:" + Ogre::String(source.CString()) );
		ogre_texture = texture_manager->load(Ogre::String(source.CString()),
											 "Rocket",
											 Ogre::TEX_TYPE_2D,
											 0);
	}

	if (ogre_texture.isNull())
	{
		Ogre::LogManager::getSingletonPtr()->logMessage( " Failed to load" );
		return false;
	}
	else
	{
		Ogre::LogManager::getSingletonPtr()->logMessage( "Loaded ok good! yay!" );
	}

	texture_dimensions.x = ogre_texture->getWidth();
	texture_dimensions.y = ogre_texture->getHeight();

	texture_handle = reinterpret_cast<Rocket::Core::TextureHandle>(new RocketOgre3DTexture(ogre_texture));
	return true;
}

// Called by Rocket when a texture is required to be built from an internally-generated sequence of pixels.
bool RenderInterfaceOgre3D::GenerateTexture(Rocket::Core::TextureHandle& texture_handle, const Rocket::Core::byte* source, const Rocket::Core::Vector2i& source_dimensions)
{
	bool result = true;
	Ogre::LogManager::getSingletonPtr()->logMessage( "libRocket: Generating texture" );
	static int texture_id = 1;
	Ogre::DataStreamPtr dataStream = Ogre::DataStreamPtr(new Ogre::MemoryDataStream((void*) source, source_dimensions.x * source_dimensions.y * sizeof(unsigned int)));
	Ogre::TexturePtr ogre_texture = Ogre::TextureManager::getSingleton().loadRawData(Rocket::Core::String(16, "%d", texture_id++).CString(),
																					 "Rocket",
																					 dataStream,
																					 (Ogre::ushort)source_dimensions.x,
																					 (Ogre::ushort)source_dimensions.y,
																					 Ogre::PF_A8R8G8B8,
																					 //Ogre::PF_A8B8G8R8,
																					 Ogre::TEX_TYPE_2D,
																					 0);

	if (ogre_texture.isNull())
	{
		result = false;
		Ogre::LogManager::getSingletonPtr()->logMessage( "libRocket: Failed to generate texture" );
	}
	else
	{
		texture_handle = reinterpret_cast<Rocket::Core::TextureHandle>(new RocketOgre3DTexture(ogre_texture));
		Ogre::LogManager::getSingletonPtr()->logMessage( "libRocket: texture generated ok good #1" );
	}

	return result;
}

// Called by Rocket when a loaded texture is no longer required.
void RenderInterfaceOgre3D::ReleaseTexture(Rocket::Core::TextureHandle texture)
{
	delete ((RocketOgre3DTexture*) texture);
}

// Returns the native horizontal texel offset for the renderer.
float RenderInterfaceOgre3D::GetHorizontalTexelOffset()
{
	return -render_system->getHorizontalTexelOffset();
}

// Returns the native vertical texel offset for the renderer.
float RenderInterfaceOgre3D::GetVerticalTexelOffset()
{
	return -render_system->getVerticalTexelOffset();
}

void RenderInterfaceOgre3D::setCustomProjectionMatrix( Ogre::Matrix4 projMatrix )
{
	customProjectionMatrix = projMatrix;
}
BlankTex.png gets loaded properly and so do the demo.rml and window.rml Im using from the librocket sample. Ive tried everything I can find. Should I download the newest 1.9 ogre source and build for android? The prebuilt sdk had been working so far. I even have bullet working properly and the Ogre::Overlay system but Ive read I shouldnt use the overlay system for a game, and I was going to but I cannot figure out how to get the overlays to reposition after reorientation.

So if anyone can please help me get libRocket rendering on my android THANK YOU.

Edit: Made title more specific.
0 x

Post Reply