librocket and Orx

edited May 2012 in Help request
Has anyone tried using librocket with Orx yet? I made an attempt today with their OpenGL renderer (replacing the orxRENDER_EVENT_OBJECT_START of an object with a dummy graphic).

The program always either crashes in this function or renders garbage on the screen:
// Called by Rocket when it wants to render geometry that it does not wish to optimise.
void ShellRenderInterfaceOpenGL::RenderGeometry(Rocket::Core::Vertex* vertices, int ROCKET_UNUSED(num_vertices), int* indices, int num_indices, const Rocket::Core::TextureHandle texture, const Rocket::Core::Vector2f& translation)
{
	glPushMatrix();
	glTranslatef(translation.x, translation.y, 0);

	glVertexPointer(2, GL_FLOAT, sizeof(Rocket::Core::Vertex), &vertices[0].position);
	//glEnableClientState(GL_COLOR_ARRAY);
	glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(Rocket::Core::Vertex), &vertices[0].colour);

	if (!texture)
	{
		glDisable(GL_TEXTURE_2D);
		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	}
	else
	{
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, (GLuint) texture);
		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
		glTexCoordPointer(2, GL_FLOAT, sizeof(Rocket::Core::Vertex), &vertices[0].tex_coord);
	}

	//glDrawElements(GL_TRIANGLES, num_indices, GL_UNSIGNED_INT, indices);

        /*
         ** CRASHES AT THIS LINE
         */
	glDrawElements(GL_TRIANGLES, num_indices, GL_UNSIGNED_SHORT, indices);

	glPopMatrix();
}

The entire file is here: http://pastebin.com/8EGbHnwE

Anyway, I don't know much about OpenGL so I'm going to have to learn to troubleshoot this more. I was just wondering if anyone else had tried this.

CEGUI sort of "just worked" when I called its rendering code the same way.

Comments

  • edited May 2012
    Yep, so you have to save (push) the OpenGL states before modifying them and restore (pop) them when you're done. Otherwise all hell breaks loose and that's what happened to you.

    Look for glPushAttrib and glPushClientAttrib on the net. However those aren't dispo for OpenGL ES I believe, which means you'll have to save everything you're going to modify manually, for example calling glGetPointerv before glVertexPointer/glColorPointer.

    All this isn't very fun I know, so another option would be to call the orxDisplay_* interface instead. As long as you draw quads/polygons you should be able to do it without having to issue your own OpenGL calls.

    Let me know if you have more troubles with that.
  • edited May 2012
    Thanks. Not that it's not fun, it's just confusing when you have to start debugging a lot of unfamiliar stuff ;)

    I added glPush and glPop around the rest of the function:
    glPushClientAttrib (GL_CLIENT_ALL_ATTRIB_BITS);
    glPushAttrib (GL_ALL_ATTRIB_BITS);
    ...
    glPopAttrib ();
    glPopClientAttrib ();
    

    Same problem. Also, the crash happens the very first time that glDrawElements call is it, so it probably doesn't mean GL state corruption from the last frame, right?

    I will pull this out of my Orx project and set up a very basic example in a barebones OpenGL project.
  • edited May 2012
    Whoops, if I add these I don't crash and I get something resembling what it's supposed to look like:
    glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
    

    http://i.imgur.com/sCWuH.png

    So yes.. looks like I need to save these pointers manually. I will try it.
  • edited May 2012
    Oh hey,

    Forgot to mention we're using an IBO (Index Buffer Object) for rendering, so if you don't unbind it, the last arg you send to your draw element code will make OpenGL look outside the buffer and crash. :D

    You simply need to unbind it before your drawing call. Look for GL _ELEMENT_ARRAY_BUFFER_ARB in the glfw display plugin.
  • edited May 2012
    hey nice find acksys

    you can check this post maybe it will help
    http://forums.librocket.com/viewtopic.php?f=6&t=870

    iarwain

    when you say:
    All this isn't very fun I know, so another option would be to call the orxDisplay_* interface instead. As long as you draw quads/polygons you should be able to do it without having to issue your own OpenGL calls.

    I have no idea on what kind of geometry libRocket is using, the comments in the source referts to TRIANGLES and that vertex_num is always a multiple of 3, but not 6 (2 TRIANGLES)

    so basically we should use orxDisplay_TransformBitmap / orxDisplay_BlitBitmap ?

    lydesik
  • edited May 2012
    Well it's usually more convenient to use the orxDisplay_* interface as it hides a lot of things that happens behind the scene but I don't know if librocket can be shoehorned that way, I've never used it myself.
  • edited May 2012
    @lydesik, I am doing a little work behind the scenes on an in-engine Orx config editor and this came up in my research. It came up again in a thread with iarwain and grey. A lot of people are using librocket, and the standout feature is it based on HTML/CSS.

    Thanks for that thread. I did come across it elsewhere. Right now, I'm just trying to get it to work on the computers. Getting close. I will post if/when I get it right.
  • edited June 2012
    Success! I had some time to work on it tonight and it is now rendering properly. It is required to push/pop attributes at the entry and exit of the rendering function and unbind the IBO as discussed.

    Here's the full function on pastebin in case it helps anyone else: http://pastebin.com/ViDAgySd

    Hopefully no one minds pastebin. I like it because the forum seems to lose indentation formatting.
  • edited June 2012
    Nice!
    How's the editor coming? :)
  • edited June 2012
    Well, I'm back to it now that I've gotten over that hiccup. I wanted to be able to evaluate CEGUI and libRocket against each other.

    Here's what's left for my 'proof of concept' milestone:

    - Finishing implementing WidgetManager for libRocket.
    - Complete the Object Editor and FX Editor windows
    - Complete save/load function for Orx config files

    At that time, I will post details and see if anyone else wants to help with the project.
  • edited June 2012
    Are you using the orxConfig API to change the edited values in memory? Cause if you do you can easily serialize everything by using orxConfig_Load and orxConfig_Save.
  • edited June 2012
    Yes. Right now I have all the editor objects inherit from a "DontSave" object and check that to make sure I don't save the editor's stuff with the user's config.

    I've since noticed there's a "Save" flag for ScrollObjects which ScrollEd uses, so I might change it to use that instead.

    Hopefully I can get some momentum and one or two other interested people and get an editor going. I think it would be great to have a config section editor that could work seamlessly alongside ScrollEd for map creation.
  • edited June 2012
    I think so too. I, for one, would love to see that project come to reality.
    Good luck! :)
  • edited June 2012
    +1000

    an UI manager/editor for orx would be awesome.

    I'm ready to help you to make this works on Android
  • edited August 2012
    any news on libRocket integration?
  • edited August 2012
    I did get librocket working, finally. It took twice as long as making CEGUI work and probably twice as much code.

    librocket has a reputation for good design, but I found the library is a lot less helpful than CEGUI. CEGUI has a bad reputation around the internet for bloat and design, but most of its dependencies are optional, it has a lot of very helpful functions, and pretty much "just works" as is advertised.

    For that reason, I'm continuing with CEGUI in my project. The librocket support is still there in a separate branch, but it's now out of sync with the master.

    @lydesik, please check https://github.com/fmahnke/OrxCraft if you're interested in this project. I would love any help. graag has also taken an interest and has added some things in his own branches.
Sign In or Register to comment.