-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMain.java
More file actions
53 lines (45 loc) · 1.95 KB
/
Main.java
File metadata and controls
53 lines (45 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.awt.*;
import java.io.IOException;
import model.math.Vec3f;
import model.pipeline.programmable.*;
import model.pipeline.programmable.shaderUtilities.CommonTransformations;
import model.pipeline.programmable.shaderUtilities.lighting.Light;
import model.pipeline.programmable.shaderUtilities.lighting.LightShader;
import controller.renderer.*;
import view.Window;
import static model.math.VecOperator.*;
import static model.pipeline.programmable.shaderUtilities.CommonTransformations.updateMatrices;
public class Main {
public static void main(String[] args) throws IOException {
// init renderer
Renderer myRenderer = new Renderer(pix_width, pix_height);
myRenderer.setShader(new PhongShader());
Window myWindow = new Window("Java Rasterizer", myRenderer);
// default global light settings
Light wlight = new Light();
wlight.lightColor = new Color(255, 255, 0);
wlight.position = new Vec3f(1.0f, 1.45f, 0.f);
LightShader.addLight(wlight);
// TODO structure : make breaking of while loop dependent on user input
// render loop
while (true) {
long start = System.nanoTime();
// clear buffers at the beginning of the frame
myRenderer.clearDepthBuffer();
myRenderer.clearColorBuffer(new Color(50, 50, 50));
// upate global geometric variables
updateMatrices();
// do the magic
myRenderer.renderModel();
// write to the buffer after doing all processing.
// avoid writing multiple times per frame as tearing happens.
myRenderer.writePixelBuffer();
myWindow.update();
long time = System.nanoTime() - start;
// System.out.println("processing time : " + (((double) time / 1_000_000) +
// "ms/frame"));
}
}
public static final int pix_height = 350;
public static final int pix_width = 350;
}