'Optimized way to display individual pixels in LWJGL/OpenGL
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).
Solution 1:[1]
use texture and stream the data to the texture and render that texture. try to stream as many pixel values to the texture at once (System.arraycopy etc)
In addition, if you are really serious about the performance, you need to use modern OpenGL at least OpenGL version 3. problem for you is that your code no longer works and learning curve is quite steep.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | obakestar |
