Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (532)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [small fonts] need help [/small fonts]  (Read 1728 times)
0 Members and 1 Guest are viewing this topic.
Offline Java Cool Dude

Senior Member




Java forever


« Posted 2003-10-21 09:03:59 »

Psssst, something is not quite right with this pic

If you didn't guess it at this point, well let me explain: That's a terrain mesh generated by two 196*196 pictures and passed to the hardware as a vertex array.
Well it's working, but the performance is horrible and I have few doubts regarding my code.
Anyways, this is the source (very short), now could someone help me out establishing why the performance is crawling so bad?
Cough*how do I make it work with Triangle strips instead of triangles? *cough
Offline quintesse

Junior Member




Java games rock!


« Reply #1 - Posted 2003-10-21 10:13:44 »

Well this is the terrain render loop I curently use, it's probably not the best way to do it, but it was the most direct way to convert the GL_TRIANGLES loop I had before (very much like yours) into a GL_TRIANGLE_STRIP loop:

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  
      private void renderGeo(GL gl, float fScale) {
            float vfHeights[][] = m_model.getHeights();
            Point3f origin = m_model.getOrigin();
            boolean bSwitchDirection = false;
            int w = m_model.getWidth();
            int h = m_model.getHeight();
            for (int i = 0; i < w; i++) {
                  if (bSwitchDirection) {
                        for (int j = 0; j < h; j++) {
                              gl.glTexCoord2f((float)(i + 1) / w, (float)j / h);
                              gl.glVertex3f(origin.x + (i + 1) * m_model.getPatchWidth(), origin.y + fScale * vfHeights[i + 1][j], origin.z + j * m_model.getPatchHeight());
                              gl.glTexCoord2f((float)i / w, (float)j / h);
                              gl.glVertex3f(origin.x + i * m_model.getPatchWidth(), origin.y + fScale * vfHeights[i][j], origin.z + j * m_model.getPatchHeight());
                        }
                  } else {
                        for (int j = h - 1; j >= 0; j--) {
                              gl.glTexCoord2f((float)i / w, (float)j / h);
                              gl.glVertex3f(origin.x + i * m_model.getPatchWidth(), origin.y + fScale * vfHeights[i][j], origin.z + j * m_model.getPatchHeight());
                              gl.glTexCoord2f((float)(i + 1) / w, (float)j / h);
                              gl.glVertex3f(origin.x + (i + 1) * m_model.getPatchWidth(), origin.y + fScale * vfHeights[i + 1][j], origin.z + j * m_model.getPatchHeight());
                        }
                  }
                  bSwitchDirection = !bSwitchDirection;
            }
      }


PS: Please ignore the silly names for the model's width and height because the have nothing to do with width and height as experienced by the viewer. I still have to rename them to width/depth or something like that.
Offline Java Cool Dude

Senior Member




Java forever


« Reply #2 - Posted 2003-10-22 03:09:59 »

Nah dude, I was generating terrain meshes that way ever since I was introduced to 3D coding.
I wanna take advantage of Vertex Arrays, and in this case, I think there is something very wrong with the code I provided. Yet  I can't put my hand on it .... Lips Sealed
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pepijnve

Junior Member




Java games rock!


« Reply #3 - Posted 2003-10-22 08:21:36 »

I had a look at the code yesterday and I can't say I saw anything wrong with it. I got about 27 fps on a p3 + onbaord i810.
I modified the code to use one triangle strip for each row of data instead of triangles but that only provided a gain of about 3 fps.
Offline Java Cool Dude

Senior Member




Java forever


« Reply #4 - Posted 2003-10-22 14:02:22 »

I used display lists and I got 510 fps instead of 66 Tongue
Offline quintesse

Junior Member




Java games rock!


« Reply #5 - Posted 2003-10-22 16:28:16 »

Java Cool Dude: He, you were asking how to do triangle strips so that's what I explained. Maybe you should have phrased your question better?  Wink

Anyway, I tried using display lists for my terrain it it slowed down horribly! It did okay for lots's of smaller objects but the terrain itself just didn't want to work :-/ It looked like it was consuming too much memory (even though there were only like 20K triangles) because after 2 seonds the application would become unresponsive and shutting it down made the hard drive trash for about 5 minutes!

PS: You say you get 510fps now, are you using any other threads in your app? If so how do you prevent starvation? Of I let my render thread go at full speed other thread hardly get any time anymore. But putting in a sleep(1) immediately drops my fps to around 80 (instead of 130-160).
Offline Java Cool Dude

Senior Member




Java forever


« Reply #6 - Posted 2003-10-22 16:44:09 »

Quote
Java Cool Dude: He, you were asking how to do triangle strips so that's what I explained. Maybe you should have phrased your question better?  Wink

Anyway, I tried using display lists for my terrain it it slowed down horribly! It did okay for lots's of smaller objects but the terrain itself just didn't want to work :-/ It looked like it was consuming too much memory (even though there were only like 20K triangles) because after 2 seonds the application would become unresponsive and shutting it down made the hard drive trash for about 5 minutes!

PS: You say you get 510fps now, are you using any other threads in your app? If so how do you prevent starvation? Of I let my render thread go at full speed other thread hardly get any time anymore. But putting in a sleep(1) immediately drops my fps to around 80 (instead of 130-160).


Hey man I'm not looking into starting a pointless argument here, but when I was saying I want it to work with tirangle strips, I was referring to the following code:
     gl.glDrawElements(gl.GL_TRIANGLE_STRIP, terrain.vertexIndices.length,gl.GL_UNSIGNED_INT, terrain.vertexIndices);

Turned out that if I wanted it that way, I would have to create a vertex array for every signle row or column; I feared that a lot, and Pepi confirmed it Cry

