TextRenderer and VAOs

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

TextRenderer and VAOs

JanBenes
Hi,
I've been trying to integrate the curve texture renderer into my code. While I was successful with an application that only draws text, it kept breaking my application as a whole. I finally tracked it down to the attached MWE TestTextRendering.java. Here's the offending piece of code:

GL3 gl = new DebugGL3(drawable.getGL().getGL3());
drawable.setGL(gl);
	
gl.glClearColor(0.3f, 0.3f, 0.3f, 1.0f);
gl.glEnable(GL3.GL_DEPTH_TEST);
gl.glEnable(GL3.GL_MULTISAMPLE);
		
try {
	font = FontFactory.get(FontFactory.UBUNTU).getDefault();
			
	textRenderState = RenderState.createRenderState(new ShaderState(), SVertex.factory());
        textRenderer = TextRenderer.create(textRenderState, 0);	
	        
        textRenderer.init(gl);
	textRenderer.setAlpha(gl, 1.0f);
	textRenderer.setColorStatic(gl, 0.0f, 0.0f, 0.0f);        
} catch(Exception e) {
	throw new RuntimeException(e);
}
        
// here, I would create a VA, IB, VB, set them up, etc, only to finally break the bind 
// on the vertex array as part of the cleanup
        
// UNCOMMENT BELOW TO MAKE APPLICATION THROW AN EXCEPTION
//gl.glBindVertexArray(0); 

If the last line gets uncommented, I get an exception thrown from within the text rendering code (full strack trace attached jogl_exception.txt) when I actually try to render some text in the main loop.

Exception in thread "AWT-EventQueue-0" javax.media.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glEnableVertexAttribArray(<int> 0x0): GL_INVALID_OPERATION ( 1282 0x502),
	at javax.media.opengl.DebugGL3.checkGLGetError(DebugGL3.java:9753)
	at javax.media.opengl.DebugGL3.glEnableVertexAttribArray(DebugGL3.java:3927)
	at com.jogamp.opengl.util.glsl.ShaderState.enableVertexAttribArray(ShaderState.java:492)
	at com.jogamp.opengl.util.glsl.ShaderState.enableVertexAttribArray(ShaderState.java:547)
	at jogamp.opengl.util.glsl.GLSLArrayHandler.enableShaderState(GLSLArrayHandler.java:112)
	at jogamp.opengl.util.glsl.GLSLArrayHandler.enableState(GLSLArrayHandler.java:64)
	at com.jogamp.opengl.util.GLArrayDataClient.enableBuffer(GLArrayDataClient.java:207)
	at com.jogamp.opengl.util.GLArrayDataClient.seal(GLArrayDataClient.java:196)
	at jogamp.graph.curve.opengl.VBORegionSPES2.update(VBORegionSPES2.java:120)
	at com.jogamp.graph.curve.opengl.GLRegion.draw(GLRegion.java:124)
	at jogamp.graph.curve.text.GlyphString.renderString3D(GlyphString.java:187)

Even though I tried mimicking the unit test for font rendering, I might have gotten something wrong. Also, I only went as far as creating the buffers and the VA in the MWE, but I never actually called the vertex array
gl.glEnableVertexAttribArray
, or bound shaders.

Am I doing something wrong? Or could it be a problem with the text rendering code?
Thanks!

I'm running a Mac OS 10.8.2 with
Renderer:       NVIDIA GeForce GTX 680MX OpenGL Engine
OpenGL version: 3.2 NVIDIA-8.6.22
GLSL version:   1.50
INFO: GL_ARB_ES2_compatibility: false
INFO: GL_ARB_ES3_compatibility: false

and am using the following revisions (will try the latest tomorrow if required)

415f5c29ffae7cf5a26737da38e31cb84b652539 Jun 24, 2013 for jogl
0cce9a0eb5ab3ca25531c8fb8a9ef8be5c758487 Jun 24, 2013 for gluegen
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer and VAOs

gouessej
Administrator
Hi

Please try to use the RC12, I remember that a bug concerning VAO was fixed a few weeks ago.
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer and VAOs

