Show Posts
|
|
Pages: [1]
|
|
2
|
Discussions / General Discussions / More VBO problems
|
on: 2005-12-28 12:37:22
|
Hello, after find how to set a vertex buffer using an offset (my previous post) and spending a whole morning (with C I did it in 5 minutes...) I couldn't get the VBO running :/ My purpose is join all small buffers in a big VBO buffer, and in the render loop only change the indices's vbo of the current drawn mesh. My app doesn't crash, but doesn't draw anything... perhaps I am missing something about nio buffers of something like that. All of the following code is made after many hours of debug and tests, so it is not optimal at all. I know that there are better methods to perform the following tasks, but I wanted to make all as simple as possible to minimize the problems. Well, here is where I join all objects (assume that the object's data is right, because with standard VA all is drawn correctly) 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
| int vertexCount = 0; for(int i=0;i<m_meshes.length;i++) vertexCount += m_meshes[i].GetNumberOfVertices(); float vert[] = new float[vertexCount*3]; int index = 0; int indexOffset = 0; long offset = 0; for(int i=0;i<m_meshes.length;i++) { float v[] = m_meshes[i].GetVertices(); for(int j=0;j<v.length;j++) { vert[index++] = v[j]; } m_meshes[i].SetOffset(offset); m_meshes[i].BuildIndexVBO(indexOffset); offset += m_meshes[i].GetNumberOfVertices() * 3 * 4; indexOffset += m_meshes[i].GetNumberOfVertices(); } m_vboGeom = new int[1]; FloatBuffer vertices = ByteBuffer.allocateDirect((vertexCount * 3) * 4).order(ByteOrder.nativeOrder()).asFloatBuffer(); vertices.put(vert); gl.glGenBuffers(1, m_vboGeom); gl.glBindBuffer(GL.GL_ARRAY_BUFFER, m_vboGeom[0]); gl.glBufferData(GL.GL_ARRAY_BUFFER, vertexCount * 3 * 4, vertices, GL.GL_STATIC_DRAW);
the SetOffset function only performs an asignement to an internal field, for later use
BUILDINDEXVBO FUNCTION public void BuildIndexVBO(int indexoffset) { for(int i=0;i<m_indexCount;i++) m_indices[i] += indexoffset; IntBuffer buffer = ByteBuffer.allocateDirect(m_indexCount * 4).order(ByteOrder.nativeOrder()).asIntBuffer(); gl.glGenBuffers(1, m_vboIndex); gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, m_vboIndex[0]); gl.glBufferData(GL.GL_ELEMENT_ARRAY_BUFFER, m_indexCount * 4, buffer, GL.GL_STATIC_DRAW); gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0); }
DRAW LOOP gl.glEnableClientState(GL.GL_VERTEX_ARRAY); for(int i=0;i<m_meshes.length;i++) { gl.glPushMatrix(); gl.glMultMatrixf(m_meshes[i].TM); gl.glBindBuffer(GL.GL_ARRAY_BUFFER, m_vboGeom[0]); ByteBuffer offsetBuffer = BufferUtils.bufferOffset(m_meshes[i].m_vboOffset); gl.glVertexPointer(3, GL.GL_FLOAT, 0, offsetBuffer); gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, m_meshes[i].m_vboIndex[0]); gl.glDrawElements(GL.GL_TRIANGLES,m_meshes[i].m_indexCount,GL.GL_UNSIGNED_INT,(Buffer) null); gl.glPopMatrix(); } gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0); gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0); gl.glDisableClientState(GL.GL_VERTEX_ARRAY); |
Any help will be appreciated, I am really lost with this issue 
|
|
|
|
|
3
|
Discussions / General Discussions / Re: VBO Offsets
|
on: 2005-12-27 20:01:09
|
|
Currently I am in production process, so I can't base my develop in a beta (I must wait for the release :/ ) But I've just found a way to perform that operation using BufferUtils, creating an offsetBuffer (it seems that I didn't dive enought deep in the documentation). Anyway, thanks for the help
|
|
|
|
|
5
|
Discussions / General Discussions / VBO Offsets
|
on: 2005-12-27 18:33:49
|
|
Hello,
Perhaps my question is obvious, but I cant find a solution, maybe you can help me: I have a scene with a large set of objects. I'm trying to setup a big vbo which will contains all vertices, and draw every object trough an offset to the so called big array. Mi problem is this: in java there aren't "pointers neither offsets", so the compiler complains to me when I try to pass an int in the latest glVertexPointer parameter. I can't figure how to pass the offset, so any help will be nice.
Thanks, Jacobo
|
|
|
|
|
6
|
Java Game APIs & Engines / JOGL Development / Re: Vertex Arrays Problems
|
on: 2005-09-07 11:12:41
|
1
| ByteBuffer.allocateDirect(24 << 2).order(ByteOrder.nativeOrder()).asFloatBuffer(); |
This "works", in the meaning that the VM does not crash, and I can see a quad, so I must clean the rest of my gl code. Here is the whole code of the rendering class (I am following a tutorial, so not all this code is mine): 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 145 146 147 148 149
| import net.java.games.jogl.*; import javax.swing.*; import javax.imageio.ImageIO; import java.nio.ByteBuffer; import java.awt.image.BufferedImage; import java.awt.image.Raster; import java.io.*; import java.nio.*;
public class JoglPanel extends JPanel implements GLEventListener, Animated { private GLCanvas canvas; private float angle; ByteBuffer texture; int[] textures; int tWidth; int tHeight; public JoglPanel() { super(); this.textures=new int[1]; GLCapabilities capabilities = new GLCapabilities(); capabilities.setHardwareAccelerated(true); capabilities.setDoubleBuffered(true); canvas = GLDrawableFactory.getFactory().createGLCanvas(capabilities); canvas.addGLEventListener(this); this.add(canvas); this.setSize(640,480); canvas.setSize(640,480); canvas.setVisible(true); }
public void BuildCube(GL myGL) { float vertices[] = {-5,-5,-5, 5,-5,-5, 5,5,-5, -5,5,-5, -5,-5,5, 5,-5,5, 5,5,5, -5,5,5}; float texCoords[] = {0,0, 1,0, 1,1, 0,1, 1,1, 0,1, 0,0, 1,0}; FloatBuffer vert = FloatBuffer.allocate(24); vert.put(vertices); vert.flip(); myGL.glVertexPointer(3, GL.GL_FLOAT, 0,(Buffer)vert); } public void init(GLDrawable glDrawable) { GL myGL = glDrawable.getGL(); BuildCube(myGL); myGL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); myGL.glShadeModel(GL.GL_SMOOTH); myGL.glGenTextures(0, textures); myGL.glBindTexture(GL.GL_TEXTURE_2D, textures[0]); loadTexture(); myGL.glTexImage2D(GL.GL_TEXTURE_2D, 0, 3, tWidth, tHeight, 0, GL.GL_RGB, GL.GL_UNSIGNED_BYTE, texture); myGL.glShadeModel(GL.GL_SMOOTH); myGL.glEnable(GL.GL_TEXTURE_2D); myGL.glEnable(GL.GL_DEPTH_TEST); myGL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); myGL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); }
public void reshape(GLDrawable glDrawable, int i, int i1, int i2, int i3) { GL myGL = glDrawable.getGL(); int width = canvas.getWidth(); int height = canvas.getHeight(); myGL.glMatrixMode(GL.GL_PROJECTION); myGL.glLoadIdentity(); glDrawable.getGLU().gluPerspective(45, (float)width/height, 1, 1000); myGL.glMatrixMode(GL.GL_MODELVIEW); myGL.glLoadIdentity(); }
public void display(GLDrawable glDrawable) { GL myGL = glDrawable.getGL(); int width = canvas.getWidth(); int height = canvas.getHeight(); myGL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); myGL.glLoadIdentity(); myGL.glTranslatef(0,0,-50); myGL.glRotatef(angle,0,0,1); myGL.glEnableClientState(GL.GL_VERTEX_ARRAY); int cube[] = {2,1,3,0, 5,6,4,7, 6,2,7,3, 1,5,0,4, 3,0,7,4, 6,5,2,1}; myGL.glDrawElements(GL.GL_QUADS, 24, GL.GL_INT, cube); myGL.glDisableClientState(GL.GL_VERTEX_ARRAY); myGL.glFlush(); } public void displayChanged(GLDrawable glDrawable, boolean b, boolean b1) { }
public void timeStep(long time) { angle+=2; canvas.repaint(); } public void loadTexture() { try { BufferedImage buff = ImageIO.read(new File("o.jpg")); Raster r = buff.getRaster(); int[] img = null; img = r.getPixels(0, 0, buff.getWidth(), buff.getHeight(), img);
texture = ByteBuffer.allocateDirect(buff.getWidth() * buff.getHeight() * 3); for (int y = 0; y < buff.getHeight(); y++) { for (int x = 0; x < buff.getWidth(); x++) { texture.put((byte) img[(y * buff.getWidth() + x) * 3]); texture.put((byte) img[(y * buff.getWidth() + x) * 3 + 1]); texture.put((byte) img[(y * buff.getWidth() + x) * 3 + 2]); } } tWidth = buff.getWidth(); tHeight = buff.getHeight(); } catch (IOException e) { e.printStackTrace(); } } |
Modification: With the changes in the creating buffer process, now all works fine, many thanks 
|
|
|
|
|
8
|
Java Game APIs & Engines / JOGL Development / Vertex Arrays Problems
|
on: 2005-09-06 18:20:17
|
Hello, probably this problem has an obviuos solution, but I'm new at Java and JoGL (I come from C++) and I cant find the solution. Well, this is my problem: I am trying to render a simple cube, through vertex arrays (not inmediate mode), but just after the glVertexPointer call, I get an exception. Here is my code: float vertices[] = {-5,-5,-5, 5,-5,-5, 5,5,-5, -5,5,-5, -5,-5,5, 5,-5,5, 5,5,5, -5,5,5}; FloatBuffer vert = FloatBuffer.allocate(24); vert.put(vertices); gl.glVertexPointer(3, gl.GL_FLOAT, 0, vert); and this is the error that I am getting: # # An unexpected error has been detected by HotSpot Virtual Machine: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000, pid=196, tid=3820 # # Java VM: Java HotSpot(TM) Client VM (1.5.0_04-b05 mixed mode, sharing) # Problematic frame: # C 0x00000000 # # An error report file with more information is saved as hs_err_pid196.log # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp# Any help would be appreciated, Thanks
|
|
|
|
|