Using display lists boosts the frame rate tremendously as shown on the following screenshot:


I'm gonna try to return to the glVertex call and see how it fairs, but I doubt it'll be faster thatn DLs.

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  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
135  
136  
137  
138  
139  
140  
141  
142  
143  
144  
import net.java.games.jogl.*;
import net.java.games.jogl.util.GLUT;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;

public class displacementMap implements KeyListener
{
  initRenderer  renderer;
  Animator      loop;
  GLCanvas      canvas;
  Terrain       terrain;
  JFrame        frame;
  boolean       keys[] = new boolean[255];
  int           screenWidth,
                screenHeight,
                canvasHeight,
                canvasWidth,
                xLocation,
                yLocation,
                list;


  public static void main(String []args) {
    displacementMap demo = new displacementMap();
  }

  displacementMap(){
    int fullScreen = JOptionPane.showConfirmDialog(        null, "Would you like to run in fullscreen mode?",
                                                   "Fullscreen",  JOptionPane.YES_NO_OPTION);
    if(fullScreen!=0)
      JFrame.setDefaultLookAndFeelDecorated(true);

    frame          = new JFrame("Displacement map");
    screenWidth    = Toolkit.getDefaultToolkit().getScreenSize().width;
    screenHeight   = Toolkit.getDefaultToolkit().getScreenSize().height;

    switch(fullScreen){
      case 0:
        frame.setUndecorated(true);
      break;
      default:
        canvasWidth  = 640;
        canvasHeight = 480;
        xLocation    = (screenWidth  - canvasWidth )>>1;
        yLocation    = (screenHeight - canvasHeight)>>1;
        frame.setLocation(xLocation,yLocation);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    canvas  = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());
    canvas.setSize(new Dimension(canvasWidth,canvasHeight));
    canvas.addGLEventListener((renderer = new initRenderer()));
    canvas.addKeyListener(this);
    canvas.requestFocus();

    frame.getContentPane().add(canvas,BorderLayout.CENTER);
    frame.addWindowListener(new shutDownWindow());
    frame.addKeyListener(this);

    if(fullScreen==0){
      GraphicsEnvironment.getLocalGraphicsEnvironment().
      getDefaultScreenDevice().setFullScreenWindow(frame);
      GraphicsEnvironment.getLocalGraphicsEnvironment().
      getDefaultScreenDevice().setDisplayMode((new DisplayMode(640, 480, 32,
                                               DisplayMode.REFRESH_RATE_UNKNOWN)));
    }
    else
      frame.pack();
    frame.setVisible(true);
  }

  public class initRenderer
               implements GLEventListener
  {
    public void init(GLDrawable drawable){
      GL  gl         = drawable.getGL();

      terrain = new Terrain(frame, "Data/height.jpg", "Data/texture.jpg");
      gl.glEnableClientState(gl.GL_VERTEX_ARRAY);
      gl.glEnableClientState(gl.GL_COLOR_ARRAY);
      gl.glNewList((list = gl.glGenLists(1)),gl.GL_COMPILE);
      gl.glVertexPointer(3, gl.GL_FLOAT, 0, terrain.vertexData);
      gl.glColorPointer( 3, gl.GL_FLOAT, 0, terrain.colorData );
      gl.glDrawElements(gl.GL_TRIANGLES, terrain.vertexIndices.length,gl.GL_UNSIGNED_INT, terrain.vertexIndices);
      gl.glEndList();
      loop  = new Animator(drawable);
      loop.start();
    }

    public void display(GLDrawable drawable){
      GL  gl         = drawable.getGL();
      GLU glu        = drawable.getGLU();
      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
      gl.glLoadIdentity();
      glu.gluLookAt(96,196,250, 96,0,96,0,1,0);
      gl.glCallList(list);
    }

    public void reshape(GLDrawable drawable,
                        int xstart,int ystart,
                        int width, int height){
      GL gl   = drawable.getGL();
      GLU glu = drawable.getGLU();
      
      height  = (height == 0) ? 1 : height;

      gl.glViewport(0,0,width,height);
      gl.glMatrixMode(gl.GL_PROJECTION);
      gl.glLoadIdentity();

      glu.gluPerspective(50.0f,(float)width/height,10.f,1700.0f);
      gl.glMatrixMode(gl.GL_MODELVIEW);
      gl.glLoadIdentity();
    }

    public void displayChanged(GLDrawable drawable,
                               boolean modeChanged,
                               boolean deviceChanged){}
  }

  public void processKeyboard(){}

  public void keyReleased(KeyEvent evt){
    keys[evt.getKeyCode()] = false;
  }

  public void keyPressed (KeyEvent evt){
    keys[evt.getKeyCode()] = true;

    if(keys[KeyEvent.VK_ESCAPE]){
      loop.stop();
      System.exit(0);
    }
  }

  public void keyTyped   (KeyEvent evt){}

  public class shutDownWindow extends WindowAdapter {
    public void windowClosing(WindowEvent e) {
      loop.stop();
    }
  }
}

Offline quintesse

Junior Member




Java games rock!


« Reply #7 - Posted 2003-10-22 22:44:08 »

Quote
Turned out that if I wanted it that way, I would have to create a vertex array for every signle row or column; I feared that a lot, and Pepi confirmed it


You do? Is there any reason why that won't work? (not that I'm doubting either one of you, just curious as to why it works that way).
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

pw (17 views)
2014-07-24 01:59:36

Riven (17 views)
2014-07-23 21:16:32

Riven (14 views)
2014-07-23 21:07:15

Riven (17 views)
2014-07-23 20:56:16

ctomni231 (45 views)
2014-07-18 06:55:21

Zero Volt (40 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (51 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!