Hello, I'm trying to draw strings with variable color depending on time, but couldn't succeed. I think, I misunderstood something about opengl and jogl, so, do not judge me.
I've put everything into the simple code. <code> RenderState renderState; RegionRenderer renderer; TextRegionUtil textRegionUtil; public void init(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); RenderState renderState = RenderState.createRenderState(SVertex.factory()); regionRenderer = RegionRenderer.create(GraphicsGL.renderState, RegionRenderer.defaultBlendEnable, RegionRenderer.defaultBlendDisable); regionRenderer.init(gl, Region.MAX_QUALITY | Region.COLORCHANNEL_RENDERING_BIT); textRegionUtil = new TextRegionUtil(Region.MAX_QUALITY | Region.COLORCHANNEL_RENDERING_BIT); regionRenderer.enable(gl, true); regionRenderer.reshapeOrtho(width, height, 0.1f, 1000f); regionRenderer.enable(gl, false); gl.glClearDepth(1f); gl.glEnable(GL.GL_DEPTH_TEST); gl.glDepthFunc(GL.GL_LEQUAL); } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { GL2 gl = drawable.getGL().getGL2(); if (height == 0) height = 1; this.width = width; this.height = height; gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(0, Widget.BASE_WIDTH, 0, Widget.BASE_HEIGHT, -1, 1); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); regionRenderer.enable(gl, true); regionRenderer.reshapeOrtho(width, height, 0.1f, 1000.0f); regionRenderer.enable(gl, false); } public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); gl.glClearColor(1, 0, 1, 0); PMVMatrix pmv = GraphicsGL.renderState.getMatrix(); pmv.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); pmv.glLoadIdentity(); pmv.glTranslatef(0, 0, -300); Font font = null; try { font = FontFactory.getDefault().getDefault();//GraphicsGL.fonts.get("Open Sans Light"); } catch (IOException e) {} float pixelSize = font.getPixelSize(32, 96); // regionRenderer.enable(gl, true); textRegionUtil.drawString3D(gl, regionRenderer, font, pixelSize, "Test4", new float[] {1, 1, 1, 1}, new int[]{4}); // regionRenderer.enable(gl, false); } </code> I'm expecting from this code to draw me a purple background with white colored text in lower-bottom corner. The code, as it is, draws me a purple background but with black colored text. If I uncomment - the code doesn't draw any text. Also, I've tried unsuccessfully instead of creating TextRegionUtil: TextRegionUtil.drawString3D(gl, Region.MAX_QUALITY | Region.COLORCHANNEL_RENDERING_BIT, GraphicsGL.regionRenderer, font, pixelSize, "Test", new float[] {1, 1, 1, 1}, new int[] {4}, new AffineTransform(), new AffineTransform()); Again black text with comments and without - even black background. Could you help me with that? Unfortunately, setStaticColor is not an option, because I need to change the alpha of the string depending on time, while to renew static color I need to call textRegionUtil.clear(gl) or something like that. The last makes the background black instead of purple - and I don't know how to make gl together with textRegionUtil in this case. Thanks in advance. Vitaly Aksenov |
Take a look at this bug: https://jogamp.org/bugzilla/show_bug.cgi?id=1272
|
Thank you! I'll try to dig more or use renderModes=0.
AV |
Free forum by Nabble | Edit this page |