I have two big questions regarding to the VAO. (It might be helpful to understand my question if you know the coding of the gl3 version of hello triangle )
1. How should I store my vertex information into the array? I know it is user-defined but what is the usual practice? I am puzzled because, in the hello triangle version, I saw 5 floats for each vertex but there are no description about their identity. What are they? Why can't just x,y,z,w? Is it recommended to combining the colors and coordinates into a single VAO? 2. Is it recommended to ArrayList to hold the vertex information before packaging it into a buffer? If yes, could you kindly give an example of putting an ArrayList into a buffer usable in opengl3? If there are any conceptual mistakes in my questions, please fill free to point it out. I am still new to opengl 3. thanks. Daniel
Never Stop ... Learn more ... Be humble ...
|
Administrator
|
Hi
You should look at the source code of several major scenegraph APIs and engines to know how we solved those problems when implementing their JOGL renderers, for example in LibGDX and in JMonkeyEngine 3.
Julien Gouesse | Personal blog | Website
|
In reply to this post by DearDaniel
Hi Daniel, 1) I am in the process of writing a small wiki, have you already had the chance to take a look at it? Essentially its a vec2 position followed by a vec3 color 2) It depends on your application and on the ArrayList type |
I understand now. Thanks for the small wiki. I am reading it now. So glad to see a proper tutorial on opengl 3(I can't find one from the internet, especially for java). That is very helpful. That solves most of my questions.
So, one last minor question. Is the z coordinate default to be 0? If I use vec2 to represent the coordinate. If I wanted to add the z coordinate, how should I inform the opengl to set the coordinate? My guess after reading the small wiki is that just increase the offset in the gl3.glVertexAttribPointer() from offset = 2 * Float.BYTES to offset = 3 * Float.BYTES. But, is opengl smart enough to know that the new float is the z coordinate of the vertex?
Never Stop ... Learn more ... Be humble ...
|
This post was updated on .
Glad it helps, I'll try to finish it sooner or later :p A vertex attribute should be padded in this way in the vertex shader (x, 0, 0, 1). But I'd suggest to not rely on the drivers policy and always specify it yourself, like I do here. Right guess. However you also need to pass 3 as the number of coordinates, so this: int stride = (2 + 3) * Float.BYTES; int offset = 0 * Float.BYTES; gl3.glEnableVertexAttribArray(Semantic.Attr.POSITION); gl3.glVertexAttribPointer(Semantic.Attr.POSITION, 2, GL_FLOAT, false, stride, offset); offset = 2 * Float.BYTES; gl3.glEnableVertexAttribArray(Semantic.Attr.COLOR); gl3.glVertexAttribPointer(Semantic.Attr.COLOR, 3, GL_FLOAT, false, stride, offset); becomes: int stride = (3 + 3) * Float.BYTES; int offset = 0 * Float.BYTES; gl3.glEnableVertexAttribArray(Semantic.Attr.POSITION); gl3.glVertexAttribPointer(Semantic.Attr.POSITION, 3, GL_FLOAT, false, stride, offset); offset = 3 * Float.BYTES; gl3.glEnableVertexAttribArray(Semantic.Attr.COLOR); gl3.glVertexAttribPointer(Semantic.Attr.COLOR, 3, GL_FLOAT, false, stride, offset); You also need to change the vertex attribute in the shader from vec2 to vec3 and the consequent padding |
Thanks, that's solves my problem.
Looking forward for the completion of your small wiki. Daniel
Never Stop ... Learn more ... Be humble ...
|
It won't be soon, unfortunately... But dont worry, in the meanwhile I strongly suggest you to follow this tutorial. It is one of the best out there and it will give you a wide first introduction to opengl |
Free forum by Nabble | Edit this page |