Hi all,
I am a beginner in JOGL, I spent almost 2 full days looking online tutorial, examples, etc…
The problem is that there is not so much material about JOGL, and among the results many stuff is outdated, for other programming languages and so on…
Well, I need to display a mesh/array of triangles
public class CudaImplementation implements GLEventListener{
public static void main(String[] args) throws IOException{
GLProfile profile = GLProfile.get(GLProfile.GL3);
final GLCapabilities capabilities = new GLCapabilities(profile);
GLCanvas canvas = new GLCanvas(capabilities);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new CudaImplementation(capabilities);
}
});
}
public CudaImplementation(GLCapabilities capabilities) {
// Initialize the GL component and the animator
GLCanvas glComponent = new GLCanvas((GLCapabilitiesImmutable)capabilities);
glComponent.setFocusable(true);
glComponent.addGLEventListener(this);
// Create the main frame
frame = new JFrame("JCuda / JOGL interaction sample");
frame.addWindowListener(new WindowAdapter()
{
@Override
public void windowClosing(WindowEvent e)
{
runExit();
}
});
frame.setLayout(new BorderLayout());
glComponent.setPreferredSize(new Dimension(800, 800));
frame.add(glComponent, BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
glComponent.requestFocus();
@Override
public void init(GLAutoDrawable gLAutoDrawable) {
// Perform the default GL initialization
GL3 gl = gLAutoDrawable.getGL().getGL3();
gl.setSwapInterval(0);
gl.glEnable(GL3.GL_DEPTH_TEST);
gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
//setupView(GLAutoDrawable);
// Create the VBO containing the vertex data
initVBO(gl);
}
@Override
public void display(GLAutoDrawable gLAutoDrawable) {
GL3 gl = gLAutoDrawable.getGL().getGL3();
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vertexArray);
gl.glEnableClientState(GL3.GL_VERTEX_ARRAY_BINDING);
gl.glDrawArrays(GL.GL_TRIANGLES, 0, array.size());
}
FloatBuffer data = Buffers.newDirectFloatBuffer(size);
private void initVBO(GL3 gl)
{
int buffer[] = new int[1];
// Create the vertex buffer object
gl.glGenBuffers(1, IntBuffer.wrap(buffer));
vertexArray = buffer[0];
// Initialize the vertex buffer object
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, vertexArray);
for(Triangle t : array) {
data.put(t.x1);
data.put(t.y1);
data.put(t.z1);
data.put(t.x2);
data.put(t.y2);
data.put(t.z2);
data.put(t.x3);
data.put(t.y3);
data.put(t.z3);
}
data.rewind();
// Fill the vertex buffer object
gl.glBufferData(GL.GL_ARRAY_BUFFER, size * Sizeof.FLOAT, data, GL.GL_STATIC_DRAW);
// data are in the GPU, data is no longer necessary
data = null;
}
The problem is that I dont see anything, I guess the main reasons could be:
- no color info in the Vertex Buffer Array (but when I used the glBegin/End it was displaying them white)
- shall I need an animator?
- shall I need to specify the view? (there is not a default one?)
- OpenGL does not know which data, or better the memory layout, of the vertex buffer array data.
In OpenGL 2.x you just write
glVertexPointer(3,GL_FLOAT,16,0);
if you have:
- 3 coordinates
- float type
- 16 the total length for triangle (vertex+color)
- 0 the offset where the 3 coordinates start in this 16 Bytes
But in GL3 I dont have anything like that
Please I would need some help from people more skilled than me (and it is not difficult >.>)