JanBenes
Hi Julien,

I have tried both RC12 and the latest, i.e.

gluegen: 3ceb32fb505363ccc02fc4cce1362257ca98a3e5
jogl: 433e3914324b90c910b018bb7d9d80e814c67123

and under both of those, the MWE that I've posted throws an exception.
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer and VAOs

Rami Santina
Administrator
hi, you need to use the program before calling bind or it will consider it as invalid operation. Not sure why ur clearing the binding.

something like this works perfectly for me; using curve render in an app for annotations etc

 if(!regionRenderer.isInitialized()) {
         regionRenderer.init(gl);
         regionRenderer.setAlpha(gl, 0.6f);
         regionRenderer.setColorStatic(gl, 1, 0, 0);
 }


renderState.getShaderState().useProgram(gl, true);
regionRenderer.resetModelview(null);
renderState.pmvMatrix().glMultMatrixf(pmvMatrix.val, 0);
 regionRenderer.setColorStatic(gl, color.getRed(), color.getGreen(), color.getBlue());
regionRenderer.setAlpha(gl, 0.6f);
regionRenderer.updateMatrix(gl);
regionRenderer.draw(gl, region, initPosition, texDim);
 renderState.getShaderState().useProgram(gl, false);

Inline image 1


On Sun, Jul 7, 2013 at 11:56 PM, JanBenes [via jogamp] <[hidden email]> wrote:
Hi Julien,

I have tried both RC12 and the latest, i.e.

gluegen: 3ceb32fb505363ccc02fc4cce1362257ca98a3e5
jogl: 433e3914324b90c910b018bb7d9d80e814c67123

and under both of those, the MWE that I've posted throws an exception.


If you reply to this email, your message will be added to the discussion below:
http://forum.jogamp.org/TextRenderer-and-VAOs-tp4029530p4029534.html
To start a new topic under jogl, email [hidden email]
To unsubscribe from jogamp, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer and VAOs

JanBenes
Hi Rami,

thanks for looking into this. Unfortunately, it didn't help (see my modified source TestTextRendering_v2.java). This is my modified display method

public void display(GLAutoDrawable drawable) {
	System.out.println("display");
		
	GL3 gl = new DebugGL3(drawable.getGL().getGL3());
	drawable.setGL(gl);
		
	gl.glClear(GL3.GL_COLOR_BUFFER_BIT | GL3.GL_DEPTH_BUFFER_BIT);		
	<nabble_a href="TestTextRendering_v2.java">TestTextRendering_v2.java</nabble_a>
	int width = drawable.getWidth();
	int height = drawable.getHeight();
		
	if(!textRenderer.isInitialized()) {
		textRenderer.init(gl);
		textRenderer.setAlpha(gl, 1.0f);
		textRenderer.setColorStatic(gl, 1, 0, 0);
	}
		
	textRenderer.getShaderState().useProgram(gl, true);
		
	textRenderer.reshapePerspective(null, 45.0f, width, height, 0.1f, 7000.0f);  // has probably no effect
	textRenderer.reshapeOrtho(null, width, height, 0.1f, 7000.0f);

        final float[] textPosition = new float[] {0, 0, 0};
        final int[] texSize = new int[] { 400 }; 
        final int fontSize = 50;
        
        textRenderer.resetModelview(null);
        textRenderer.translate(gl, 250, 250, -6000);
        textRenderer.updateMatrix(gl);
        textRenderer.drawString3D(gl, font, "Hi", textPosition, fontSize, texSize);
        
        textRenderer.getShaderState().useProgram(gl, false);
        
        // UNCOMMENT BELOW TO MAKE APPLICATION THROW AN EXCEPTION IN THE NEXT CALL TO DISPLAY
        // gl.glBindVertexArray(0); 
}

To me, it seems as if the text renderer wasn't able to handle the unbinding of (its) vertex array. I don't think it is illegal to call glBindVertexArray(0). Maybe a different call is needed to re-bind the text renderer's buffer? Also, Rami, could you please show me how the Region variable is created? I can't try to just copy-paste and run your code without it. Thanks!

