pouët.net

Go to bottom

"edit" box for GL

category: code [glöplog]
anybody with a class that I can use to edit text (multiline, copy&past,fonts,etc) in OpenGL? I was trying a native RichEdit but it fights with the GL rendering, of course. I'm looking for something tiny and self contained, not a complete GUI system that does events and crap. Something like

Code: class GlEdit { const char *GetText( void ); void SetText( const char *txt ); void KeyPress( char key ); void JumpToLine( int line ); void SetFont( int size, bool italic, bool bold, const char *fontName ); void SetColor( int rgb ); void Render( void ); };


I would give him user's key presses though KeyPress() and let the class do multilines, scrolling and stuff. Render simply renders the stuff, etc etc.

I would need it soon, so rather than a "have a look to <amazing the opensource GUI>, you can probably strip it down and remove the crap and get the thing" I would actually appreciate any code/direct pointer to the self-contained class, if that exisited.
added on the 2010-08-25 07:52:55 by iq iq
I seriously doubt one exists.
added on the 2010-08-25 08:00:27 by sol_hsa sol_hsa
Have you considered overriding the paint method of a RichEdit control? Get it to render to an offscreen bitmap, then copy the bitmap to your GL surface (or a texture) after any update.

Alternatively, don't update the parts of the GL surface that contain edit boxes. Not sure how that works in GL, but in DX it's straightforward.
added on the 2010-08-25 08:35:43 by doomdoom doomdoom
feels over the top but may be relatively quick and natural to implement: awesomium (an embeddable HTML/JS rendering component) with a Javascript rich edit control, such as FCKeditor and the likes?

if i understand it well awesomium can render to offscreen bitmaps and stuff like that.
added on the 2010-08-25 09:04:51 by skrebbel skrebbel
got one in VSXu since 5 years, always editing shaders in realtime there.
but it's part of the big GUI system.
but it works kind of like you describe. maybe you can strip out the annoying parts..
added on the 2010-08-25 09:10:00 by jaw jaw
If you don't do heavy rendering, you could try to render all areas that are NOT in the native RichEdit area, using 4 scissor boxes, with the opengl scissor test.
- top rect (0,0, width, editBoxTop)
- left rect (0, editBoxTop, editBoxLeft, editBoxBottom)
- right rect (editBoxRight, editBoxTop, width, editBoxBottom)
- bottom rect (0, editBoxBottom, width, height)

This of course implies rendering the scene 4 times... But it might work.
added on the 2010-08-25 09:30:30 by xTr1m xTr1m
Quote:
rather than a "have a look to <amazing the opensource GUI>, you can probably strip it down and remove the crap and get the thing" I would actually appreciate any code/direct pointer to the self-contained class


Quote:
but it's part of the big GUI system.
but it works kind of like you describe. maybe you can strip out the annoying parts..


\o/

Anyway, I do think you should be able to extract a bitmap from a double-buffered RichEdit control and pass it on to OpenGL, while preventing the control from refreshing itself. If you can't extract an existing bitmap, you should be able to redirect paint events to an off-screen bitmap.

In theory it's simple and elegant, and I strongly doubt there are any self-contained rich-edit OpenGL classes out there. They'll either be very simple (no fonts etc.) or part of some glorious framework.
added on the 2010-08-25 09:50:12 by doomdoom doomdoom
AntTweakBar is a library which does not mess up with OpenGL state. I think it has such an editor.
added on the 2010-08-25 10:49:24 by ponce ponce
iq: Shouldn't the pixels should be culled by the pixel ownership test in OpenGL? Did you set up the OpenGL context in a weird way?
added on the 2010-08-25 11:50:02 by kusma kusma
http://www.pawfal.org/fluxus/
not quite what you're looking for?
added on the 2010-08-25 12:16:01 by psenough psenough
wow, that anttweakbar looks really useful for in-demo editing!
added on the 2010-08-25 12:38:43 by skrebbel skrebbel
I agree with the DOOM and would go with overriding the WM_PAINT handler of the edit box. Seems like a simple solution. AntTweakBar looks nice though!
added on the 2010-08-25 15:01:43 by raer raer
why not use a child window?
added on the 2010-08-25 15:36:29 by the_Ye-Ti the_Ye-Ti
fullscreen is the only reason that comes to mind...
added on the 2010-08-25 16:24:49 by raer raer
rare: There's no such thing as "fullscreen" in OpenGL...
added on the 2010-08-25 17:05:22 by kusma kusma
That AntTweakBar looks great and easy to use. Does it support OpenGL 3.x?
added on the 2010-08-25 17:11:33 by xernobyl xernobyl
I second that. AntTweakBar seems awesome!
xernobyl: You can always use compatibility profile while creating your context.
added on the 2010-08-25 18:01:50 by masterm masterm
I've read the first post and that's actually not what iq wants.
added on the 2010-08-25 18:38:06 by ponce ponce
ftgl had some sort of layout capabilities. quite simple, but should not be that hard to expand it to handle rtf afair
added on the 2010-08-25 21:08:59 by rmeht rmeht
I'd also override WM_PAINT on a richedit. Some common controls (not 100% sure about richedit) support passing in a HDC to the wParam of WM_PAINT, which makes them draw to that instead of the window. In which case, it's simply a case of creating a new in-memory DC, attaching a bitmap to it, passing that to the original WindowProc, then copying that to a texture.

