Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / JOGL Development / Smooth Scrolling text. on: 2012-06-05 21:36:38
Hello all,

I am writing a prompter that is supposed to scroll text as smoothly as possible. I have had some success, but how smoothly the text scrolls seems to vary in ways that I don't understand. I hope if I could understand why, I might be able to make it always scroll as smoothly as the smoothest that it scrolls now.

Currently, this is how I am doing it.
I wrap the text and draw one paragraph using the graphics from a BufferedImage (I used to use a TextRenderer and TextureRenderer but neither one of them are any faster: the problem isn't with drawing it to a texture, but with drawing the texture). Then I create a call list for each paragraph to draw its texture. Then I make a call list for calling each of these call lists that fit on the screen.

I would be happy to post more of my code, but I am not sure which parts will be the most helpful.

Here is how I create texture (Do not concern yourself with using the BufferedImage first, I will explain that):
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
      BufferedImage image = new BufferedImage(size.width, (int) height, BufferedImage.TYPE_INT_RGB);
      Graphics2D graphics = (Graphics2D) image.getGraphics();

      graphics.fillRect(...);

      for (Line line : lines) {
         ArrayList<TextLayout> layouts = line.layouts;
         ArrayList<Float> horizontalPoses = line.horizontalPoses;
         for (int i = 0; i < layouts.size(); i++) {
            layouts.get(i).draw(graphics, horizontalPoses.get(i),
                  line.ypos);
         }
      }

      //Texture paragraph = tr.getTexture();
     int w = (int) (settings.getScaleFactor() * size.width);
      int h = (int) (settings.getScaleFactor() * height);

      BufferedImage resized = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
      resized.getGraphics().drawImage(image, 0, 0, w, h, null);
      Texture paragraph = AWTTextureIO.newTexture(gl.profile, resized, true);

      paragraph.setTexParameteri(gl.gl, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
      paragraph.setTexParameteri(gl.gl, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
      paragraph.setTexParameteri(gl.gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
      paragraph.setTexParameteri(gl.gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);



Here is how I create the paragraph call list:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
      float y2 = -2 * height / size.height; // multiply by scale here?

      if (texture.getMustFlipVertically()) {
         float tmp = y1;
         y1 = y2;
         y2 = tmp;
      }

      gl.gl.glNewList(displayLists.get(gl), GL2.GL_COMPILE);
      texture.bind(gl.gl);
      gl.gl.glBegin(GL2.GL_QUADS);
      {
         gl.gl.glTexCoord2d(0.0, 0.0);
         gl.gl.glVertex2f(x1, y2);
         gl.gl.glTexCoord2d(1.0, 0.0);
         gl.gl.glVertex2f(x2, y2);
         gl.gl.glTexCoord2d(1.0, 1.0);
         gl.gl.glVertex2f(x2, y1);
         gl.gl.glTexCoord2d(0.0, 1.0);
         gl.gl.glVertex2f(x1, y1);
      }
      gl.gl.glEnd();
      gl.gl.glEndList();

Here is what I run inside of my animator's display call:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
            gl.glTranslatef(...);

            if (prevBegin == startIndex && prevEnd == endIndex && call) {
               gl.glCallList(curList);
            } else {
               prevBegin = startIndex;
               prevEnd = endIndex;
               gl.glNewList(curList, GL2.GL_COMPILE_AND_EXECUTE);
               gl.glClear(GL.GL_COLOR_BUFFER_BIT);

               int indx = startIndex;
               for (;;) {
                  Drawable d = rr.get(indx);
// this is a call to
//      gl.glCallList(displayList); with the Drawable's displayList
                 draw(gl, d);

                  if (endIndex < ++indx) {
                     break;
                  }
                  gl.glTranslatef(0f, -2 * d.getHeight() / getHeight(), 0);
               }

               gl.glLoadIdentity();
               gl.glEndList();
               call = true;
            }

            if (cloneView != null) {
               cloneView.display();
            }


I create a BufferedImage first because I was experimenting with resizing the texture to save space: but this did very little for me.

Using call lists doesn't make it one bit smoother. I enable double buffering, and set the vertical refresh rate to fix the tearing. The problem is that on my computer the cloneView (which is another GLCanvas that shares the textures from the main canvas) is MUCH smoother than the main prompter. It doesn't matter if call lists are enabled on either canvas, or if I apply an extra transformation (like rotating the text upside down). However, if I use a different animator (instead of calling the the main cloneView's display() method while inside the main prompter's display(gl)), then they are both slow.

Unfortunately, that is only on my computer: even on much nicer computers, both canvases are jerky (jerky as in make large jumps in when scrolling). I have asked for help on here before, and I received many warm-hearted suggestions (Thanks!) but none of them have smoothed the scrolling. If somebody can think of some variable that would be affecting the smoothness, it would help a lot! I can clarify anything that doesn't make sense.
2  Java Game APIs & Engines / OpenGL Development / Re: How to smooth scroll text? on: 2012-01-12 19:36:16
Yes, I am very to new to JOGL and graphics programming, and honestly hate asking questions out of line. Before I give up though, there is one thing I should know that is obvious to you and would greatly help my understanding.

My understanding of glTranstate() is that I have to call it so that I am in the proper position BEFORE I draw my quad (using gl.begin(GL2.GL_QUADS)). From your posts in almost seems like your saying I can translate a quad without using gl.begin/gl.end. That I only have to call my gl.begin(GL2.GL_QUADS)/gl.end once, and then by calling glTranslate() to translate my quad. If this is the case, then could you point me at a method in the javadoc/example of somebody doing this? ( GLUquadric would seem to be the only thing in the documentation that I can think that might be able to "remember" a quad, but it doesn't seem quite what I am looking for.)

Otherwise, thanks for everything you've helped me with! In that case, will be stuck continually binding a texture to my gl, and then using the gl do draw a quad for each tile(/character eventually).

Again, thanks for your patience and helping a poor noob!
3  Java Game APIs & Engines / OpenGL Development / Re: How to smooth scroll text? on: 2012-01-12 17:51:39
First of all, I see JOGL has its own section in this forum, so I should have put this in there. Sorry.

I am pretty sure I do have to clear the screen every time a tile "moves", but not calling clear before drawing the tile does help. It is still not smooth enough though, I guess the only thing I can thing of left is to create textures for each character instead of each tile, and to make display lists for the tiles.

I don't understand what you mean by translating/rotating the quads instead of updating the texture. I will call translate and rotate to be in the right position to draw the quad containing the texture, but I sill have to bind the texture to the gl each time. If you mean my calls:

1  
2  
3  
4  
      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);


then yes, that was easy to just move into the section where I create the tile, so it is only called once.

Thanks for your patience!
4  Java Game APIs & Engines / OpenGL Development / Re: How to smooth scroll text? on: 2012-01-11 22:07:59
Thanks again!

That makes sense, as long as I understand properly.

Yes, I was calling glClear for each tile. Absent-mindedly, I had thought I was only clearing the region the next vertex quad was going to take up. (That explains why I was only displaying one tile at a time!") I will have to figure out how to "remember" or "save" the quad that I draw so that I only have to call gl_translate each draw instead of drawing a whole new one. (My best guess is that this will be done for me if I just don't clear the screen. Maybe all I have to do is call gl_translate! Back to google...) I hadn't realized that I was updating the texture each time I was binding it to the gl.
 
No! There is no reason I wasn't making a texture for each character, I had assumed it would be best to make the texture as big as possible so that as much work was being done "under the hood" as possible. (The first thing I did when I was in Graphics2D was to render the whole text document at once, and I only decided to break it up into tiles after it took to long to resize.) As soon as I figure out how to only translate the quad I will fix this too.

Yes, I have had several demos: first using Graphics2D and drawing each line, then drawing Tiles with BufferedImages, then JOGL with a TextRenderer, and the the TextureRenderer was my last attempt. I could see the text and everything, but it looked very clearly wrong.

Wow, thanks so much! I have no idea how many examples and javadoc pages I would have read through before tying to simply translate the quad. One of the examples I was building from was the one on Wikipedia (which calls gl.glBegin(GL2.GL_QUADS)/gl.glEnd every time draw is called).

Again I just can't thank you enough: I feel like I have hope again!
5  Java Game APIs & Engines / OpenGL Development / Re: How to smooth scroll text? on: 2012-01-11 20:37:33
Thanks for the response lhkbob!

Sorry, I was not being clear. (sometimes I develop my own terminology that conflicts with others!) I use a TextureRenderer to "render" each texture when it comes on the screen, and then I save the texture. From that time on (until the window resizes), I draw that same texture using the first code snippet.

Is that what I should do, or is there a way to "move" a texture without drawing it (using the GL_QUADS) over again? What that way be more smooth than what I am doing?

Thanks again!
6  Java Game APIs & Engines / OpenGL Development / Re: How to smooth scroll text? on: 2012-01-11 17:59:32
I did mean to say that I create a TextureRenderer for each tile instead of TextRenderer. If it helps, my code for that is:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
      renderer = new TextureRenderer(width,height,false);
      Graphics2D graphics = renderer.createGraphics();
      graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
     
      Settings settings = Settings.getInstance();
      graphics.setColor(settings.getBackgroundColor());
      graphics.fillRect(0,0,width,height);
      graphics.setColor(settings.getForegroundColor());
      if(!isBlank) {
         ArrayList<RenderedItem> ris = getItems();
         
         float offset = ...;
         for(int i=0;i<size;i++) {
// this makes a call to draw on a TextLayout object
           ris.get(i).draw(graphics, offset);
            offset += ris.get(i).getHeight();
         }
      }
      graphics.dispose();
//      renderer.markDirty(0,0,width,height);
     return renderer.getTexture();
7  Java Game APIs & Engines / OpenGL Development / How to smooth scroll text? on: 2012-01-11 17:03:55
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:


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
      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:

1  
2  
3  
      // 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:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
      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!

Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

BurntPizza (24 views)
2014-09-19 03:14:18

Dwinin (39 views)
2014-09-12 09:08:26

Norakomi (67 views)
2014-09-10 13:57:51

TehJavaDev (93 views)
2014-09-10 06:39:09

Tekkerue (47 views)
2014-09-09 02:24:56

mitcheeb (68 views)
2014-09-08 06:06:29

BurntPizza (51 views)
2014-09-07 01:13:42

Longarmx (38 views)
2014-09-07 01:12:14

Longarmx (44 views)
2014-09-07 01:11:22

Longarmx (40 views)
2014-09-07 01:10:19
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!