hi, trying to get the nehe port to run in eclipse.
it compiles. but can not find the images like: demos\data\images\terrain.bmp does anyone know where they live? thanks |
found some here (including the source) http://www.java-tips.org/images/stories/tips/others/jogl/170606/nehe.zip
lesson45 now working. vbo test throws a npe in gl.glGenBuffers(2,temp,0); - original code was using awt while i am using a jpanel. thanks |
Administrator
|
Which variable is set to null? The GL? Can you show your source code?
Julien Gouesse | Personal blog | Website
|
not sure why my code was throwing, but this code works fine:
import java.nio.FloatBuffer; import java.nio.ShortBuffer; import javax.media.opengl.GL; import javax.media.opengl.GL2; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLEventListener; import javax.media.opengl.awt.GLJPanel; import javax.media.opengl.fixedfunc.GLPointerFunc; import javax.swing.JFrame; import javax.swing.WindowConstants; import com.jogamp.common.nio.Buffers; public class VBOGLJPanel extends GLJPanel implements GLEventListener { public static void main(String[] args) { JFrame frame=new JFrame(); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); VBOGLJPanel canvas=new VBOGLJPanel(); canvas.addGLEventListener(canvas); frame.add(canvas); frame.setSize(640,480); frame.setVisible(true); } @Override public void init(GLAutoDrawable drawable) { vboInit(drawable); } private void vboInit(GLAutoDrawable drawable) { float[] vertexArray={-0.5f,0.5f,0,0.5f,0.5f,0,0.5f,-0.5f,0,-0.5f,-0.5f,0}; FloatBuffer vertices=Buffers.newDirectFloatBuffer(vertexArray.length); vertices.put(vertexArray); vertices.flip(); short[] indexArray={0,1,2,1/* 0 */,2,3}; ShortBuffer indices=Buffers.newDirectShortBuffer(indexArray.length); indices.put(indexArray); indices.flip(); GL gl=drawable.getGL(); gl.glGenBuffers(1,VBOVertices,0); gl.glBindBuffer(GL.GL_ARRAY_BUFFER,VBOVertices[0]); gl.glBufferData(GL.GL_ARRAY_BUFFER,vertices.capacity()*Buffers.SIZEOF_FLOAT,vertices,GL.GL_STATIC_DRAW); gl.glBindBuffer(GL.GL_ARRAY_BUFFER,0); gl.glGenBuffers(1,VBOIndices,0); gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER,VBOIndices[0]); gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER,indices.capacity()*Buffers.SIZEOF_SHORT,indices,GL.GL_DYNAMIC_DRAW); gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER,0); indicesCapacity=indices.capacity(); } private void vboRender(GLAutoDrawable drawable) { GL2 gl=drawable.getGL().getGL2(); gl.glEnableClientState(GLPointerFunc.GL_VERTEX_ARRAY); gl.glBindBuffer(GL.GL_ARRAY_BUFFER,VBOVertices[0]); gl.glVertexPointer(3,GL.GL_FLOAT,0,0); gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER,VBOIndices[0]); gl.glDrawElements(GL.GL_TRIANGLES,indicesCapacity,GL.GL_UNSIGNED_SHORT,0); gl.glDisableClientState(GLPointerFunc.GL_VERTEX_ARRAY); } @Override public void display(GLAutoDrawable drawable) { vboRender(drawable); } @Override public void reshape(GLAutoDrawable drawable,int x,int y,int width,int height) {} public void displayChanged(GLAutoDrawable drawable,boolean modeChanged,boolean deviceChanged) {} @Override public void dispose(GLAutoDrawable drawable) {} private int[] VBOVertices=new int[1]; private int[] VBOIndices=new int[1]; int indicesCapacity; private static final long serialVersionUID=1L; } |
Free forum by Nabble | Edit this page |