New ProjectでKotlin→JVMを選択
Project nameを適当につけてFinish
srcフォルダにktファイルを作成
下記サイトのFirstStepSwing.javaをコピペし、kotlinコードに変換

gradleでjogl-all-mainとgluegen-rt-mainをimplementation
init~dispose関数にoverrideキーワードを追加
dispose関数の中身を削除

〇Hello World
class Renderer : GLEventListener {
override fun init(drawable: GLAutoDrawable?) {}
override fun reshape(drawable: GLAutoDrawable?, x: Int, y:Int, width: Int, height: Int) {}
override fun display(drawable: GLAutoDrawable?) {}
override fun dispose(drawable: GLAutoDrawable?) {}
}

fun main() {
val frameSize = Dimension(300, 300)
val caps = GLCapabilities(GLProfile.get(GLProfile.GL2))
val frame = JFrame().apply {
size = frameSize
}
val panel = GLJPanel(caps).apply {
addGLEventListener(Renderer())
size = frameSize
}
frame.contentPane.add(panel)
frame.isVisible = true
}

・ポリゴン描画
class Renderer : GLEventListener {
override fun init(drawable: GLAutoDrawable?) {
drawable?.let {
val gl = it.gl.gL2
gl.glClearColor(0.0f, 0.0f, 1.0f, 1.0f)
}
}
override fun reshape(drawable: GLAutoDrawable?, x: Int, y: Int, width: Int, height: Int) {}
override fun display(drawable: GLAutoDrawable?) {
drawable?.let {
val gl = it.gl.gL2
gl.glClear(GL2.GL_COLOR_BUFFER_BIT)
gl.glBegin(GL2.GL_POLYGON)
gl.glColor3f(1.0f, 0.0f, 0.0f)
gl.glVertex2f(-0.9f, -0.9f)
gl.glColor3f(0.0f, 1.0f, 0.0f)
gl.glVertex2f(0.9f, -0.9f)
gl.glColor3f(0.0f, 0.0f, 1.0f)
gl.glVertex2f(0.9f, 0.9f)
gl.glColor3f(1.0f, 1.0f, 0.0f)
gl.glVertex2f(-0.9f, 0.9f)
gl.glEnd()
}
}
override fun dispose(drawable: GLAutoDrawable?) {}
}

・テクスチャマッピング
class Renderer : GLEventListener {

private var texture : Texture? = null

override fun init(drawable: GLAutoDrawable?) {
drawable?.let {
val gl = it.gl.gL2
gl.glClearColor(0.0f, 0.0f, 1.0f, 1.0f)
texture = TextureIO.newTexture(File("yutaka.png"), false)
}
}
override fun reshape(drawable: GLAutoDrawable?, x: Int, y: Int, width: Int, height: Int) {}
override fun display(drawable: GLAutoDrawable?) {
drawable?.let {
val gl = it.gl.gL2
gl.glClear(GL2.GL_COLOR_BUFFER_BIT)
gl.glEnable(GL2.GL_TEXTURE_2D)
gl.glBegin(GL2.GL_QUADS);
gl.glTexCoord2f(0.0f, 0.0f)
gl.glVertex2f(-0.9f, -0.9f)
gl.glTexCoord2f(1.0f, 0.0f)
gl.glVertex2f(0.9f, -0.9f)
gl.glTexCoord2f(1.0f, 1.0f)
gl.glVertex2f(0.9f, 0.9f)
gl.glTexCoord2f(0.0f, 1.0f)
gl.glVertex2f(-0.9f, 0.9f)
gl.glEnd()
}
}
override fun dispose(drawable: GLAutoDrawable?) {}
}

・透視投影
import com.jogamp.opengl.*
import com.jogamp.opengl.awt.GLJPanel
import com.jogamp.opengl.glu.GLU
import java.awt.Dimension
import javax.swing.JFrame


class Renderer : GLEventListener {

private var glu : GLU? = null

var vertices = arrayOf(
floatArrayOf(0.0f, 0.0f, 0.0f),
floatArrayOf(1.0f, 0.0f, 0.0f),
floatArrayOf(1.0f, 1.0f, 0.0f),
floatArrayOf(0.0f, 1.0f, 0.0f),
floatArrayOf(0.0f, 0.0f, 1.0f),
floatArrayOf(1.0f, 0.0f, 1.0f),
floatArrayOf(1.0f, 1.0f, 1.0f),
floatArrayOf(0.0f, 1.0f, 1.0f)
)

var edges = arrayOf(
intArrayOf(0, 1),
intArrayOf(1, 2),
intArrayOf(2, 3),
intArrayOf(3, 0),
intArrayOf(4, 5),
intArrayOf(5, 6),
intArrayOf(6, 7),
intArrayOf(7, 4),
intArrayOf(0, 4),
intArrayOf(1, 5),
intArrayOf(2, 6),
intArrayOf(3, 7)
)

override fun init(drawable: GLAutoDrawable?) {
drawable?.let {
val gl = it.gl.gL2
gl.glClearColor(0.0f, 0.0f, 1.0f, 1.0f)
glu = GLU()
}
}
override fun reshape(drawable: GLAutoDrawable?, x: Int, y:Int, width: Int, height: Int) {
drawable?.let {
val gl = it.gl.gL2

gl.glMatrixMode(GL2.GL_PROJECTION)
gl.glLoadIdentity()
glu!!.gluPerspective(30.0, width.toDouble() / height, 1.0, 100.0)
gl.glTranslatef(0.0f, 0.0f, -5.0f)

gl.glMatrixMode(GL2.GL_MODELVIEW)
gl.glLoadIdentity()
glu!!.gluLookAt(3.0f, 4.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f)
}

}
override fun display(drawable: GLAutoDrawable?) {
drawable?.let {
val gl = it.gl.gL2
gl.glClear(GL2.GL_COLOR_BUFFER_BIT)
gl.glBegin(GL2.GL_LINES)
for (edge in edges) {
gl.glVertex3fv(vertices[edge[0]], 0)
gl.glVertex3fv(vertices[edge[1]], 0)
}
gl.glEnd()
}
}
override fun dispose(drawable: GLAutoDrawable?) {}
}


fun main() {

val frameSize = Dimension(300, 300)

val caps = GLCapabilities(GLProfile.get(GLProfile.GL2))
val panel = GLJPanel(caps).apply {
addGLEventListener(Renderer())
size = frameSize
}

val frame = JFrame().apply {
size = frameSize
contentPane.add(panel)
isVisible = true
}
}