Can someone please help me complete this sample code?
Posted by s3a on Jul 28, 2011; 6:24pm
URL: https://forum.jogamp.org/Can-someone-please-help-me-complete-this-sample-code-tp3207414.html
I am reading C++ OpenGL tutorials on random websites and this is the translation I made. I am using JOGL 1.1.1/OpenGL 2.1 (and I am avoiding deprecated code).
My current problem is understanding what these two lines do (or if I translated them correctly from C++ since my Java is good but my C++ isn't so great - I am working on my C++ skills separately):
gl.glGenBuffers(1, &positionBufferObject);
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, positionBufferObject);
If I did anything else wrong, please correct me for that too. I'm still trying to make a polygon or some kind of shape display in 3D without using syntax like glBegin and glEnd as a "Hello world" type of program so that I can get started for real. Basically, I think I am avoiding the fixed function pipeline and aiming at using the programmable shader pipeline.
Here is the mini-JOGL code sample I made:
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLEventListener;
import javax.swing.JFrame;
public class Third implements GLEventListener
{
public void init(GLAutoDrawable glad) {
}
public void display(GLAutoDrawable drawable) {
// What I know works
GL gl = drawable.getGL();
gl.glClearColor(0.1f, 0.5f, 1.0f, 0.7f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glFlush();
// What I'm trying to learn now
int theProgram = gl.glCreateProgram();
gl.glUseProgram(theProgram);
gl.glGenBuffers(1, &positionBufferObject); // This seems pointer-ish (I do not know much about C++ pointers yet) - is it incorrect in Java use?
gl.glBindBuffer(GL.GL_ARRAY_BUFFER, positionBufferObject); // I am trying to create a positionBufferObject object reference variable on the line above
gl.glEnableVertexAttribArray(0);
gl.glVertexAttribPointer(0, 4, GL.GL_FLOAT, false, 0, 0);
gl.glDrawArrays(GL.GL_TRIANGLES, 0, 3);
gl.glDisableVertexAttribArray(0);
gl.glUseProgram(0);
// gl.glutSwapBuffers();
}
public void reshape(GLAutoDrawable glad, int i, int i1, int i2, int i3) {
}
public void displayChanged(GLAutoDrawable glad, boolean bln, boolean bln1) {
}
public static void main(String[] args) {
JFrame frame = new JFrame("TheFrame");
GLCanvas canvas = new GLCanvas();
canvas.addGLEventListener(new Third());
frame.add(canvas);
frame.setSize(300,300);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Any input would be greatly appreciated!
Thanks in advance!