I wrote a simple raytracer in Java and displayed the individual pixels using Swing, but Swing was slowing down the application. I am trying to convert it to LWJGL (OpenGL for Java), but I don't know if I am doing it efficiently. I read a Stack Overflow post that said OpenGL wasn't optimized for individual pixels, so what should I use?
Currently, I have something like the following:
public void render() {
glBegin(GL_POINTS);
for (int x = 0; x < width; x ++) {
for (int y = 0; y < height; y++) {
Color c = getPixel(x, y);
glColor3d(c.getR() / 255.0, c.getG() / 255.0, c.getB() / 255.0);
glVertex2f(x, y);
}
}
glEnd();
}
I only know the basics of OpenGL, because this use case is very limited. I am not sure if this is the best way or if I can use something like a raster to make it faster (performance is critical, as this renders at least a million pixels).