You are on page 1of 3

public void render() {

glClear(GL_COLOR_BUFFER_BIT);//menghapus layar
glColor3f(1.0f,0.0f,0.0f);
glLineWidth(5);
glBegin(GL_LINE_LOOP);//objek garis
glVertex2d(200, 200); // koordinat x dan y
glVertex2d(600, 200);
glVertex2d(200, 325);
glVertex2d(600, 325);
glVertex2d(200, 450);
glVertex2d(600, 450);
glEnd();
glFlush();
}

void initGL() {
glClearColor(0.0f, 1.0f, 1.0f, 1.0f);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
}
public 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();
}
public 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);
}
}

public void destroy() {


Mouse.destroy();
Keyboard.destroy();
//Display.destroy();
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Grafik02 main=null;
try{
main=new Grafik02();
main.create();
main.run();
}catch(Exception ex){
Logger.getLogger(Create_Line.class.getName()).log(Level.SEVERE,null,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("Struktur Dasar OpenGL dan LWJGL");
Display.create();
//keyboard
Keyboard.create();
//mouse
Mouse.setGrabbed(false);
Mouse.create();
//OpenGL
initGL();
resizeGL();
//untuk change body of generated methhods, choose tools | templates.
}

public static final int DISPLAY_HEIGHT=480;


public static final int DISPLAY_WIDTH=640;
public render(){
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f,0.0f,0.0f);
glLineWidth(5);
glBegin(GL_LINE_LOOP);//objek garis
glVertex2d(200, 200); // koordinat x dan y
glVertex2d(600, 200);
glVertex2d(200, 325);
glVertex2d(600, 325);
glVertex2d(200, 450);
glVertex2d(600, 450);
glEnd();
glFlush();
}

public static void main(String[]args){


Grafik02 main=null;
try{
main = new Grafik02();
main.create();
main.run();
}catch(Exception ex){
Logger.getLogger(Create_Line.class.getName()).log(Level.SEVERE,null,ex);
}