Alright, so I started learning LWJGL through a few tutorials of TheCodingUniverse, but I've hit a wall at drawing lines and quads.
The code
package LWJGL_Learn;
import static org.lwjgl.opengl.GL11.*;
import org.lwjgl.opengl.*;
import org.lwjgl.*;
public class SimpleOGLRenderer {
public SimpleOGLRenderer() {
try {
Display.setDisplayMode(new DisplayMode(640, 480));
Display.setTitle("SimpleOGLRenderer");
//Display.setInitialBackground(256, 256, 256);
Display.create();
} catch (LWJGLException e) {
e.printStackTrace();
}
//OpenGL Initialization
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 640, 480, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
while (!Display.isCloseRequested()) {
//Render Code'
glBegin(GL_QUADS);
glVertex2i(50, 50);
glVertex2i(80, 70);
glVertex2i(80, 130);
glVertex2i(50, 300);
glEnd();
glBegin(GL_LINES);
glVertex2i(100, 100);
glVertex2i(200, 200);
glEnd();
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
Display.update();
Display.sync(60);
}
Display.destroy();
System.exit(0);
}
public static void main(String[] args) {
new SimpleOGLRenderer();
}
}
Refer to around 6:50 minutes in this video to see what the code is supposed to be, and what its supposed to do.
Anyway, the problem is that no lines or quads show up. The screen stays black. Now, I thought maybe it was because black lines were being drawn on a black display so I modified the background color (the commented out line which went like .setInitialDisplay...
), but with no result. The color changed, but the screen stayed white and no lines appeared. Do any of you guys know what I'm doing wrong?
1) The default color is white, but you are clearing the color buffer right before doing the Display.update() remove:
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
2) You're not using the coordinates from the video, right before 6:50.