GL.Graphics - Add GLModels after setup || how to do it anyway :)
in
Contributed Library Questions
•
1 year ago
Hello folks,
I've been experimenting with glgraphics because i need to have the models run on the gpu for obvious (speed) reasons but i am quite unsuccesful in my atempts to do so. In the attached code i have a glModel which is made up of class punt(), and is the point you see on the screen but if i try to add more than 1 there's is an "arrayindexoutofboundsexp: 4". Weird thing is, it's always four even when the array is not larger than 2. Why i don't know...
In the code you'll also see i add the point to glmodel inside the class, is it the "correct" way to instantiate the point like that? Create a glModel for every point seems too much, is there a way too create all the points seperate and bind them to a single glModel? Seems much more efficient. Also another question regarding the ammount of points. Can you change this in the draw function or is this a static ammount set only in the setup?
For example what if i have glModel test which is made up of class punt() which holds another class which itself is creating points, will they be automatically added to the glmodel too?
I hope i've been succesfull in explaining the questions. If not i can always try to elaborate :) Thanks for reading/helping (i hope ofcourse),
FRid
Almost forgot; why isn't the color working properly? Should be white right?
I've been experimenting with glgraphics because i need to have the models run on the gpu for obvious (speed) reasons but i am quite unsuccesful in my atempts to do so. In the attached code i have a glModel which is made up of class punt(), and is the point you see on the screen but if i try to add more than 1 there's is an "arrayindexoutofboundsexp: 4". Weird thing is, it's always four even when the array is not larger than 2. Why i don't know...
In the code you'll also see i add the point to glmodel inside the class, is it the "correct" way to instantiate the point like that? Create a glModel for every point seems too much, is there a way too create all the points seperate and bind them to a single glModel? Seems much more efficient. Also another question regarding the ammount of points. Can you change this in the draw function or is this a static ammount set only in the setup?
For example what if i have glModel test which is made up of class punt() which holds another class which itself is creating points, will they be automatically added to the glmodel too?
I hope i've been succesfull in explaining the questions. If not i can always try to elaborate :) Thanks for reading/helping (i hope ofcourse),
FRid
Almost forgot; why isn't the color working properly? Should be white right?
- import processing.opengl.*;
import codeanticode.glgraphics.*;
import peasy.*;
PeasyCam cam;
GLModel test;
int num = 1;
color c = color(255,255,255);
void setup() {
size(500,500,GLConstants.GLGRAPHICS);
cam = new PeasyCam(this, 100);
cam.lookAt(0,0,0);
test = punt();
test.initColors();
test.beginUpdateVertices();
for (int i=0;i<num;i++) {
test.updateVertex(i,0,0,0);
}
test.endUpdateVertices();
test.beginUpdateColors();
for (int i=0;i<num;i++) {
test.updateColor(i,c);
}
test.endUpdateColors();
}
void draw() {
background(100);
GLGraphics renderer = (GLGraphics)g;
renderer.beginGL();
renderer.model(test);
renderer.endGL();
}
//Class---------------------------------------------------------------------------------------------------Class-------------
GLModel punt() {
float x = 0;
float y = 0;
float z = 0;
stroke(255);
point(x,y,z);
GLModel model = new GLModel(this, 1, POINTS, GLModel.DYNAMIC);
return model; //Doesn't really seem right doing this here. Better in the main program?
}
1