Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
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  
  VBO help  (Read 852 times)
0 Members and 1 Guest are viewing this topic.
Offline _thomas_

Junior Newbie





« Posted 2008-04-02 12:28:48 »

Hi!

Here is my Vertex Buffer Object test code:
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  
import com.sun.opengl.util.Animator;
import com.sun.opengl.util.BufferUtil;
import java.awt.BorderLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import java.nio.IntBuffer;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;
import javax.swing.JFrame;

public class VBO extends JFrame implements GLEventListener, KeyListener {
    private GL gl;
    private GLU glu;
    private GLCanvas canvas;
    private Animator anim;
   private GLCapabilities caps;
   private static final int SW = 1024;
   private static final int SH = 768;
   private boolean VBOsupported = false;
   // VBO
  private int vertexCount;    // Vertex Count
  private IntBuffer vertices;    // Vertex Data
  // Vertex Buffer Object Names
  private int[] VBOVertices = new int[1];  // Vertex VBO Name
   
    public VBO() {
      setUndecorated( true );
      caps = new GLCapabilities();
      canvas = new GLCanvas( caps );
        canvas.addGLEventListener(this);
      canvas.addKeyListener( this );
        getContentPane().add(canvas, BorderLayout.CENTER);
        setSize( SW, SH );
        setTitle("AStar");
        setVisible(true);
        anim = new Animator(canvas);            // calls display() periodically
       anim.start();
    }
   
    public static void main(String[] args) {
        new VBO();
    }

    public void init(GLAutoDrawable arg0) {
        gl = arg0.getGL();
      glu = new GLU();
        gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
      gl.glColor4f( 1f, 1f, 1f, 1f );
      glu.gluOrtho2D( 0.0, SW, 0.0, SH );
      gl.glDisable( GL.GL_TEXTURE_2D );
      gl.glLineWidth( 1.0f );
      gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_FILL );
      gl.glShadeModel( GL.GL_SMOOTH );
      gl.glHint( GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST );
     
      // Check For VBO support
       VBOsupported = gl.isFunctionAvailable("glGenBuffersARB") &&
                gl.isFunctionAvailable("glBindBufferARB") &&
                gl.isFunctionAvailable("glBufferDataARB") &&
                gl.isFunctionAvailable("glDeleteBuffersARB");
     
      if ( VBOsupported ){
         debug( "VBO SUPPORTED!" );
      } else {
         debug( "VBO NOT SUPPORTED!" );
         System.exit( 0 );
      }
     
      vertexCount = 4;
      vertices = BufferUtil.newIntBuffer( vertexCount * 2 );
      vertices.put( SW/2 );
      vertices.put( SH/2 );
     
      vertices.put( SW/2 );
      vertices.put( SH/2+20 );
     
      vertices.put( SW/2+20 );
      vertices.put( SH/2+20 );
     
      vertices.put( SW/2+20 );
      vertices.put( SH/2 );
     
      // Generate And Bind The Vertex Buffer
     gl.glGenBuffersARB( 1, VBOVertices, 0 );  // Get A Valid Name
     gl.glBindBufferARB( GL.GL_ARRAY_BUFFER_ARB, VBOVertices[0] );  // Bind The Buffer
     // Load The Data
     gl.glBufferDataARB( GL.GL_ARRAY_BUFFER_ARB, vertexCount * 2 *
            BufferUtil.SIZEOF_INT, vertices, GL.GL_STATIC_DRAW_ARB );

      // Our Copy Of The Data Is No Longer Necessary, It Is Safe In The Graphics Card
     vertices = null;
    }
   
   private void debug( String str ){
      System.out.println( "DEBUG: " + str );
   }
   
    public void display(GLAutoDrawable arg0) {
        final GL gl = arg0.getGL();
        gl.glClear( GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );
      //VBO
     gl.glLoadIdentity();
      // Enable Pointers
     gl.glEnableClientState( GL.GL_VERTEX_ARRAY );  // Enable Vertex Arrays
     gl.glBindBufferARB( GL.GL_ARRAY_BUFFER_ARB, VBOVertices[0] );
      // Set The Vertex Pointer To The Vertex Buffer
     gl.glVertexPointer( 2, GL.GL_INT, 0, 0 );
      gl.glDrawArrays( GL.GL_QUADS, 0, vertexCount );  
      gl.glDisableClientState( GL.GL_VERTEX_ARRAY );
    }

   
    public void reshape(GLAutoDrawable drawable, int x, int y, int width,
            int height) {
    }

    public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2) {}

   public void keyTyped( KeyEvent e ){
   }

   public void keyPressed( KeyEvent e ){
      if ( e.getKeyCode() == KeyEvent.VK_ESCAPE ){
         System.exit( 0 );
      }
   }

   public void keyReleased( KeyEvent e ){
   }
}


There's nothing on the screen. What did I wrong?
Environment:
java 1.6.0_02
jogl 1.1.1 rc8
windows xp sp2 eng 32bit
ati x1600 xt

Thanks!
Bye,
  _thomas_
Offline GKW

Senior Member




Revenge is mine!


« Reply #1 - Posted 2008-04-02 18:07:56 »

YOu need to read up on the projection matrix and the modelview matrix.
Offline _thomas_

Junior Newbie





« Reply #2 - Posted 2008-04-02 21:08:30 »

YOu need to read up on the projection matrix and the modelview matrix.

I modified the reshape method:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
public void reshape( GLAutoDrawable drawable, int x, int y, int width,  int height ){
    gl.glViewport( 0, 0, width, height );
    gl.glMatrixMode( GL.GL_PROJECTION );
    gl.glLoadIdentity();

    glu.gluPerspective( 45, ( float ) width / height, 1, 1000 );
    gl.glMatrixMode( GL.GL_MODELVIEW );
    gl.glLoadIdentity();
}

But it's not work.
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.

xsi3rr4x (53 views)
2014-04-15 18:08:23

BurntPizza (51 views)
2014-04-15 03:46:01

UprightPath (65 views)
2014-04-14 17:39:50

UprightPath (48 views)
2014-04-14 17:35:47

Porlus (65 views)
2014-04-14 15:48:38

tom_mai78101 (89 views)
2014-04-10 04:04:31

BurntPizza (149 views)
2014-04-08 23:06:04

tom_mai78101 (245 views)
2014-04-05 13:34:39

trollwarrior1 (203 views)
2014-04-04 12:06:45

CJLetsGame (210 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!