We are about to switch to a new forum software. Until then we have removed the registration on this forum.
(Did some research this topic on processing, their is no answer todate. So i post my some of my discoveries for the benefit of the community)
@jeffthompson Hello
glShadeModel(GL_FLAT) is deprecated since then 10 years, this is how things work befor shaders were introduced.
You can also compute the hole thing on the CPU.
It should (untested) work with Processing Version <= 2.2.1
Pseudocode https://github.com/processing/processing/wiki/Advanced-OpenGL-in-Processing-2.x
PGraphicsOpenGL pg = (PGraphicsOpenGL)g;
PGL pgl = beginPGL();
gl2 = ((PJOGL)pgl).gl.getGL2();
gl2.glShadeModel(GL.GL_FLAT); // enable flat shading
Second:
"in a really complex project."
Pseudocode
//
void flatShading(float red, float blue, float green ) {
if (enableFlatShading==true) {
PShader flatshader = loadShader("flat.vert","flat.frag");
flatshader.set("color", red, blue, green);
}
else {
resetShader(); // reset to default processing shaders
}
}
hahah too complex. :)
And as i already wrote.Its a modern shader approach transpose inverse of Camera/Object View Matrix (MatrixMath is done on the CPU previously). For backward compatibility, use an older version shader, you can find tones of them on the web.
see here: (works on browsers, should work everywhere)
https://github.com/glslify/glsl-face-normal
If you think about the graphicpipeline. Cube, or what ever shape, will create you some Buffers and then everything is send to shaders, in order to change the color, you have to tweek the shader. https://processing.org/tutorials/pshader/
Probably also there is a way to implement flat shading direct into Shapes3D library.
So it appears that glFog is only available in GL2.
I'm able to get the GL2 context from the GL2ES2 gl like this
pgl = (PJOGL) beginPGL();
GL2ES2 gl = pgl.gl.getGL2ES2()
GL2 = gl.getGL2()
I'm able to access the glFog() functions but when I run the program I get the error
com.jogamp.opengl.GLException: Not a GL2 implementation
I'm stuck...
In case you haven't done so, have you checked prev posts?
https://forum.processing.org/two/search?Search=getGL2
In your first code, are you trying to set up a camera angle?
There is a potential you can get feedback if you describe your issue better. From the link you provided:
projection and modelview matrices needed for an accurate projection of the scene onto a real world model . Based on the exported modelview and projection matrix, I would like to use Processing to create a nice scene
What are modelview matrices? What kind of world model are you referring to? I am guessing this is not your post but you ate familiar with that terminology? Maybe is it realted to shaders? From what I have seen in the forum, shaders assistance is limited, hit and miss.
Kf
this should be fine
GL2 gl2 = ((PJOGL)beginPGL()).gl.getGL2();
mine compiles and runs but tells me it's not a GL2 implementation.
void drawsketch {
PGL pgl;
pgl = beginPGL();
GL2 gl = ((PJOGL)pgl).gl.getGL2();
}
By the way I finally could make the original code more likely.
still getting a GLException: Not a GL2 implementation
Got some old reference, but seems like this way of implementing is now obsolete. https://github.com/processing/processing/blob/e107f6dfb8e322a5edcc6ed751cb1ef952619fb8/build/shared/revisions.txt
import com.jogamp.opengl.*;
import java.nio.FloatBuffer;
float[] modelview = {
0.670984f, 0.250691f, 0.674993f, 0, -0.288247f,
0.966749f, -0.137371f, 0f, -0.68315f, -0.0505059f, 0.720934f, 0f,
0.164808f, 2.1425f, 32.9616f, 1f };
float[] proj = {
0.78125f, 0, 0, 0, 0, 1.04167f, 0, 0, 0, 0, -1.0002f, -1, 0,
0, -2.0002f, 0 };
FloatBuffer mvbuf;
FloatBuffer projbuf;
void setup() {
size(1024, 768, P3D);
PJOGL.profile = 2; //not sure if needed
mvbuf = FloatBuffer.wrap(modelview);
projbuf= FloatBuffer.wrap(proj);
GLProfile glp = GLProfile.get(GLProfile.GL2);
GLCapabilitiesImmutable glcaps = (GLCapabilitiesImmutable) new GLCapabilities(glp);
GLCapabilities tGLCapabilities = new GLCapabilities(glp);
println("System Capabilities:" + glcaps.toString());
println("Profile Details: " + glp.toString());
println("Is GL2 Supported?: " + glp.isGL2());
}
void draw() {
background(0);
PGL pgl = (PJOGL) beginPGL();
GL gl = ((PJOGL) pgl).gl;
GL2 gl2 = gl.getGL2(); //GLException: not a GL2 implemantation
gl2.glMatrixMode(GL2.GL_PROJECTION);
gl2.glLoadIdentity();
gl2.glLoadMatrixf(projbuf);
gl2.glMatrixMode(GL2.GL_MODELVIEW);
gl2.glLoadIdentity();
gl2.glLoadMatrixf(mvbuf);
drawGrid(100, 10, gl2);
endPGL(); //not sure if this is closing what it supposed to
}
void drawGrid(float len, float offset, GL2 g) {
int nr_lines = (int)(len/offset);
g.glColor3f(1, 1, 1);
g.glBegin(g.GL_LINES);
for (int i=-nr_lines; i<nr_lines; i++) {
g.glVertex3f(i*offset, 0, -nr_lines*offset);
g.glVertex3f(i*offset, 0, nr_lines*offset);
}
for (int i=-nr_lines; i<nr_lines; i++) {
g.glVertex3f(-nr_lines*offset, 0, i*offset);
g.glVertex3f(nr_lines*offset, 0, i*offset);
}
g.glEnd();
}
Hi, I am fresh in Processing and Kinect, but I played little bit with Point Cloud sketch. I would like to export this point cloud preview as video. I tried to find tutorial on youtube and google but I coudn't find solution for that. What code I should write to export that preview? The oryginal Sketch is:
/*
Copyright (C) 2014 Thomas Sanchez Lengeling.
KinectPV2, Kinect for Windows v2 library for processing
*/
import java.nio.FloatBuffer;
import KinectPV2.*;
import javax.media.opengl.GL2;
private KinectPV2 kinect;
float a = 0;
int zval = 50;
float scaleVal = 260;
//Distance Threashold
float maxD = 4.0f; //meters
float minD = 1.0f;
public void setup() {
size(1366, 768, P3D);
kinect = new KinectPV2(this);
kinect.enableDepthImg(true);
kinect.enablePointCloud(true);
kinect.activateRawDepth(true);
kinect.setLowThresholdPC(minD);
kinect.setHighThresholdPC(maxD);
kinect.init();
}
public void draw() {
background(0);
//image(kinect.getDepthImage(), 0, 0, 320, 240);
//Threahold of the point Cloud.
kinect.setLowThresholdPC(minD);
kinect.setHighThresholdPC(maxD);
FloatBuffer pointCloudBuffer = kinect.getPointCloudDepthPos();
PJOGL pgl = (PJOGL)beginPGL();
GL2 gl2 = pgl.gl.getGL2();
gl2.glEnable( GL2.GL_BLEND );
gl2.glEnable(GL2.GL_POINT_SMOOTH);
gl2.glEnableClientState(GL2.GL_VERTEX_ARRAY);
gl2.glVertexPointer(3, GL2.GL_FLOAT, 0, pointCloudBuffer);
gl2.glTranslatef(width/2, height/2, zval);
gl2.glScalef(scaleVal, -1*scaleVal, scaleVal);
gl2.glRotatef(a, 0.0f, 1.0f, 0.0f);
gl2.glDrawArrays(GL2.GL_POINTS, 0, kinect.WIDTHDepth * kinect.HEIGHTDepth);
gl2.glDisableClientState(GL2.GL_VERTEX_ARRAY);
gl2.glDisable(GL2.GL_BLEND);
endPGL();
stroke(255, 0, 0);
text(frameRate, 50, height- 50);
}
public void mousePressed() {
println(frameRate);
// saveFrame();
}
public void keyPressed() {
if (key == 'a') {
zval +=1;
println(zval);
}
if (key == 's') {
zval -= 1;
println(zval);
}
if (key == 'z') {
scaleVal += 0.1;
println(scaleVal);
}
if (key == 'x') {
scaleVal -= 0.1;
println(scaleVal);
}
if (key == 'q') {
a += 1;
println(a);
}
if (key == 'w') {
a -= 1;
println(a);
}
if (key == '1') {
minD += 0.01;
println("Change min: "+minD);
}
if (key == '2') {
minD -= 0.01;
println("Change min: "+minD);
}
if (key == '3') {
maxD += 0.01;
println("Change max: "+maxD);
}
if (key == '4') {
maxD -= 0.01;
println("Change max: "+maxD);
}
if (key == '2') {
minD -= 0.01;
println("Change min: "+minD);
}
if (key == '3') {
maxD += 0.01;
println("Change max: "+maxD);
}
if (key == '4') {
maxD -= 0.01;
println("Change max: "+maxD);
}
}
I've changed the above code that I posted to this:
PGraphicsOpenGL pg = (PGraphicsOpenGL) g; // processings opengl graphics object
PGL pgl = beginPGL();
gl2 = ((PJOGL)pgl).gl.getGL2();
pgl.enable(GL2.GL_LINE_SMOOTH); // make points round
gl2.glLineWidth(lineWeight);
gl2.glBegin(GL2.GL_LINES);
No errors anymore, at least for now!
Hello. I've been having issues with running a sketch I have found that was made back in 2012. I've updated a lot of the code but there are some functions and ways of calling with OpenGl that give me errors. I would appreciate if anyone could help me to update the following:
PGraphicsOpenGL pg = (PGraphicsOpenGL) g; // processings opengl graphics object
PGL pgl = beginPGL();
gl2 = ((PJOGL)pgl).gl.getGL2();
pgl.enable(GL2.GL_LINE_SMOOTH); // make points round
pgl.LineWidth(lineWeight);
gl.glBegin(GL.GL_LINES);
Currently I'm getting "the function LineWidth(int) does not exist." What do I need to change? I'm using Processing 2.2.1
Dated sketch can be found here: https://github.com/trentbrooks/Noise-Ink/tree/master/NoiseInk
import java.nio.FloatBuffer;
import com.sun.opengl.util.*;
boolean renderUsingVA = true;
void fadeToColor(GL2 gl, float r, float g, float b, float speed) {
gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA);
gl.glColor4f(r, g, b, speed);
gl.glBegin(gl.GL_QUADS);
gl.glVertex2f(0, 0);
gl.glVertex2f(width, 0);
gl.glVertex2f(width, height);
gl.glVertex2f(0, height);
gl.glEnd();
}
class ParticleSystem {
FloatBuffer posArray;
FloatBuffer colArray;
final static int maxParticles = 5000;
int curIndex;
Particle[] particles;
ParticleSystem() {
particles = new Particle[maxParticles];
for(int i=0; i<maxParticles; i++) particles[i] = new Particle();
curIndex = 0;
posArray = BufferUtil.newFloatBuffer(maxParticles * 2 * 2);// 2 coordinates per point, 2 points per particle (current and previous)
colArray = BufferUtil.newFloatBuffer(maxParticles * 3 * 2);
}
void updateAndDraw(){
//OPENGL Processing 2.1
PGL pgl; // JOGL's GL object
pgl = beginPGL();
GL2 gl = ((PJOGL)pgl).gl.getGL2(); // processings opengl graphics object
gl.glEnable( GL2.GL_BLEND ); // enable blending
gl.glBlendFunc(GL2.GL_ONE, GL2.GL_ONE); // additive blending (ignore alpha)
gl.glEnable(GL2.GL_LINE_SMOOTH); // make points round
gl.glLineWidth(1);
if(renderUsingVA) {
for(int i=0; i<maxParticles; i++) {
if(particles[i].alpha > 0) {
particles[i].update();
particles[i].updateVertexArrays(i, posArray, colArray);
}
}
gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);
gl.glVertexPointer(2, GL2.GL_FLOAT, 0, posArray);
gl.glEnableClientState(GL2.GL_COLOR_ARRAY);
gl.glColorPointer(3, GL2.GL_FLOAT, 0, colArray);
gl.glDrawArrays(GL2.GL_LINES, 0, maxParticles * 2);
}
else {
gl.glBegin(gl.GL_LINES); // start drawing points
for(int i=0; i<maxParticles; i++) {
if(particles[i].alpha > 0) {
particles[i].update();
particles[i].drawOldSchool(gl); // use oldschool renderng
}
}
gl.glEnd();
}
gl.glDisable(GL2.GL_BLEND);
endPGL();
}
void addParticles(float x, float y, int count ){
for(int i=0; i<count; i++) addParticle(x + random(-15, 15), y + random(-15, 15));
}
void addParticle(float x, float y) {
particles[curIndex].init(x, y);
curIndex++;
if(curIndex >= maxParticles) curIndex = 0;
}
}
Hello, Here is the solution:
in setup()
pgl = (PGraphicsOpenGL) g;
in draw()
gl = ((PJOGL)beginPGL()).gl.getGL2();
here you put the stuff you want and after that:
endPGL();
This is working for me. Sorry for the delayed answer. Regards. Luis
um, don't know. searching the forums i get the following code snippets to access opengl directly
here's what i used 3 years ago (probably 1.5.1 as that's what i usually use)
GL gl = ((PGraphicsOpenGL)g).gl;
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(...);
here's something from 2 years ago:
PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
GL2 gl = pgl.beginPGL().gl.getGL2();
gl.glEnable(GL.GL_BLEND);
...
Hello,
I changed an older OpenGL example to draw triangles instead of drawing points (below). Can somebody tell me how I incorporate lights into this scene? I don't need anything fancy; something that replicates processing's usual lights() function would be perfect.
Thanks for your suggestions! Fred
ps. On another note, can PGL also draw quads instead of triangles?
import javax.media.opengl.GL2;
import java.nio.*;
int nvert = 1000;
int SIZEOF_INT = Integer.SIZE / 8;
int SIZEOF_FLOAT = Float.SIZE / 8;
PGL pgl;
IntBuffer vboName;
FloatBuffer vertData;
void setup() {
size(640, 360, P3D);
createGeometry();
initVBO();
}
void draw() {
background(0);
translate(320,180);
rotate(frameCount * 0.01, width, height, 0);
pgl = beginPGL();
GL2 gl2 = ((PJOGL)pgl).gl.getGL2();
pgl.bindBuffer(PGL.ARRAY_BUFFER, vboName.get(0));
gl2.glEnableClientState(GL2.GL_VERTEX_ARRAY);
gl2.glEnableClientState(GL2.GL_COLOR_ARRAY);
gl2.glVertexPointer(3, PGL.FLOAT, 7 * SIZEOF_FLOAT, 0);
gl2.glColorPointer(4, PGL.FLOAT, 7 * SIZEOF_FLOAT, 3 * SIZEOF_FLOAT);
pgl.drawArrays(PGL.TRIANGLES, 0, nvert/3);
gl2.glDisableClientState(GL2.GL_VERTEX_ARRAY);
gl2.glDisableClientState(GL2.GL_COLOR_ARRAY);
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
endPGL();
if (frameCount % 60 == 0) println("fps: " + frameRate);
}
void createGeometry() {
float[] temp = new float[nvert * 7];
for (int n = 0; n < nvert; n++) {
// position
temp[n * 7 + 0] = random(-100, +100);
temp[n * 7 + 1] = random(-100, +100);
temp[n * 7 + 2] = random(-100, +100);
// color
temp[n * 7 + 3] = 1;
temp[n * 7 + 4] = 1;
temp[n * 7 + 5] = 1;
temp[n * 7 + 6] = 1;
}
vertData = allocateDirectFloatBuffer(nvert * 7);
vertData.rewind();
vertData.put(temp);
vertData.position(0);
}
void initVBO() {
vboName = allocateDirectIntBuffer(1);
pgl = beginPGL();
pgl.genBuffers(1, vboName);
pgl.bindBuffer(PGL.ARRAY_BUFFER, vboName.get(0));
pgl.bufferData(PGL.ARRAY_BUFFER, nvert * 7 * SIZEOF_FLOAT, vertData, PGL.STATIC_DRAW);
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
endPGL();
}
IntBuffer allocateDirectIntBuffer(int n) {
return ByteBuffer.allocateDirect(n * SIZEOF_INT).order(ByteOrder.nativeOrder()).asIntBuffer();
}
FloatBuffer allocateDirectFloatBuffer(int n) {
return ByteBuffer.allocateDirect(n * SIZEOF_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
}
Resisting change, I have been unwilling to jump on the Processing 2.0 band wagon in fear of having to learn something new, and change my ways. As a digital Amish person, I've been stubbornly milking my PGraphicsOpenGL objects and loading my tables using the old fashioned ways.
Until now.
You see, I actually really do want to live in the future. I've got electricity, internet, everything. So please help me solve the following issues:
(1) Blend modes & depth sorting
Whenever I port my code, and try and upgrade a custom opengl blending override from say:
PGraphicsOpenGL pgl = (PGraphicsOpenGL) g;
GL gl = pgl.beginGL();
gl.glDisable(GL.GL_DEPTH_TEST);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
pgl.endGL();
to:
PGL pgl = beginPGL();
gl = ((PJOGL)pgl).gl.getGL2();
etc...
I don't get the blending to work the same way as before - that is to say, it doesn't seem to disable depth testing and do a brute force additive blending from any perspective. I get horrible texture clipping artifacts etc. Using the sparkly new blendMode(ADD) function yields the same results, nor does hint(DISABLE_DEPTH_TEST) seem to do anything.
Any ideas?
(2) Performance
A simple sketch running through 360x180 vertices using beginShape(POINTS) with the sketch set to OPENGL breezes through running 1.5, but seems to really struggle running 3.0 Alpha 2. What's going on? Any buttons I forgot to press? I set the thing to noSmooth() in 3.0 even (whilst doing hint(ENABLE_OPENGL_4X_SMOOTH) in 1.5).
??
I'm sure I'm ignorant due to my absence on the boards in the past few years (for which - my apologies!) Ideas and any sort of help much appreciated!
T
Sure..
Here is an example code :
import com.jogamp.opengl.util.gl2.GLUT;
import java.nio.*;
import java.util.*;
import javax.media.opengl.GL2;
import javax.media.opengl.glu.GLU;
PJOGL pgl;
GL2 gl;
GLU glu;
GLUT glut;
float angle = .67;
void setup()
{
size(1280, 720, P3D);
pgl = (PJOGL) beginPGL();
glu = pgl.glu;
glut = new GLUT();
gl = GLU.getCurrentGL().getGL2();
gl.setSwapInterval(1);
gl.glShadeModel(GL2.GL_SMOOTH);
gl.glClearDepth(1.0f);
gl.glEnable(GL2.GL_DEPTH_TEST);
gl.glDepthFunc(GL2.GL_LEQUAL);
gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);
// OFFENDING LINE ! runs with just "smooth();", but not "smooth(32)",
// as soon as I use OpenGL objects..
smooth(32);
}
void draw()
{
background(50);
gl.glPushMatrix();
gl.glTranslatef(displayWidth/2, displayHeight/2, 0);
gl.glRotatef(angle,0,1,0);
gl.glRotatef(angle * 1.02 ,1,0,0);
gl.glScalef(1,-1,1);
gl.glScalef(200,200,200);
drawGlCube();
gl.glPopMatrix();
}
public void drawGlCube()
{
gl.glBegin(GL2.GL_QUADS);
gl.glNormal3f(0,0,-1);
gl.glTexCoord2f(0,0);
gl.glVertex3f(-1,1,-1);
gl.glTexCoord2f(0,1);
gl.glVertex3f(-1,-1,-1);
gl.glTexCoord2f(1,1);
gl.glVertex3f(1,-1,-1);
gl.glTexCoord2f(1,0);
gl.glVertex3f(1,1,-1);
gl.glNormal3f(1,0,0);
gl.glTexCoord2f(1,1);
gl.glVertex3f(1,-1,1);
gl.glTexCoord2f(1,0);
gl.glVertex3f(1,1,1);
gl.glTexCoord2f(0,0);
gl.glVertex3f(1,1,-1);
gl.glTexCoord2f(0,1);
gl.glVertex3f(1,-1,-1);
gl.glNormal3f(0,0,1);
gl.glTexCoord2f(1,1);
gl.glVertex3f(-1,-1,1);
gl.glTexCoord2f(1,0);
gl.glVertex3f(-1,1,1);
gl.glTexCoord2f(0,0);
gl.glVertex3f(1,1,1);
gl.glTexCoord2f(0,1);
gl.glVertex3f(1,-1,1);
gl.glNormal3f(-1,0,0);
gl.glTexCoord2f(0,0);
gl.glVertex3f(-1,1,1);
gl.glTexCoord2f(0,1);
gl.glVertex3f(-1,-1,1);
gl.glTexCoord2f(1,1);
gl.glVertex3f(-1,-1,-1);
gl.glTexCoord2f(1,0);
gl.glVertex3f(-1,1,-1);
gl.glNormal3f(0,1,0);
gl.glTexCoord2f(0,0);
gl.glVertex3f(1,1,1);
gl.glTexCoord2f(0,1);
gl.glVertex3f(-1,1,1);
gl.glTexCoord2f(1,1);
gl.glVertex3f(-1,1,-1);
gl.glTexCoord2f(1,0);
gl.glVertex3f(1,1,-1);
gl.glNormal3f(0,-1,0);
gl.glTexCoord2f(0,0);
gl.glVertex3f(-1,-1,1);
gl.glTexCoord2f(0,1);
gl.glVertex3f(1,-1,1);
gl.glTexCoord2f(1,1);
gl.glVertex3f(1,-1,-1);
gl.glTexCoord2f(1,0);
gl.glVertex3f(-1,-1,-1);
gl.glEnd();
}
When I try to run this, I get a NullPointerException
with the following call stack dump :
java.lang.NullPointerException
at processing.mode.java.runner.Runner.findException(Runner.java:926)
at processing.mode.java.runner.Runner.reportException(Runner.java:871)
at processing.mode.java.runner.Runner.exceptionEvent(Runner.java:797)
at processing.mode.java.runner.Runner$2.run(Runner.java:686)
When I use smooth()
, everything runs fine, but as soon as I write smooth(32)
and use OpenGL code afterwards, I get this exception.
Any idea where it may come from ?
Code Example
import javax.media.opengl.GL;
import javax.media.opengl.GL2;
void setup() {
size(500, 500, P3D);
GL gl = ((PJOGL)beginPGL()).gl.getGL();
endPGL();
GL2 gl2 = ((PJOGL)beginPGL()).gl.getGL2();
endPGL();
exit();
}
Processing's inner architecture, especially related to OpenGL, is constantly changing.
Right now, you could use the following code.
// add global import
import javax.media.opengl.GL2;
// place before shader & shape calls in draw()
GL2 gl = ((PJOGL)beginPGL()).gl.getGL2();
gl.glPolygonMode( GL2.GL_FRONT_AND_BACK, GL2.GL_LINE );
// place after shader & shape calls in draw()
gl.glPolygonMode( GL2.GL_FRONT_AND_BACK, GL2.GL_FILL );
endPGL();
Of course.
However the WIKI is wrong, the correct way to call GL2 is:
PGL pgl = beginPGL();
GL2 gl2 = ((PJOGL)pgl).gl.getGL2();
Thanks koogs. I thought to cut the texture up into smaller blocks, but now I prefer to use low-level opengl. The WIKI reports this:
GL2 gl = ((PGraphicsOpenGL)g).beginPGL().gl.getGL2();
but with Processing 2.1 doesn't work. Any idea how to call GL2?
Thanks in advance. paolofuse
An equivalent, fixed-function pipeline version of the previous code would be (2.1+ only):
import javax.media.opengl.GL2;
import java.nio.*;
int nvert = 1000;
int SIZEOF_INT = Integer.SIZE / 8;
int SIZEOF_FLOAT = Float.SIZE / 8;
PGL pgl;
IntBuffer vboName;
FloatBuffer vertData;
void setup() {
size(640, 360, P3D);
createGeometry();
initVBO();
}
void draw() {
background(0);
rotate(frameCount * 0.01, width, height, 0);
pgl = beginPGL();
GL2 gl2 = ((PJOGL)pgl).gl.getGL2();
pgl.bindBuffer(PGL.ARRAY_BUFFER, vboName.get(0));
gl2.glEnableClientState(GL2.GL_VERTEX_ARRAY);
gl2.glEnableClientState(GL2.GL_COLOR_ARRAY);
gl2.glVertexPointer(3, PGL.FLOAT, 7 * SIZEOF_FLOAT, 0);
gl2.glColorPointer(4, PGL.FLOAT, 7 * SIZEOF_FLOAT, 3 * SIZEOF_FLOAT);
pgl.drawArrays(PGL.POINTS, 0, nvert);
gl2.glDisableClientState(GL2.GL_VERTEX_ARRAY);
gl2.glDisableClientState(GL2.GL_COLOR_ARRAY);
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
endPGL();
if (frameCount % 60 == 0) println("fps: " + frameRate);
}
void createGeometry() {
float[] temp = new float[nvert * 7];
for (int n = 0; n < nvert; n++) {
// position
temp[n * 7 + 0] = random(-1500, +1500);
temp[n * 7 + 1] = random(-1500, +1500);
temp[n * 7 + 2] = random(-1500, +1500);
// color
temp[n * 7 + 3] = 1;
temp[n * 7 + 4] = 1;
temp[n * 7 + 5] = 1;
temp[n * 7 + 6] = 1;
}
vertData = allocateDirectFloatBuffer(nvert * 7);
vertData.rewind();
vertData.put(temp);
vertData.position(0);
}
void initVBO() {
vboName = allocateDirectIntBuffer(1);
pgl = beginPGL();
pgl.genBuffers(1, vboName);
pgl.bindBuffer(PGL.ARRAY_BUFFER, vboName.get(0));
pgl.bufferData(PGL.ARRAY_BUFFER, nvert * 7 * SIZEOF_FLOAT, vertData, PGL.STATIC_DRAW);
pgl.bindBuffer(PGL.ARRAY_BUFFER, 0);
endPGL();
}
IntBuffer allocateDirectIntBuffer(int n) {
return ByteBuffer.allocateDirect(n * SIZEOF_INT).order(ByteOrder.nativeOrder()).asIntBuffer();
}
FloatBuffer allocateDirectFloatBuffer(int n) {
return ByteBuffer.allocateDirect(n * SIZEOF_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer();
}
Notice that here you need to obtain the GL2 interface from JOGL, because the vertex and color attributes need to be enabled and configured with the glEnableClientState(), glVertexPointer() and glColorPointer(), which are not part of the GLES 2.0 spec exposed by PGL.