feat: meilleurs affichage
This commit is contained in:
parent
f5ac6b8172
commit
df59522366
|
@ -58,6 +58,27 @@ public class Rasterizer {
|
||||||
f.setPosition(f.getY(), f.getX());
|
f.setPosition(f.getY(), f.getX());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void rasterizeVertice(Fragment v1, Fragment v2) {
|
||||||
|
/* Coordinates of V1 and V2 */
|
||||||
|
int x1 = v1.getX();
|
||||||
|
int y1 = v1.getY();
|
||||||
|
int x2 = v2.getX();
|
||||||
|
int y2 = v2.getY();
|
||||||
|
|
||||||
|
/* For now : just display the vertices */
|
||||||
|
Fragment f = new Fragment(0, 0);
|
||||||
|
int size = 2;
|
||||||
|
for (int i = 0; i < v1.getNumAttributes(); i++) {
|
||||||
|
f.setAttribute(i, v1.getAttribute(i));
|
||||||
|
}
|
||||||
|
for (int i = -size; i <= size; i++) {
|
||||||
|
for (int j = -size; j <= size; j++) {
|
||||||
|
f.setPosition(x1 + i, y1 + j);
|
||||||
|
shader.shade(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rasterizes the edge between the projected vectors v1 and v2.
|
* Rasterizes the edge between the projected vectors v1 and v2.
|
||||||
* Generates Fragment's and calls the Shader::shade() metho on each of them.
|
* Generates Fragment's and calls the Shader::shade() metho on each of them.
|
||||||
|
@ -70,19 +91,6 @@ public class Rasterizer {
|
||||||
int x2 = v2.getX();
|
int x2 = v2.getX();
|
||||||
int y2 = v2.getY();
|
int y2 = v2.getY();
|
||||||
|
|
||||||
// /* For now : just display the vertices */
|
|
||||||
// Fragment f = new Fragment(0, 0);
|
|
||||||
// int size = 2;
|
|
||||||
// for (int i = 0; i < v1.getNumAttributes(); i++) {
|
|
||||||
// f.setAttribute(i, v1.getAttribute(i));
|
|
||||||
// }
|
|
||||||
// for (int i = -size; i <= size; i++) {
|
|
||||||
// for (int j = -size; j <= size; j++) {
|
|
||||||
// f.setPosition(x1 + i, y1 + j);
|
|
||||||
// shader.shade(f);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// tracé d'un segment avec l'algo de Bresenham
|
// tracé d'un segment avec l'algo de Bresenham
|
||||||
Fragment fragment = new Fragment(0, 0); // , numAttributes);
|
Fragment fragment = new Fragment(0, 0); // , numAttributes);
|
||||||
|
|
||||||
|
|
|
@ -23,10 +23,9 @@ public class Renderer {
|
||||||
mesh = new Mesh(scene.getMeshFileName());
|
mesh = new Mesh(scene.getMeshFileName());
|
||||||
screen = new GraphicsWrapper(scene.getScreenW(), scene.getScreenH());
|
screen = new GraphicsWrapper(scene.getScreenW(), scene.getScreenH());
|
||||||
screen.clearBuffer();
|
screen.clearBuffer();
|
||||||
// shader = new SimpleShader(screen);
|
shader = new SimpleShader(screen);
|
||||||
shader = new PainterShader(screen);
|
// rasterizer = new PerspectiveCorrectRasterizer(shader);
|
||||||
rasterizer = new PerspectiveCorrectRasterizer(shader);
|
rasterizer = new Rasterizer(shader);
|
||||||
// rasterizer = new Rasterizer(shader);
|
|
||||||
|
|
||||||
xform = new Transformation();
|
xform = new Transformation();
|
||||||
xform.setLookAt(scene.getCameraPosition(), scene.getCameraLookAt(), scene.getCameraUp());
|
xform.setLookAt(scene.getCameraPosition(), scene.getCameraLookAt(), scene.getCameraUp());
|
||||||
|
@ -89,6 +88,20 @@ public class Renderer {
|
||||||
return fragments;
|
return fragments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void renderVertices() {
|
||||||
|
Fragment[] fragment = projectVertices();
|
||||||
|
int[] faces = mesh.getFaces();
|
||||||
|
|
||||||
|
for (int i = 0; i < 3 * mesh.getNumFaces(); i += 3) {
|
||||||
|
for (int j = 0; j < 3; j++) {
|
||||||
|
Fragment v1 = fragment[faces[i + j]];
|
||||||
|
Fragment v2 = fragment[faces[i + ((j + 1) % 3)]];
|
||||||
|
rasterizer.rasterizeVertice(v1, v2);
|
||||||
|
screen.repaint(); // on refresh l'écran
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void renderWireframe() {
|
static void renderWireframe() {
|
||||||
Fragment[] fragment = projectVertices();
|
Fragment[] fragment = projectVertices();
|
||||||
int[] faces = mesh.getFaces();
|
int[] faces = mesh.getFaces();
|
||||||
|
@ -142,16 +155,28 @@ public class Renderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* vertice rendering */
|
||||||
|
renderVertices();
|
||||||
|
wait(1);
|
||||||
|
|
||||||
/* wireframe rendering */
|
/* wireframe rendering */
|
||||||
renderWireframe();
|
renderWireframe();
|
||||||
// screen.swapBuffers();
|
|
||||||
wait(1);
|
wait(1);
|
||||||
|
|
||||||
/* solid rendering, no lighting */
|
/* solid rendering, no lighting */
|
||||||
|
shader = new SimpleShader(screen);
|
||||||
|
rasterizer = new Rasterizer(shader);
|
||||||
|
screen.clearBuffer();
|
||||||
|
shader.reset();
|
||||||
|
renderSolid();
|
||||||
|
wait(1);
|
||||||
|
|
||||||
|
/* solid rendering, no lighting */
|
||||||
|
shader = new PainterShader(screen);
|
||||||
|
rasterizer = new Rasterizer(shader);
|
||||||
screen.clearBuffer();
|
screen.clearBuffer();
|
||||||
shader.reset();
|
shader.reset();
|
||||||
renderSolid();
|
renderSolid();
|
||||||
screen.swapBuffers();
|
|
||||||
wait(1);
|
wait(1);
|
||||||
|
|
||||||
/* solid rendering, with lighting */
|
/* solid rendering, with lighting */
|
||||||
|
@ -159,20 +184,32 @@ public class Renderer {
|
||||||
shader.reset();
|
shader.reset();
|
||||||
setLightingEnabled(true);
|
setLightingEnabled(true);
|
||||||
renderSolid();
|
renderSolid();
|
||||||
screen.swapBuffers();
|
|
||||||
wait(1);
|
wait(1);
|
||||||
|
|
||||||
/* solid rendering, with texture */
|
/* création du texture shader */
|
||||||
screen.clearBuffer();
|
|
||||||
TextureShader texShader = new TextureShader(screen);
|
TextureShader texShader = new TextureShader(screen);
|
||||||
texShader.setTexture("data/brick.jpg");
|
texShader.setTexture("data/brick.jpg");
|
||||||
shader = texShader;
|
shader = texShader;
|
||||||
|
|
||||||
|
/* solid rendering, with texture */
|
||||||
|
rasterizer = new Rasterizer(shader);
|
||||||
|
screen.clearBuffer();
|
||||||
|
shader.reset();
|
||||||
rasterizer.setShader(texShader);
|
rasterizer.setShader(texShader);
|
||||||
setLightingEnabled(true);
|
setLightingEnabled(true);
|
||||||
renderSolid();
|
renderSolid();
|
||||||
screen.swapBuffers();
|
|
||||||
wait(1);
|
wait(1);
|
||||||
|
|
||||||
|
/* solid rendering, with texture */
|
||||||
|
rasterizer = new PerspectiveCorrectRasterizer(shader);
|
||||||
|
screen.clearBuffer();
|
||||||
|
shader.reset();
|
||||||
|
rasterizer.setShader(texShader);
|
||||||
|
setLightingEnabled(true);
|
||||||
|
renderSolid();
|
||||||
|
wait(1);
|
||||||
|
|
||||||
|
// on attend un peu avant de fermer la fenêtre
|
||||||
wait(60);
|
wait(60);
|
||||||
screen.destroy();
|
screen.destroy();
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
|
|
Loading…
Reference in a new issue