This post was updated on .
First post here. I just started using jogl and I have a lot of questions, but right now I'm adressing the ones about VAOs and VBOs.
I'm trying to follow and tutorial on youtube but the guy is using lwjgl and it seems they're very different. His code can be found here: https://www.dropbox.com/sh/sqqfm1s0vxcqf8u/AACkLQP2v_e-oDt_PaTKapoza/Loader.java?dl=0 So, from what I've understood until now (or at least I think I did), lwjgl uses static methods to create/bind/changeAtributes etc... VAOs and VBOs and JOGL uses instance methods that need to be refered from a context, so instead of calling the "GL'X'"."method()" (If I wanted to do this in a separate class like this guy) I would need a contructor that would be called in the "public void init(GLAutoDrawable drawable)" and would pass drawable so these class would have a field "GL2 gl = drawable.getGL().getGL2();" right? And after this I would call gl."methods"?. The next question is about this method: private int createVAO() { int vaoID = GL30.glGenVertexArrays(); vaos.add(vaoID); GL30.glBindVertexArray(vaoID); return vaoID; } So, i try to call gl.glGenVertexArrays()... It needs two parameters (or three), a size (of what?), a buffer(which buffer?) or an array plus offset(which array and offset?) and it doesn't return a int so I can't reference it later (so I can't use: public void cleanUp() { for (int vao : vaos) { GL30.glDeleteVertexArrays(vao); } for (int vbo : vbos) { GL15.glDeleteBuffers(vbo); } for (int texture : textures) { GL11.glDeleteTextures(texture); } } ) Same with VBOs: private void storeDataInAttributeList(int attributeNumber, int coordinateSize, float[] data) { int vboID = GL15.glGenBuffers(); vbos.add(vboID); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboID); FloatBuffer buffer = storeDataInFloatBuffer(data); GL15.glBufferData(GL15.GL_ARRAY_BUFFER, buffer, GL15.GL_STATIC_DRAW); GL20.glVertexAttribPointer(attributeNumber, coordinateSize, GL11.GL_FLOAT, false, 0, 0); GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); } Once again I don't get a reference so same poblem as before Sorry about my english (not native speaker) and if this is a noob question or as been adressed before. I tried to research a lot before posting it but a lot of stuff is in c++ (what I don't know) and I don't really know what glGenVertexArrays(int, &?) mean... Edit: Wait! Don't tell me those parameters are filled "as I wish" to give "specific references" instead of "generating random ones and saving them" in lwjgl I mean: gl.glGenVertexArrays("put here the int I was asking for", my "array" of VAO's? ) |
This post was updated on .
Yes, this is a very common question with a simple answer; "OpenGL's implementation is not static". Q: Why does JOGL use Instances of GLContext / GL* instead of exposing a Static API? A: http://forum.jogamp.org/Why-does-JOGL-use-Instances-of-GLContext-GL-instead-of-exposing-a-Static-API-td4034144.html OpenGL have defined glGenVertexArrays as a void function. void glGenVertexArrays(GLsizei n, GLuint *arrays); n Specifies the number of vertex array object names to generate. arrays Specifies an array in which the generated vertex array object names are stored. https://www.opengl.org/sdk/docs/man3/xhtml/glGenVertexArrays.xml LWJGL uses syntactic sugar to create a simplified API but this simplification makes it impossible for the users to generate more than 1 array in one call despite that the name is glGenVertexArrays. OpenGL glGenVertexArrays is designed to allows multiple GPU arrays creation, the function returns multiple ints, one int for each VAO id. JOGL exposes this function to JVM users without limiting the functionality. Java do not support passing a * pointer like in C instead Java has to pass an array [] + an integer offset, or passing an IntBuffer object, in order to give the user the same functionality as passing a * pointer in C. http://jogamp.org/deployment/jogamp-current/javadoc/jogl/javadoc/com/jogamp/opengl/GL2ES3.html#glGenVertexArrays%28int,%20java.nio.IntBuffer%29 Yes same with VBO, see the answer to VAO above. No you have misunderstood the glGenVertexArrays arguments; the int you pass is the number of VAO you want to generate, the passed array will be filled with the returned VAO int id's, just like in OpenGL! |
In reply to this post by PedDavid
You can look at the tutorials. For example Wade Walker has a tutorial about VBOs
http://jogamp.org/wiki/index.php/Jogl_Tutorial#Wade.27s_JOGL_tutorials Maybe the demo source can be of help: http://jogamp.org/git/?p=jogl-demos.git;a=tree;f=src/demos;hb=HEAD They will show you how you get an instance of a GL interface to call GL-methods. But basically you allocate an int array on the java side. Then pass that array to genVertexArrays. OpenGL will create a new 'name' for that VAO and fill in the array with the 'name' (OpenGL uses numbers for names - one of the many strange things about OpenGL). Like this: final int[] vas = new int[1]; gl.glGenVertexArrays(this.vas.length, this.vas, 0); final int[] vbos = new int[numberOfBuffers]; gl.glBindVertexArray(this.vas[0]); gl.glGenBuffers(this.vbos.length, this.vbos, 0); |
In reply to this post by Xerxes Rånby
Thanks a lot! I will try this when I get time for it. (I hope still today). I still have a ltitle question:
So, in the linked code this class is used to create a VAO, fill it with vbos and then repeat if I call it again, however, in jogl, I will "have to know how many VAOs I will want", ask for that, and then fill each of them with VBOs? I guess that's why there is the method with the (int, array, offset), I guess I can use that to do code similar to the one linked. PS: I will want to get back to this post with the results, but then should I close the topic or something? Is there any "mark this reply" as helpfull or anything like that? |
In reply to this post by Xerxes Rånby
Just wanted to let you know that I finally managed to make it :D (after trying the code that I had before with your explanation I still had problems (nothing was rendering) but managed to find the problem, forgot to multiply my buffers.capacity() by 4 in the parameter gl.glBufferData to get the value in bytes. I also already managed to put a simple shader working and I'm now going to work on textures. Thanks a ton for your help :)
Edit: Also, the code is a little bit messy because I started doing it the same way I coded games before but I can probably post it after if someone wants to take a look |
Free forum by Nabble | Edit this page |