ŏ Oni vO

hLg̖ڎ


ŏ Oni vO OpenWindow.java łB ͉ʂɔOp``vOłB sƈȉ̂悤ȉʂ\܂Bq L[ƏI܂B

OpenWindow screen

ȉǂẴ\[XR[hĂ܂B


OpenWindow NXs

ȉAWindows Iy[eBOVXeŎs@łB ܂Aȉ̏KvłB

  1. Java 2 SDK CXg[Ă
  2. Oni Java ^C oni.jar -classpathŎsɓǂݍ܂悤ɂȂĂ
  3. Oni ̕tDLL(gl.dllAgrt.dll) fBNgPATHݒ肷铙ADLLǂݍ߂悤ɂȂĂ

Oni vO OpenWindow RpCɎsꍇ͈ȉ̂悤ȃR}hs܂B

> java oni.runtime.OniRuntime OpenWindow
ʏ Java vO̎sƈႢ oni.runtime.OniRuntime NXNA ̈ɎsNXn\ɂȂĂ܂B

import


import oni.runtime.OniRuntime;
import oni.runtime.Application;
import oni.gfx.GLGraphics;
import oni.gfx.GLConstants;
import oni.gfx.PixelFormat;
import oni.runtime.event.KeyListener;
import oni.runtime.event.KeyEvent;

ŏ Oni ʼnʂNXC|[gĂ܂B ŗpĂ Oni pbP[W͈ȉ̂悤ɂȂ܂B


Application C^tF[X


public class OpenWindow implements Application {
    private int width = 640;
    private int height = 480;

    public void oniMain(OniRuntime oniRuntime, String[] args) {
        ...
    }
    
    public void initGraphics(GLGraphics glGraphics) {
        ...
    }
    
    public void update(GLGraphics glGraphics) {
        ...
    }
}

Oni ŋNNX oni.runtime.Application C^tF[XȂĂ͂܂B ̃NX̖RXgN^ new łKv܂B oni.runtime.Application ŎȂĂ͂Ȃ\bh 3 ‚܂B

oniMain \bh

public void oniMain(OniRuntime oniRuntime, String[] args) {

    oniRuntime.addKeyListener(new DemoKeyListener(oniRuntime));
    oniRuntime.createWindow("your first KEEL program", width, height);
    oniRuntime.createGraphicsWithDefaultPixelFormat();

    oniRuntime.run();

    System.out.println("Never called.");
}

̃vOł͈ȉ̂ƂsĂ܂B

  1. L[̓Cxg oni.runtime.event.KeyListener IuWFNgݒ肷
  2. EBhẼ^CgAʂ̃TCYݒ肷
  3. ftHg̃fBXvC̕`ݒ oni.gfx.PixelFormat ݒ肷

Application NXNƍŏɂ̃\bhĂяo܂B oni.runtime.OniRuntime ͉ʂァ御すNXナロに果れ合AOniRuntime フイX^XoA Kvワ OniRuntime CX^Xノ対Fン棚 run \bhトべば果ワvOナは run \bhトばれた轤サネ降フ碧は進゛とま


initGraphicsAupdate \bh`


public void initGraphics(GLGraphics glGraphics) {
    glGraphics.glOrtho(0, width, 0, height, -1, 1);
    glGraphics.glScalef(1.0f, -1.0f, 1.0f);
    glGraphics.glTranslatef(0, -height, 0);
}

public void update(GLGraphics glGraphics) {
    glGraphics.glClear(GLConstants.GL_COLOR_BUFFER_BIT);
    drawTriangle(glGraphics);
    glGraphics.glFlush();
}

public void quitRequested() {

}

private void drawTriangle(GLGraphics glGraphics) {
    int topY = height / 3;
    int bottomY = (height / 3) * 2;
    int centerX = width / 2;
    int leftX = width / 3;
    int rightX = (width / 3) * 2;
    
    glGraphics.glBegin(GLConstants.GL_TRIANGLES);
    
    glGraphics.glColor3f(1.0f, 1.0f, 1.0f);
    
    glGraphics.glVertex2i(leftX, bottomY);
    glGraphics.glVertex2i(rightX, bottomY);
    glGraphics.glVertex2i(centerX, topY);
    
    glGraphics.glEnd();
}

フプOナinitGraphics \bhł̓OtBbNX̍W̒`(0, 0)A E(width, height)ƂEBhE̍WɂȂ悤ύXĂ܂B update \bhł͉ʂNAĂAOp`ʂĂ܂B

initGraphics A update \bhł oni.gfx.GLGraphics IuWFNgn܂BGLGraphicsIuWFNgł OpenGL vO~OƓ悤ɃvO~O邱Ƃ”\łB

quitRequested \bh͏IƂɌĂ΂郁\bhłB ł͉Ă܂B


KeyListener C^tF[X`


class DemoKeyListener implements KeyListener {
    public DemoKeyListener(OniRuntime aOniRuntime) {
        oniRuntime = aOniRuntime;
    }
    
    public void keyTyped(KeyEvent event) {
        System.out.println(event);
    }
    
    public void keyPressed(KeyEvent event) {
        System.out.println(event);
        if (event.getKeyCode() == KeyEvent.VK_Q) {
            oniRuntime.disposeDisplay();
            System.exit(0);
        }
    }
    
    public void keyReleased(KeyEvent event) {
        System.out.println(event);
    }
    
    private OniRuntime oniRuntime;
}

oni.runtime.event.KeyListener C^tF[X OniRuntime CX^Xɓo^邱Ƃœ͂ꂽL[{[h̃Cxg邱Ƃ”\łB ł͂ꂼ̃L[Cxgœnꂽ oni.runtime.event.KeyEvent IuWFNgWo͂ɏoĂ܂BăL[{[h 'q' ͂ꂽ ʂ‚ăvOI悤ɂĂ܂B




Copyright © 2001-2002 CyberStep, Inc. All Rights Reserved.

Oni \tgEFA