import java.util.logging.Level;
//import java.util.logging.Logger;
//import static komgraf01.KomGraf01.DISPLAY_HEIGHT;
//import static komgraf01.KomGraf01.DISPLAY_WIDTH;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.gluOrtho2D;
public class Create_Line {
public static int DISPLAY_WIDTH=800;
public static int DISPLAY_HEIGHT=600;
public void render() {
glColor3f(1.0f, 0.0f, 1.0f);
glLineWidth(5);
glBegin(GL_LINES);
glVertex2f(100, 100);
glVertex2f(100, 350);
glVertex2f(200, 100);
glVertex2f(300, 350);
glVertex2f(350, 225);
glVertex2f(550, 225);
glEnd();
glFlush();
}
public static void main(String[] args) {
Create_Line main = null;
try {
System.out.println("Keys:");
System.out.println("esc - Exit");
main = new Create_Line();
main.create();
main.run();
} catch (Exception ex) {
// LOGGER.log(Level.SEVERE, ex.toString,ex);
} finally {
if (main != null) {
main.destroy();
}
}
}
private void create() throws LWJGLException {
Display.setDisplayMode(new DisplayMode(DISPLAY_WIDTH, DISPLAY_HEIGHT));
Display.setFullscreen(false);
Display.setTitle("Create Point");
Display.create();
//Keyboard
Keyboard.create();
//Mouse
Mouse.setGrabbed(false);
Mouse.create();
//OpenGL
initGL();
resizeGL(); //To change body of generated methods, choose Tools | Templates.
}
private void run() {
while (!Display.isCloseRequested() && !Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
if (Display.isVisible()) {
render();
} else {
if (Display.isDirty()) {
render();
}
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
}
}
Display.update();
Display.sync(60);
}
}
private void destroy() {
Mouse.destroy();
Keyboard.destroy();
Display.destroy();
}
private void initGL() {
//2D Initialization
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
}
private void resizeGL() {
//2D Scene
glViewport(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0f, DISPLAY_WIDTH, 0.0f, DISPLAY_HEIGHT);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
}
}
Tampilannya sbb:
//import java.util.logging.Logger;
//import static komgraf01.KomGraf01.DISPLAY_HEIGHT;
//import static komgraf01.KomGraf01.DISPLAY_WIDTH;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.util.glu.GLU.gluOrtho2D;
public class Create_Line {
public static int DISPLAY_WIDTH=800;
public static int DISPLAY_HEIGHT=600;
public void render() {
glColor3f(1.0f, 0.0f, 1.0f);
glLineWidth(5);
glBegin(GL_LINES);
glVertex2f(100, 100);
glVertex2f(100, 350);
glVertex2f(200, 100);
glVertex2f(300, 350);
glVertex2f(350, 225);
glVertex2f(550, 225);
glEnd();
glFlush();
}
public static void main(String[] args) {
Create_Line main = null;
try {
System.out.println("Keys:");
System.out.println("esc - Exit");
main = new Create_Line();
main.create();
main.run();
} catch (Exception ex) {
// LOGGER.log(Level.SEVERE, ex.toString,ex);
} finally {
if (main != null) {
main.destroy();
}
}
}
private void create() throws LWJGLException {
Display.setDisplayMode(new DisplayMode(DISPLAY_WIDTH, DISPLAY_HEIGHT));
Display.setFullscreen(false);
Display.setTitle("Create Point");
Display.create();
//Keyboard
Keyboard.create();
//Mouse
Mouse.setGrabbed(false);
Mouse.create();
//OpenGL
initGL();
resizeGL(); //To change body of generated methods, choose Tools | Templates.
}
private void run() {
while (!Display.isCloseRequested() && !Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
if (Display.isVisible()) {
render();
} else {
if (Display.isDirty()) {
render();
}
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
}
}
Display.update();
Display.sync(60);
}
}
private void destroy() {
Mouse.destroy();
Keyboard.destroy();
Display.destroy();
}
private void initGL() {
//2D Initialization
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
}
private void resizeGL() {
//2D Scene
glViewport(0, 0, DISPLAY_WIDTH, DISPLAY_HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0f, DISPLAY_WIDTH, 0.0f, DISPLAY_HEIGHT);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
}
}
Tampilannya sbb:
Tidak ada komentar:
Posting Komentar