I have tried (don't know why I haven't tried that before) using a DebugGL3 context and am now getting the following output by calling drawString3D after calling glBindVertexArray(0); here, "init" and "display" are just debugging print-outs. I get:

init
display
display
Exception in thread "AWT-EventQueue-0" javax.media.opengl.GLException: Thread[AWT-EventQueue-0,6,main] glGetError() returned the following error codes after a call to glGetVertexAttribiv(<int> 0x0, <int> 0x889F, <[I>, <int> 0x0): GL_INVALID_OPERATION ( 1282 0x502), 
	at javax.media.opengl.DebugGL3.checkGLGetError(DebugGL3.java:9753)
	at javax.media.opengl.DebugGL3.glGetVertexAttribiv(DebugGL3.java:8150)
	at javax.media.opengl.DebugGL3.glGetVertexAttribiv(DebugGL3.java:8144)
	at javax.media.opengl.DebugGL3.glGetVertexAttribiv(DebugGL3.java:8144)
	at jogamp.opengl.util.glsl.GLSLArrayHandler.enableShaderState(GLSLArrayHandler.java:101)
	at jogamp.opengl.util.glsl.GLSLArrayHandler.enableState(GLSLArrayHandler.java:64)
	at com.jogamp.opengl.util.GLArrayDataClient.enableBuffer(GLArrayDataClient.java:207)
	at jogamp.graph.curve.opengl.VBORegionSPES2.drawImpl(VBORegionSPES2.java:129)
	at com.jogamp.graph.curve.opengl.GLRegion.draw(GLRegion.java:125)
	at jogamp.graph.curve.text.GlyphString.renderString3D(GlyphString.java:187)
	at jogamp.graph.curve.opengl.TextRendererImpl01.drawString3D(TextRendererImpl01.java:105)
	at simplebrowser.prototype.TestTextRendering.display(TestTextRendering.java:101)
	at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:583)
	at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:567)
	at javax.media.opengl.awt.GLCanvas$7.run(GLCanvas.java:1054)
	at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1029)
	at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:904)
	at javax.media.opengl.awt.GLCanvas$8.run(GLCanvas.java:1065)
	at javax.media.opengl.Threading.invoke(Threading.java:193)
	at javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:483)
	at javax.media.opengl.awt.GLCanvas.paint(GLCanvas.java:537)
	at javax.media.opengl.awt.GLCanvas.update(GLCanvas.java:719)
	at sun.awt.RepaintArea.updateComponent(RepaintArea.java:255)
	at sun.lwawt.LWRepaintArea.updateComponent(LWRepaintArea.java:42)
	at sun.awt.RepaintArea.paint(RepaintArea.java:232)
	at sun.lwawt.LWComponentPeer.handleJavaPaintEvent(LWComponentPeer.java:1277)
	at sun.lwawt.LWComponentPeer.handleEvent(LWComponentPeer.java:1165)
	at java.awt.Component.dispatchEventImpl(Component.java:4937)
	at java.awt.Component.dispatchEvent(Component.java:4687)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:729)
	at java.awt.EventQueue.access$200(EventQueue.java:103)
	at java.awt.EventQueue$3.run(EventQueue.java:688)
	at java.awt.EventQueue$3.run(EventQueue.java:686)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
	at java.awt.EventQueue$4.run(EventQueue.java:702)
	at java.awt.EventQueue$4.run(EventQueue.java:700)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:699)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

edit: remove extra source code link
Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer and VAOs

Rami Santina
Administrator
Hi, i see your using GLCanvas, please try using NewtCanvasAWT instead. 

As for region creation:
GlyphString glyphString = textRenderer.createString(gl, font, size, text);
GLRegion region = glyphString.createRegion(gl, 0);

Reply | Threaded
Open this post in threaded view
|

Re: TextRenderer and VAOs

JanBenes
Hi Rami & others

sorry for the very long response time, I was swamped with other, more pressing, tasks. To give you a context refresh - I was hoping to render text and had problems doing so because calling gl.glBindVertexArray after drawing text would always cause a crash.

