If I switch GL_QUADS to GL_TRIANGLES and remove the last point, the triangle renders fine.
However, changing it back to GL_QUADS and adding another point just leaves me with a black screen. So what do I do?
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;
public class Main {
public Main() {
this.start();
}
private void start() {
try {
Display.setDisplayMode(new DisplayMode(640,640));
Display.setTitle("FPSTest");
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
}
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(-10, 10, -10, 10, -1000, 1000);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
while (!Display.isCloseRequested()) {
GL11.glClear(GL11.GL_DEPTH_BUFFER_BIT|GL11.GL_COLOR_BUFFER_BIT);
GL11.glRotatef(0, 1, 1, 1);
GL11.glBegin(GL11.GL_QUADS);
// GL11.glBegin(GL11.GL_TRIANGLES);
{
GL11.glColor3f(1.0f, 0.0f, 0.0f);
GL11.glVertex3f(0.0f, 3.0f, 0.0f);
GL11.glColor3f(0.0f, 1.0f, 0.0f);
GL11.glVertex3f(0.0f, 0.0f, -3.0f);
GL11.glColor3f(0.0f, 0.0f, 1.0f);
GL11.glVertex3f(3.0f, 0.0f, 0.0f);
GL11.glColor3f(0.0f, 1.0f, 0.0f);
GL11.glVertex3f(0.0f, 0.0f, 3.0f);
}
GL11.glEnd();
GL11.glLoadIdentity();
Display.update();
}
Display.destroy();
}
public static void main(String[] argv) {
new Main();
}
}
The vertices of a quad must be coplanar. The four vertices you specified are not, and according to this, the results are undefined in this case (which is probably the reason for the blank screen).
Here’s a tool to help you find the plane equation, so you can choose a coplanar 4th point. Your first 3 points form the equation
-9x -9y +9z + 27 = 0, so one example of a suitable point is: