Error in opengl: stack underflow
Forum rules
Developer discussions only. Newbie questions belong in the HELP! forum. This is a forum for discussing development work on the Ardor3D core systems. Basically, anything that is in the ardor3d-core, math or savable modules.
Developer discussions only. Newbie questions belong in the HELP! forum. This is a forum for discussing development work on the Ardor3D core systems. Basically, anything that is in the ardor3d-core, math or savable modules.
26 posts
• Page 3 of 3 • 1, 2, 3
Re: Error in opengl: stack underflow
Hi,
It looks like I've same issues (it works fine with LWJGL)
Using GLDebug I've got following stack trace :
I tried to modify Mesh.java code according to gouessej previous instructions, but it's neither good.
Without code modifications the exception is thrown after a random amount of time (40 sec at my last try), with the code modification it is thrown at the beginning.
Here is my code
Is the patch ok ? If so where is it and how to use it ? (
)
It looks like I've same issues (it works fine with LWJGL)
Using GLDebug I've got following stack trace :
- Code: Select all
javax.media.opengl.GLException: glGetError() returned the following error codes after a call to glPopMatrix(): GL_STACK_UNDERFLOW
at javax.media.opengl.DebugGL.checkGLGetError(DebugGL.java:12715)
at javax.media.opengl.DebugGL.glPopMatrix(DebugGL.java:6774)
at com.ardor3d.renderer.jogl.JoglRenderer.undoTransforms(JoglRenderer.java:659)
at com.ardor3d.scenegraph.Mesh.render(Mesh.java:295)
at com.ardor3d.scenegraph.Mesh.render(Mesh.java:243)
at com.ardor3d.renderer.jogl.JoglRenderer.draw(JoglRenderer.java:630)
at com.ardor3d.scenegraph.Mesh.draw(Mesh.java:434)
at com.ardor3d.renderer.queue.AbstractRenderBucket.render(AbstractRenderBucket.java:75)
at com.ardor3d.renderer.queue.RenderQueue.renderBuckets(RenderQueue.java:117)
at com.ardor3d.renderer.jogl.JoglRenderer.renderBuckets(JoglRenderer.java:134)
at com.ardor3d.renderer.jogl.JoglRenderer.renderBuckets(JoglRenderer.java:127)
at com.ardor3d.renderer.jogl.JoglRenderer.flushFrame(JoglRenderer.java:212)
at com.ardor3d.framework.jogl.JoglCanvasRenderer.draw(JoglCanvasRenderer.java:208)
at com.ardor3d.framework.jogl.JoglAwtCanvas.draw(JoglAwtCanvas.java:60)
at com.ardor3d.framework.jogl.JoglCanvas.draw(JoglCanvas.java:234)
at com.ardor3d.framework.FrameHandler.updateFrame(FrameHandler.java:90)
at com.ardor3d.example.ExampleBase.run(ExampleBase.java:147)
at java.lang.Thread.run(Unknown Source)
I tried to modify Mesh.java code according to gouessej previous instructions, but it's neither good.
Without code modifications the exception is thrown after a random amount of time (40 sec at my last try), with the code modification it is thrown at the beginning.
Here is my code
- Code: Select all
/**
* Copyright (c) 2008-2011 Ardor Labs, Inc.
*
* This file is part of Ardor3D.
*
* Ardor3D is free software: you can redistribute it and/or modify it
* under the terms of its license which may be found in the accompanying
* LICENSE file or at <http://www.ardor3d.com/LICENSE>.
*/
package com.ardor3d.example.basic;
import com.ardor3d.example.ExampleBase;
import com.ardor3d.example.Purpose;
import com.ardor3d.framework.Canvas;
import com.ardor3d.image.Texture;
import com.ardor3d.input.Key;
import com.ardor3d.input.logical.InputTrigger;
import com.ardor3d.input.logical.KeyPressedCondition;
import com.ardor3d.input.logical.TriggerAction;
import com.ardor3d.input.logical.TwoInputStates;
import com.ardor3d.math.ColorRGBA;
import com.ardor3d.math.MathUtils;
import com.ardor3d.math.Matrix3;
import com.ardor3d.math.Vector3;
import com.ardor3d.renderer.Renderer;
import com.ardor3d.renderer.state.ColorMaskState;
import com.ardor3d.renderer.state.LightState;
import com.ardor3d.renderer.state.MaterialState;
import com.ardor3d.renderer.state.MaterialState.ColorMaterial;
import com.ardor3d.renderer.state.StencilState;
import com.ardor3d.renderer.state.StencilState.StencilFunction;
import com.ardor3d.renderer.state.StencilState.StencilOperation;
import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.scenegraph.Mesh;
import com.ardor3d.scenegraph.shape.Box;
import com.ardor3d.util.ReadOnlyTimer;
import com.ardor3d.util.TextureManager;
/**
* A simple example showing a textured and lit box spinning.
*/
@Purpose(htmlDescriptionKey = "com.ardor3d.example.basic.BoxExample", //
thumbnailPath = "com/ardor3d/example/media/thumbnails/basic_BoxExample.jpg", //
maxHeapMemory = 64)
public class BoxStencilTest extends ExampleBase {
/** Keep a reference to the box to be able to rotate it each frame. */
private Mesh small, small2, big;
private StencilState ssQ2;
private ColorMaskState cmsQ1;
private TextureState ts;
/** Rotation matrix for the spinning box. */
private final Matrix3 rotate = new Matrix3();
/** Angle of rotation for the box. */
private double angle = 0;
/** Axis to rotate the box around. */
private final Vector3 axis = new Vector3(1, 1, 0.5f).normalizeLocal();
public static void main(final String[] args) {
_minStencilBits = 8;
start(BoxStencilTest.class);
}
@Override
protected void updateExample(final ReadOnlyTimer timer) {
// Update the angle using the current tpf to rotate at a constant speed.
angle += timer.getTimePerFrame() * 50;
// Wrap the angle to keep it inside 0-360 range
angle %= 360;
// Update the rotation matrix using the angle and rotation axis.
rotate.fromAngleNormalAxis(angle * MathUtils.DEG_TO_RAD, axis);
// Update the box rotation using the rotation matrix.
small.setRotation(rotate);
small2.setRotation(rotate);
big.setRotation(rotate);
}
@Override
protected void initExample() {
_canvas.getCanvasRenderer().setFrameClear(Renderer.BUFFER_COLOR_AND_DEPTH | Renderer.BUFFER_STENCIL);
_canvas.setTitle("Stencil Example");
// Create a new box centered at (0,0,0) with width/height/depth of size 10.
small = new Box("Box", new Vector3(0, 0, 0), 5, 5, 5);
small2 = new Box("Box", new Vector3(0, 0, 0), 5, 5, 5);
// small = new Quad("Quad", 3, 3);
big = new Box("Box", new Vector3(0, 0, 0), 6, 6, 6);
// big = new Quad("Quad", 6, 7);
// big.setTranslation(new Vector3(1, 1, 1));
final MaterialState ms = new MaterialState();
ms.setColorMaterial(ColorMaterial.Diffuse);
small.setRenderState(ms);
small2.setRenderState(ms);
big.setRenderState(ms);
// Give the box some nice colors.
small.setSolidColor(new ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f));
big.setSolidColor(new ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f));
// big.setSolidColor(new ColorRGBA(0.0f, 0.0f, 1.0f, 1.0f));
// Add a texture to the box.
ts = new TextureState();
ts.setTexture(TextureManager.load("images/ardor3d_white_256.jpg", Texture.MinificationFilter.Trilinear, true));
small2.setRenderState(ts);
_root.attachChild(small2);
_root.attachChild(big);
_root.attachChild(small);
cmsQ1 = new ColorMaskState();
cmsQ1.setEnabled(true);
cmsQ1.setAll(false);
small.setRenderState(cmsQ1);
final StencilState ssQ1 = new StencilState();
ssQ1.setStencilFunction(StencilFunction.Always);
ssQ1.setStencilReference(0x1);
ssQ1.setStencilFuncMask(0x1);
ssQ1.setStencilOpFail(StencilOperation.Replace);
ssQ1.setStencilOpZFail(StencilOperation.Replace);
ssQ1.setStencilOpZPass(StencilOperation.Replace);
small.setRenderState(ssQ1);
ssQ2 = new StencilState();
ssQ2.setStencilFunction(StencilFunction.EqualTo);
ssQ2.setStencilReference(0x0);
ssQ2.setStencilFuncMask(0x1);
ssQ2.setStencilOpFail(StencilOperation.Keep);
ssQ2.setStencilOpZFail(StencilOperation.Keep);
ssQ2.setStencilOpZPass(StencilOperation.Keep);
big.setRenderState(ssQ2);
final LightState ls = new LightState();
// ls.setLightMask(LightState.MASK_AMBIENT | LightState.MASK_DIFFUSE);
ls.setLightMask(LightState.MASK_GLOBALAMBIENT);
big.setRenderState(ls);
_logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.SPACE), new TriggerAction() {
public void perform(final Canvas source, final TwoInputStates inputState, final double tpf) {
// cmsQ1.setEnabled(!cmsQ1.isEnabled());
// ssQ2.setEnabled(!ssQ2.isEnabled());
ts.setEnabled(!ts.isEnabled());
}
}));
}
}
Is the patch ok ? If so where is it and how to use it ? (
- Bobza
- newcomer
- Posts: 43
- Joined: Tue Feb 21, 2012 4:29 am
Re: Error in opengl: stack underflow
Are you up to date with svn trunk (which has his patch already)? I don't have any issues running your code in jogl with the latest trunk.
Also, your example needs to ensure that the smaller box that has a stencil state gets rendered before the big box. You also have another box with a texture that does not have a stencil state at all, so it will ignore stencil. One way you can control render order by setting root's scenehint's renderbucket type to Skip. The scene graph is then rendered as it traverses the nodes, rendering the children of nodes from the most recently added, back. (LIFO) The default render bucket type is Opaque, which means we gather up the spatials and then sort them according to various properties before finally rendering them. This is usually most efficient as it batches together items with the same textures, etc., but in your case with the stencil, it's not what you need.
Hope that helps. Here's a tweak of your code that makes the big box slightly transparent so you can see inside it. It also grows the textured box a bit so it doesn't directly overlap the stenciled box (but is still smaller than the big box). I also added the big box's stencil state to the textured box. Finally, it changes the bucket type to skip and reorders the draw calls so everything renders properly.
Keep in mind that ordering matters for a few reasons. First, you need your stencil to draw first to get the stencil value into the buffer. Second, all of the boxes are inheriting a zstate that blocks writing if there's a z value already in the buffer that's <= the z of the item you are drawing. So if for example, you draw the big red box first and then the textured box, you won't see the textured box because its z value is larger than the big red box.
Hope that helps!
Also, your example needs to ensure that the smaller box that has a stencil state gets rendered before the big box. You also have another box with a texture that does not have a stencil state at all, so it will ignore stencil. One way you can control render order by setting root's scenehint's renderbucket type to Skip. The scene graph is then rendered as it traverses the nodes, rendering the children of nodes from the most recently added, back. (LIFO) The default render bucket type is Opaque, which means we gather up the spatials and then sort them according to various properties before finally rendering them. This is usually most efficient as it batches together items with the same textures, etc., but in your case with the stencil, it's not what you need.
Hope that helps. Here's a tweak of your code that makes the big box slightly transparent so you can see inside it. It also grows the textured box a bit so it doesn't directly overlap the stenciled box (but is still smaller than the big box). I also added the big box's stencil state to the textured box. Finally, it changes the bucket type to skip and reorders the draw calls so everything renders properly.
- Code: Select all
/**
* Copyright (c) 2008-2011 Ardor Labs, Inc.
*
* This file is part of Ardor3D.
*
* Ardor3D is free software: you can redistribute it and/or modify it
* under the terms of its license which may be found in the accompanying
* LICENSE file or at <http://www.ardor3d.com/LICENSE>.
*/
package com.ardor3d.example.basic;
import com.ardor3d.example.ExampleBase;
import com.ardor3d.example.Purpose;
import com.ardor3d.framework.Canvas;
import com.ardor3d.image.Texture;
import com.ardor3d.input.Key;
import com.ardor3d.input.logical.InputTrigger;
import com.ardor3d.input.logical.KeyPressedCondition;
import com.ardor3d.input.logical.TriggerAction;
import com.ardor3d.input.logical.TwoInputStates;
import com.ardor3d.math.ColorRGBA;
import com.ardor3d.math.MathUtils;
import com.ardor3d.math.Matrix3;
import com.ardor3d.math.Vector3;
import com.ardor3d.renderer.Renderer;
import com.ardor3d.renderer.queue.RenderBucketType;
import com.ardor3d.renderer.state.BlendState;
import com.ardor3d.renderer.state.ColorMaskState;
import com.ardor3d.renderer.state.LightState;
import com.ardor3d.renderer.state.MaterialState;
import com.ardor3d.renderer.state.StencilState;
import com.ardor3d.renderer.state.TextureState;
import com.ardor3d.renderer.state.BlendState.DestinationFunction;
import com.ardor3d.renderer.state.BlendState.SourceFunction;
import com.ardor3d.renderer.state.MaterialState.ColorMaterial;
import com.ardor3d.renderer.state.StencilState.StencilFunction;
import com.ardor3d.renderer.state.StencilState.StencilOperation;
import com.ardor3d.scenegraph.Mesh;
import com.ardor3d.scenegraph.shape.Box;
import com.ardor3d.util.ReadOnlyTimer;
import com.ardor3d.util.TextureManager;
/**
* A simple example showing a textured and lit box spinning.
*/
@Purpose(htmlDescriptionKey = "com.ardor3d.example.basic.BoxExample", //
thumbnailPath = "com/ardor3d/example/media/thumbnails/basic_BoxExample.jpg", //
maxHeapMemory = 64)
public class BoxStencilTest extends ExampleBase {
/** Keep a reference to the box to be able to rotate it each frame. */
private Mesh small, small2, big;
private StencilState ssQ2;
private ColorMaskState cmsQ1;
private TextureState ts;
/** Rotation matrix for the spinning box. */
private final Matrix3 rotate = new Matrix3();
/** Angle of rotation for the box. */
private double angle = 0;
/** Axis to rotate the box around. */
private final Vector3 axis = new Vector3(1, 1, 0.5f).normalizeLocal();
public static void main(final String[] args) {
_minStencilBits = 8;
start(BoxStencilTest.class);
}
@Override
protected void updateExample(final ReadOnlyTimer timer) {
// Update the angle using the current tpf to rotate at a constant speed.
angle += timer.getTimePerFrame() * 50;
// Wrap the angle to keep it inside 0-360 range
angle %= 360;
// Update the rotation matrix using the angle and rotation axis.
rotate.fromAngleNormalAxis(angle * MathUtils.DEG_TO_RAD, axis);
// Update the box rotation using the rotation matrix.
small.setRotation(rotate);
small2.setRotation(rotate);
big.setRotation(rotate);
}
@Override
protected void initExample() {
_canvas.getCanvasRenderer().setFrameClear(Renderer.BUFFER_COLOR_AND_DEPTH | Renderer.BUFFER_STENCIL);
_canvas.setTitle("Stencil Example");
// Create a new box centered at (0,0,0) with width/height/depth of size 10.
small = new Box("Box", new Vector3(0, 0, 0), 5, 5, 5);
small2 = new Box("Box", new Vector3(0, 0, 0), 5.5, 5.5, 5.5);
// small = new Quad("Quad", 3, 3);
big = new Box("Box", new Vector3(0, 0, 0), 6, 6, 6);
// big = new Quad("Quad", 6, 7);
// big.setTranslation(new Vector3(1, 1, 1));
final MaterialState ms = new MaterialState();
ms.setColorMaterial(ColorMaterial.Diffuse);
small.setRenderState(ms);
small2.setRenderState(ms);
big.setRenderState(ms);
// Give the box some nice colors.
small.setSolidColor(new ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f));
big.setSolidColor(new ColorRGBA(1.0f, 0.0f, 0.0f, .5f));
// big.setSolidColor(new ColorRGBA(0.0f, 0.0f, 1.0f, 1.0f));
// Add a texture to the box.
ts = new TextureState();
ts.setTexture(TextureManager.load("images/ardor3d_white_256.jpg", Texture.MinificationFilter.Trilinear, true));
small2.setRenderState(ts);
_root.getSceneHints().setRenderBucketType(RenderBucketType.Skip);
_root.attachChild(big);
_root.attachChild(small2);
_root.attachChild(small);
final BlendState bs = new BlendState();
bs.setSourceFunction(SourceFunction.SourceAlpha);
bs.setDestinationFunction(DestinationFunction.OneMinusSourceAlpha);
bs.setBlendEnabled(true);
big.setRenderState(bs);
cmsQ1 = new ColorMaskState();
cmsQ1.setEnabled(true);
cmsQ1.setAll(false);
small.setRenderState(cmsQ1);
final StencilState ssQ1 = new StencilState();
ssQ1.setStencilFunction(StencilFunction.Always);
ssQ1.setStencilReference(0x1);
ssQ1.setStencilMask(0x1);
ssQ1.setStencilOpFail(StencilOperation.Replace);
ssQ1.setStencilOpZFail(StencilOperation.Replace);
ssQ1.setStencilOpZPass(StencilOperation.Replace);
small.setRenderState(ssQ1);
ssQ2 = new StencilState();
ssQ2.setStencilFunction(StencilFunction.EqualTo);
ssQ2.setStencilReference(0x0);
ssQ2.setStencilFuncMask(0x1);
ssQ2.setStencilOpFail(StencilOperation.Keep);
ssQ2.setStencilOpZFail(StencilOperation.Keep);
ssQ2.setStencilOpZPass(StencilOperation.Keep);
big.setRenderState(ssQ2);
small2.setRenderState(ssQ2);
final LightState ls = new LightState();
// ls.setLightMask(LightState.MASK_AMBIENT | LightState.MASK_DIFFUSE);
ls.setLightMask(LightState.MASK_GLOBALAMBIENT);
big.setRenderState(ls);
_logicalLayer.registerTrigger(new InputTrigger(new KeyPressedCondition(Key.SPACE), new TriggerAction() {
public void perform(final Canvas source, final TwoInputStates inputState, final double tpf) {
// cmsQ1.setEnabled(!cmsQ1.isEnabled());
// ssQ2.setEnabled(!ssQ2.isEnabled());
ts.setEnabled(!ts.isEnabled());
}
}));
}
}
Keep in mind that ordering matters for a few reasons. First, you need your stencil to draw first to get the stencil value into the buffer. Second, all of the boxes are inheriting a zstate that blocks writing if there's a z value already in the buffer that's <= the z of the item you are drawing. So if for example, you draw the big red box first and then the textured box, you won't see the textured box because its z value is larger than the big red box.
Hope that helps!
Gratitude is a mark of a noble soul and a refined character.
-

renanse - Site Admin
- Posts: 2955
- Joined: Tue Oct 28, 2008 6:49 pm
- Location: Austin, TX
Re: Error in opengl: stack underflow
Thanks a lot renanse !
This is a really usefull post for me.
I actually was not up to date with the svn trunk. I did it and it's ok now
(I swet a bit having a "Can't load AMD 64-bit .dll on a IA 32-bit platform" exception. It looks like the native library location of the jogl.jar file is set "by default" to the amd64 dll on the .classpath file that is on the repositery. This is a little confusing when you're not very used to A3D.
Concerning the rendering order, I knew it's important. I assumed order was done in a LIFO style. I planned to use nodes for further ordering. My final scene should contain :
- opaque meshes
- slight transparent meshes (far to near ordered)
- overlined mesh.
I planned to use a node for each "group", so that rendering order is done correctly : first opaque, second slight transparent, last overlined.
I will have to reconsider all this with your scenebucket type explanation : I guess I will have to define scenebucket type at node levels.
Your post also cleared BlendState things that I planned to use, and didn't know yet how to !
Thanks a lot, really !
Another thing I can't succeed is the lighting of the big box ; I intended to deactivate it (glDisable(GL.GL_LIGHTING) , so that it is rendered with an uniform red color.
As you can see in following pic, external red bounder color is different between top, side and down sides. Disabling lighting should make the trick, but I can't succeed ; maybe some lightmask issue ?

(don't know what's wrong with this url
) http://www.hostingpics.net/viewer.php?id=557989shot.png
I searched for the glDisable(GL.GL_LIGHTING) code in the jogl Renderer ; it looked weird to me the way it's called....
This is a really usefull post for me.
I actually was not up to date with the svn trunk. I did it and it's ok now
(I swet a bit having a "Can't load AMD 64-bit .dll on a IA 32-bit platform" exception. It looks like the native library location of the jogl.jar file is set "by default" to the amd64 dll on the .classpath file that is on the repositery. This is a little confusing when you're not very used to A3D.
Concerning the rendering order, I knew it's important. I assumed order was done in a LIFO style. I planned to use nodes for further ordering. My final scene should contain :
- opaque meshes
- slight transparent meshes (far to near ordered)
- overlined mesh.
I planned to use a node for each "group", so that rendering order is done correctly : first opaque, second slight transparent, last overlined.
I will have to reconsider all this with your scenebucket type explanation : I guess I will have to define scenebucket type at node levels.
Your post also cleared BlendState things that I planned to use, and didn't know yet how to !
Thanks a lot, really !
Another thing I can't succeed is the lighting of the big box ; I intended to deactivate it (glDisable(GL.GL_LIGHTING) , so that it is rendered with an uniform red color.
As you can see in following pic, external red bounder color is different between top, side and down sides. Disabling lighting should make the trick, but I can't succeed ; maybe some lightmask issue ?

(don't know what's wrong with this url
I searched for the glDisable(GL.GL_LIGHTING) code in the jogl Renderer ; it looked weird to me the way it's called....
- Bobza
- newcomer
- Posts: 43
- Joined: Tue Feb 21, 2012 4:29 am
Re: Error in opengl: stack underflow
You can disable lighting on a particular Spatial by setting LightCombineMode to Off in its SceneHints.
Gratitude is a mark of a noble soul and a refined character.
-

renanse - Site Admin
- Posts: 2955
- Joined: Tue Oct 28, 2008 6:49 pm
- Location: Austin, TX
Re: Error in opengl: stack underflow
This works fine.
Thanks a lot.
Thanks a lot.
- Bobza
- newcomer
- Posts: 43
- Joined: Tue Feb 21, 2012 4:29 am
Re: Error in opengl: stack underflow
... the native library location does not need to be set when using the JOGL 2.0 renderer, JOGL 2.0 is smart enough to detect your architecture and load the proper native libraries without any hint.
- gouessej
- regular
- Posts: 1186
- Joined: Fri May 01, 2009 3:26 am
- Location: France
26 posts
• Page 3 of 3 • 1, 2, 3
Return to Core Development Discussions
Who is online
Users browsing this forum: No registered users and 0 guests