Following your advice, I tried

1) Just changing to NewtCanvasAWT. I initialized my window/frame according to this post. The resulting file is here:TestTextRendering_v2.java. I still get exactly the same issues as with GLCanvas. To answer your question. I'm calling gl.glBindVertexArray(0); because it has the same effect as calling gl.glBindVertexArray(anActualIdOfMyOwnVertexArray). I hope that by resolving this issue in the MWE, I will also be able to resolve it in my application.
Exception in thread "main" javax.media.opengl.GLException: Thread[main,5,main] glGetError() returned the following error codes after a call to glGetVertexAttribiv(<int> 0x0, <int> 0x889F, <[I>, <int> 0x0): GL_INVALID_OPERATION ( 1282 0x502), 
	at javax.media.opengl.DebugGL3.checkGLGetError(DebugGL3.java:9753)
	at javax.media.opengl.DebugGL3.glGetVertexAttribiv(DebugGL3.java:8150)
	at javax.media.opengl.DebugGL3.glGetVertexAttribiv(DebugGL3.java:8144)
	at javax.media.opengl.DebugGL3.glGetVertexAttribiv(DebugGL3.java:8144)
	at jogamp.opengl.util.glsl.GLSLArrayHandler.enableShaderState(GLSLArrayHandler.java:101)
	at jogamp.opengl.util.glsl.GLSLArrayHandler.enableState(GLSLArrayHandler.java:64)
	at com.jogamp.opengl.util.GLArrayDataClient.enableBuffer(GLArrayDataClient.java:207)
	at jogamp.graph.curve.opengl.VBORegionSPES2.drawImpl(VBORegionSPES2.java:129)
	at com.jogamp.graph.curve.opengl.GLRegion.draw(GLRegion.java:125)
	at jogamp.graph.curve.text.GlyphString.renderString3D(GlyphString.java:187)
	at jogamp.graph.curve.opengl.TextRendererImpl01.drawString3D(TextRendererImpl01.java:105)
	at simplebrowser.prototype.TestTextRendering_v2.display(TestTextRendering_v2.java:110)
	at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:583)
	at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:567)
	at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:377)
	at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1029)
	at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:904)
	at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:593)
	at jogamp.opengl.GLAutoDrawableBase.defaultWindowResizedOp(GLAutoDrawableBase.java:222)
	at com.jogamp.newt.opengl.GLWindow.access$200(GLWindow.java:103)
	at com.jogamp.newt.opengl.GLWindow$2.windowResized(GLWindow.java:124)
	at jogamp.newt.WindowImpl.consumeWindowEvent(WindowImpl.java:2632)
	at jogamp.newt.WindowImpl.sendWindowEvent(WindowImpl.java:2570)
	at com.jogamp.newt.opengl.GLWindow.sendWindowEvent(GLWindow.java:674)
	at com.jogamp.newt.awt.NewtCanvasAWT.attachNewtChild(NewtCanvasAWT.java:589)
	at com.jogamp.newt.awt.NewtCanvasAWT.validateComponent(NewtCanvasAWT.java:501)
	at com.jogamp.newt.awt.NewtCanvasAWT.reshape(NewtCanvasAWT.java:439)
	at java.awt.Component.setBounds(Component.java:2243)
	at java.awt.BorderLayout.layoutContainer(BorderLayout.java:838)
	at java.awt.Container.layout(Container.java:1503)
	at java.awt.Container.doLayout(Container.java:1492)
	at java.awt.Container.validateTree(Container.java:1688)
	at java.awt.Container.validateTree(Container.java:1697)
	at java.awt.Container.validateTree(Container.java:1697)
	at java.awt.Container.validateTree(Container.java:1697)
	at java.awt.Container.validate(Container.java:1623)
	at java.awt.Container.validateUnconditionally(Container.java:1660)
	at java.awt.Window.pack(Window.java:818)
	at simplebrowser.prototype.TestTextRendering_v2.init2(TestTextRendering_v2.java:71)
	at simplebrowser.prototype.TestTextRendering_v2.main(TestTextRendering_v2.java:78)
