Multiple GLModel render
in
Contributed Library Questions
•
1 year ago
Hey there,
I have a little questions about GLModel rendering with GLGraphics library (I'm using Processing 1.5.1).
I have 3 GLModels, one with a bunch of cubes, one with lines and a last one is a point cloud. They all have their own colors and alpha. If I render them all together without lighting, everything seems to be just fine, but once I enable one light, then it seems like only one of the model is lighted correctly and the colors and alpha values of the other 2 ones are completely ignored.
The code looks something like that:
I've checked that article http://www.sjbaker.org/steve/omniv/opengl_lighting.html about openGL color and I understand the overall logic, but I can't seem to figure out what's the pb here... Do I need to assign one light per model? Any help on that would be great.
Thanks!
I have a little questions about GLModel rendering with GLGraphics library (I'm using Processing 1.5.1).
I have 3 GLModels, one with a bunch of cubes, one with lines and a last one is a point cloud. They all have their own colors and alpha. If I render them all together without lighting, everything seems to be just fine, but once I enable one light, then it seems like only one of the model is lighted correctly and the colors and alpha values of the other 2 ones are completely ignored.
The code looks something like that:
- // GLGraphic rendering
GLGraphics renderer = (GLGraphics)g;
renderer.beginGL();
background(0);
// Render Lights
float lightX = map(mouseX, 0, width, 640, 0);
float lightY = map(mouseY, 0, height, 0, 480);
float lightZ = 800;
if (lightType == 0) {
renderer.ambientLight(255, 255, 255, lightX, lightY, lightZ);
} else if (lightType == 1) {
float dirX = lightX;
float dirY = lightY;
float dirZ = 0 + lightZ;
float n = sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);
dirX /= n;
dirY /= n;
dirZ /= n;
renderer.directionalLight(255, 255, 255, -dirX, -dirY, dirZ);
} else if (lightType == 2) {
renderer.pointLight(51, 102, 126, lightX, lightY, lightZ);
} else if (lightType == 3) {
float dirX = lightX;
float dirY = lightY;
float dirZ = 0 + lightZ;
float n = sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);
dirX /= n;
dirY /= n;
dirZ /= n;
renderer.spotLight(255, 255, 255, lightX, lightY, lightZ, dirX, dirY, dirZ, 2*PI, 40);
}
// Render Models
cubes.render();
pointCloud.render();
linesModel.render();
renderer.endGL();
I've checked that article http://www.sjbaker.org/steve/omniv/opengl_lighting.html about openGL color and I understand the overall logic, but I can't seem to figure out what's the pb here... Do I need to assign one light per model? Any help on that would be great.
Thanks!
1