我正在尝试使用openGL和processing2.0 2.0库来实现一个点亮的立方体。但是,当我试图从处理库中调用任何照明方法时(lights(),directionalLight()等),当我试图运行它时,我得到了一个空指针错误。下面是方法:
private void render(GLAutoDrawable drawable)
{
GL2 gl = drawable.getGL().getGL2();
//Gets the drawable object which performs the rendering
PGraphics3D pg = new PGraphics3D();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
//Clears the color buffer
pg.directionalLight(51, 102, 126, 0, -1, 0);
pg.ambientLight(51, 102, 126);
pg.specular(204, 102, 0);
pg.ambient(51, 26, 0);
glutSolidCube(1);
// pg.box(1);
}发布于 2013-08-06 15:07:02
您可以使用内置的处理函数使用闪电绘制一个立方体。P3D渲染器内部也使用OpenGL。
float angle = 0.0;
float step = 0.01;
void setup(){
size(400, 400, P3D);
noStroke();
}
void draw(){
background(0);
directionalLight(126, 126, 126, 0, 0, -1);
ambientLight(102, 102, 102);
translate(width/2, height/2, 0);
rotateX(angle*0.1);
rotateY(angle);
angle += step;
box(200);
}https://stackoverflow.com/questions/18048526
复制相似问题