2) Reconstructing a MWE from your snippets. I wonder if I went wrong somewhere (TestTextRendering_v3.java), but I'm getting the below listed exception (without ever calling the offending glBindVertexArray):

Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException
	at jogamp.newt.DefaultEDTUtil.invokeImpl(DefaultEDTUtil.java:220)
	at jogamp.newt.DefaultEDTUtil.invoke(DefaultEDTUtil.java:135)
	at jogamp.newt.DisplayImpl.runOnEDTIfAvail(DisplayImpl.java:221)
	at jogamp.newt.WindowImpl.runOnEDTIfAvail(WindowImpl.java:1724)
	at jogamp.newt.WindowImpl.setVisible(WindowImpl.java:885)
	at jogamp.newt.WindowImpl.setVisible(WindowImpl.java:890)
	at com.jogamp.newt.opengl.GLWindow.setVisible(GLWindow.java:417)
	at com.jogamp.newt.awt.NewtCanvasAWT.attachNewtChild(NewtCanvasAWT.java:587)
	at com.jogamp.newt.awt.NewtCanvasAWT.validateComponent(NewtCanvasAWT.java:501)
	at com.jogamp.newt.awt.NewtCanvasAWT.reshape(NewtCanvasAWT.java:439)
	at java.awt.Component.setBounds(Component.java:2243)
	at java.awt.BorderLayout.layoutContainer(BorderLayout.java:838)
	at java.awt.Container.layout(Container.java:1503)
	at java.awt.Container.doLayout(Container.java:1492)
	at java.awt.Container.validateTree(Container.java:1688)
	at java.awt.Container.validateTree(Container.java:1697)
	at java.awt.Container.validateTree(Container.java:1697)
	at java.awt.Container.validateTree(Container.java:1697)
	at java.awt.Container.validate(Container.java:1623)
	at java.awt.Container.validateUnconditionally(Container.java:1660)
	at java.awt.Window.show(Window.java:1033)
	at java.awt.Component.show(Component.java:1651)
	at java.awt.Component.setVisible(Component.java:1603)
	at java.awt.Window.setVisible(Window.java:1014)
	at simplebrowser.prototype.TestTextRendering_v3.init2(TestTextRendering_v3.java:74)
	at simplebrowser.prototype.TestTextRendering_v3.main(TestTextRendering_v3.java:80)
Caused by: java.lang.NullPointerException
	at simplebrowser.prototype.TestTextRendering_v3.display(TestTextRendering_v3.java:92)
	at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:583)
	at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:567)
	at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:377)
	at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1029)
	at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:904)
	at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:593)
	at jogamp.opengl.GLAutoDrawableBase.defaultWindowResizedOp(GLAutoDrawableBase.java:222)
	at com.jogamp.newt.opengl.GLWindow.access$200(GLWindow.java:103)
	at com.jogamp.newt.opengl.GLWindow$2.windowResized(GLWindow.java:124)
	at jogamp.newt.WindowImpl.consumeWindowEvent(WindowImpl.java:2632)
	at jogamp.newt.WindowImpl.sendWindowEvent(WindowImpl.java:2570)
	at jogamp.newt.WindowImpl.setVisibleActionImpl(WindowImpl.java:866)
	at jogamp.newt.WindowImpl$VisibleAction.run(WindowImpl.java:877)
	at com.jogamp.common.util.RunnableTask.run(RunnableTask.java:112)
	at jogamp.newt.DefaultEDTUtil$EventDispatchThread.run(DefaultEDTUtil.java:331)

Overall, I have had a really hard time finding out how to create a window that uses NewCanvasAWT (I also couldn't find the text demos in the demos repository) and I did manage to down the JVM several times in the process. I have spent tens of hours now trying to render text in my application (and constructing the MWE/finding out what the issue is) and really hope I can resolve this issue soon.

Could someone go ahead and run the the TestTextRendering_v2.java source and tell me if it works for them on a different machine? Any suggestions appreciated.

Thanks a lot!
J.