Hello,
I am new to JOGL, so forgive me if this should have been posted in the newbie section or I am missing something very dumb. However, I have been stuck on this for several days now.
I am trying to develop an application that provides ultra-smooth text scrolling in Java. In order to achieve this I have been trying to use JOGL from examples I have found on the internet, but with only minimal luck. The canvas continually flickers, and moves my GL_QUADS (or texture, idk) even when I am not calling the redraw method of my GLCanvas. I don’t know how to describe it well, but image is very jerky. When I had a similar problem with Graphics2D, using a frame buffer helped. I have found some sites that say (atleast on windows, but I am using linux) that you have to disable the awt erasing:
System.setProperty(“sun.awt.noerasebackground”, “true”);
but that does not work for me. I have also tried setting the noddraw, and that doesn’t work. What is worse is that not all the lines of text in the same texture seem to move at the same rate (even though they are being rendered from the same tile). This was the problem with simply using a TextRenderer, making that option infeasable.
Basically, I break up the text I want to scroll, and create a TextRenderer for each section (I call them a “Tile”) and use its graphics2D to draw the pieces of text. Then when each tile comes into view, I want to draw the textures with jogl. That way I don’t have to draw the whole document at once. My GLCanvas then draws each of the tiles using the following method:
GL2 gl = canvas.getGL().getGL2();
texture.setTexParameteri(gl,GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
texture.setTexParameteri(gl,GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);
texture.setTexParameteri(gl,GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
texture.setTexParameteri(gl,GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
float startY = ...;
float endY = ...;
texture.bind(gl);
//gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE);
gl.glClear(GL2.GL_COLOR_BUFFER_BIT); //use the clear color we set
/* I can't make this code work, but I doubt it would be any better.
renderer.beginOrthoRendering(,);
renderer.drawOrthoRect(,);
renderer.endOrthoRendering();*/
gl.glBegin(GL2.GL_QUADS);
{
gl.glTexCoord2d(0.0, 0.0);
gl.glVertex2d(0.0f, startY);
gl.glTexCoord2d(1.0, 0.0);
gl.glVertex2d(1.0f, startY);
gl.glTexCoord2d(1.0, 1.0);
gl.glVertex2d(1.0f, endY);
gl.glTexCoord2d(0.0, 1.0);
gl.glVertex2d(0.0f, endY);
}
gl.glEnd();
After calling this for each of the Textures, I run:
// glad is the GLAutoDrawable
glad.getGL().getGL2().glFlush();
glad.swapBuffers();
Those lines don’t seem to make any difference. My initialization code is as follows:
GLCapabilities caps = new GLCapabilities(getGLProfile());
caps.setDoubleBuffered(true);
caps.setHardwareAccelerated(true);
GL2 gl = glad.getGL().getGL2();
// Clearing screen color
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
// this is where to flip the image, etc.
gl.glOrtho(0, 1, 0, 1, -1, 1);
Is it possible to smooth scroll in jogl? Should I be using something aside from textures like bitmaps? Should I always use the same quad but scroll the texture over it? Would compiling help? Do you have any other tips/ideas? I guess part of the question is also just, “What tools would you use to develop the smoothest scrolling application you could?”
Thanks in advance!