Hello everyone!
I’m try understand how to make architecture classes with OpenGLView. But… Have some troubles in it.
In example, class View3D (OpenGLView):
package;
import openfl.display.OpenGLView;
import openfl.display.Sprite;
import openfl.geom.Rectangle;
import openfl.gl.*;
class View3D {
private var view:OpenGLView;
private var objects:Array<Object3D>;
public function new(layer:Sprite) {
if (OpenGLView.isSupported) {
view = new OpenGLView();
GL.enable(GL.DEPTH_TEST);
GL.depthFunc(GL.LEQUAL);
view.render = _render;
layer.addChild(view);
}
}
public function add(object:Object3D):Void {
if (objects == null) objects = [];
objects.push(object);
}
private function _render(rect:Rectangle):Void {
_update();
GL.viewport(Std.int(rect.x), Std.int(rect.y), Std.int(rect.width), Std.int(rect.height));
GL.clearColor(0.0, 0.0, 0.0, 1.0);
GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT);
//render objects:
if (objects != null) {
for (i in 0...objects.length) {
objects[i].render();
}
}
}
private function _update():Void {
//Time to make anything.
}
}
Question. What i need realize in class Object3D? In example, Object3D is realize the cube. Then i need func for initialize buffer/texture and render func for calls from View3D. Need to create a shader program in Object3D (or it’s need make in View3D)?
I want to make 3D scene and just create any primitives to adding on scene.
view3d.add(new Object3D());
Some like this. May be the question is not clearly. Sorry for my english.
I understand how to draw primitives (in single class Main), but I want to split all tasks on the classes.