"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
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.
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.
I seriously doubt one exists.
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.
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.
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.
if i understand it well awesomium can render to offscreen bitmaps and stuff like that.
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..
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..
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.
- 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.
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.
AntTweakBar is a library which does not mess up with OpenGL state. I think it has such an editor.
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?
http://www.pawfal.org/fluxus/
not quite what you're looking for?
not quite what you're looking for?
wow, that anttweakbar looks really useful for in-demo editing!
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!
why not use a child window?
fullscreen is the only reason that comes to mind...
rare: There's no such thing as "fullscreen" in OpenGL...
That AntTweakBar looks great and easy to use. Does it support OpenGL 3.x?
I second that. AntTweakBar seems awesome!
xernobyl: You can always use compatibility profile while creating your context.
xernobyl: You can always use compatibility profile while creating your context.
I've read the first post and that's actually not what iq wants.
ftgl had some sort of layout capabilities. quite simple, but should not be that hard to expand it to handle rtf afair
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
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
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?)
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?)
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...
iq: Is this all because you're too lazy to write a scroller?
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)
The whole code for this program is
There is a sample (ParamsBasic)
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 )
Does libcinder actually have a rich edit box?