I'm not sure how much it'll help, but here's some really dodgy code I wrote for doing it with a listview, in D3D: http://pastebin.com/7ntdQbgK
added on the 2010-08-25 22:10:38 by leblane leblane
thx guys, I will try the WM_PAINT overriding idea, despite is Windows only.

About Fluxus, yes, it is live coding what I want to do (right now I do it in an external editor), but I'm not sure they have source code available that I can rip from.

If anybody makes ever a GlEdit class as the one I described, please please please release it as a demotool here in pouet, or something - i will promise you eternal gratitude (note to self - why don't you write your own, lazy bastard?)
added on the 2010-08-26 03:35:18 by iq iq
iq: why not using a custom external editor that sends your text\sourcecode\whatever to your opengl application through socket\dde\clipboard\whatever? with two monitor should be even more usable...
added on the 2010-08-26 08:54:10 by rmeht rmeht
iq: Is this all because you're too lazy to write a scroller?
added on the 2010-08-26 09:07:45 by doomdoom doomdoom
iq, I would give a try to libcinder. Its well integrated with OpenGL and seems to have some cool UI API.

There is a sample (ParamsBasic)
BB Image

The whole code for this program is
Code: #include "cinder/app/AppBasic.h" #include "cinder/Camera.h" #include "cinder/params/Params.h" using namespace ci; using namespace ci::app; class TweakBarApp : public AppBasic { public: void setup(); void resize( int width, int height ); void draw(); CameraPersp mCam; params::InterfaceGl mParams; float mObjSize; Quatf mObjOrientation; Vec3f mLightDirection; ColorA mColor; }; void TweakBarApp::setup() { mObjSize = 4; mLightDirection = Vec3f( 0, 0, -1 ); mColor = ColorA( 0.25f, 0.5f, 1.0f, 1.0f ); // setup our default camera, looking down the z-axis mCam.lookAt( Vec3f( -20, 0, 0 ), Vec3f::zero() ); // Setup the parameters mParams = params::InterfaceGl( "Parameters", Vec2i( 200, 400 ) ); mParams.addParam( "Cube Size", &mObjSize, "min=0.1 max=20.5 step=0.5 keyIncr=z keyDecr=Z" ); mParams.addParam( "Cube Rotation", &mObjOrientation ); mParams.addParam( "Cube Color", &mColor, "" ); mParams.addSeparator(); mParams.addParam( "Light Direction", &mLightDirection, "" ); } void TweakBarApp::resize( int width, int height ) { mCam.setAspectRatio( getWindowAspectRatio() ); } void TweakBarApp::draw() { // this pair of lines is the standard way to clear the screen in OpenGL gl::enableDepthRead(); gl::enableDepthWrite(); gl::clear( Color( 0.1f, 0.1f, 0.1f ) ); glLoadIdentity(); glEnable( GL_LIGHTING ); glEnable( GL_LIGHT0 ); GLfloat lightPosition[] = { -mLightDirection.x, -mLightDirection.y, -mLightDirection.z, 0.0f }; glLightfv( GL_LIGHT0, GL_POSITION, lightPosition ); glMaterialfv( GL_FRONT, GL_DIFFUSE, mColor ); gl::setMatrices( mCam ); gl::rotate( mObjOrientation ); gl::color( mColor ); gl::drawCube( Vec3f::zero(), Vec3f( mObjSize, mObjSize, mObjSize ) ); // Draw the interface params::InterfaceGl::draw(); } CINDER_APP_BASIC( TweakBarApp, RendererGl )
added on the 2010-08-26 09:51:07 by xoofx xoofx
Does libcinder actually have a rich edit box?
added on the 2010-08-26 10:00:54 by doomdoom doomdoom

login

Go to top