Dim pcamx# = 0
Dim pcamy# = 0
Dim pcamz# = 4
'variabel untuk posisi titik pandang
Dim prefx# = 0
Dim prefy# = 0
Dim prefz# = 0
'variabel perpindahan
Dim pindah# = 0.01
'variabel tekstur
Dim teksturkayu
teksturkayu = loadmipmaptexture("images.jpg")
glEnable(GL_TEXTURE_2D)
while true
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
gluLookAt(pcamx#, pcamy#, pcamz#, prefx#, prefy#, prefz#, 0, 1, 0)
glBindTexture(GL_TEXTURE_2D, teksturkayu)
glBegin (GL_QUADS) 'sisi belakang
'glColor3f(1.0, 0.0, 0.0)
glTexCoord2f(1,1)
glVertex3f(1.0, 2.0, -1.0) 'kanan atas
'glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(1,0)
glVertex3f(1.0, -2.0, -1.0) 'kanan bawah
'glColor3f(0.0, 0.0, 1.0)
glTexCoord2f(0,0)
glVertex3f(-1.0, -2.0, -1.0) 'kiri bawah
'glColor3f(1.0, 0.0, 1.0)
glTexCoord2f(0,1)
glVertex3f(-1.0, 2.0, -1.0) 'kiri atas
glEnd()
glBegin (GL_QUADS) 'sisi depan
'glColor3f(1.0, 0.0, 0.0)
glTexCoord2f(1,1)
glVertex3f(1.0, 2.0, 1.0) 'kanan atas
'glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(1,0)
glVertex3f(1.0, -2.0, 1.0) 'kanan bawah
'glColor3f(0.0, 0.0, 1.0)
glTexCoord2f(0,0)
glVertex3f(-1.0, -2.0, 1.0) 'kiri bawah
'glColor3f(1.0, 0.0, 1.0)
glTexCoord2f(0,1)
glVertex3f(-1.0, 2.0, 1.0) 'kiri atas
glEnd()
glBegin (GL_QUADS) 'sisi kiri
'glColor3f(1.0, 0.0, 0.0)
glTexCoord2f(0,1)
glVertex3f(-1.0, 2.0, -1.0)
'glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(1,1)
glVertex3f(-1.0, 2.0, 1.0)
'glColor3f(0.0, 0.0, 1.0)
glTexCoord2f(1,0)
glVertex3f(-1.0, -2.0, 1.0)
'glColor3f(1.0, 0.0, 1.0)
glTexCoord2f(0,0)
glVertex3f(-1.0, -2.0, -1.0)
glEnd()
glBegin (GL_QUADS) 'sisi kanan
'glColor3f(1.0, 0.0, 0.0)
glTexCoord2f(0,1)
glVertex3f(1.0, 2.0, -1.0)
'glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(1,1)
glVertex3f(1.0, 2.0, 1.0)
'glColor3f(0.0, 0.0, 1.0)
glTexCoord2f(1,0)
glVertex3f(1.0, -2.0, 1.0)
'glColor3f(1.0, 0.0, 1.0)
glTexCoord2f(0,0)
glVertex3f(1.0, -2.0, -1.0)
glEnd()
glBegin (GL_QUADS) 'sisi bawah
'glColor3f(1.0, 0.0, 0.0)
glTexCoord2f(1,0)
glVertex3f(1.0, -2.0, 1.0)
'glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(1,1)
glVertex3f(1.0, -2.0, -1.0)
'glColor3f(0.0, 0.0, 1.0)
glTexCoord2f(0,1)
glVertex3f(-1.0, -2.0, -1.0)
'glColor3f(1.0, 0.0, 1.0)
glTexCoord2f(0,0)
glVertex3f(-1.0, -2.0, 1.0)
glEnd()
'kubus atas'
glBegin (GL_QUADS) 'sisi belakang
'glColor3f(1.0, 0.0, 0.0)
glTexCoord2f(1,1)
glVertex3f(1.0, 1.0, -1.0) 'kanan atas
'glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(1,0)
glVertex3f(1.0, -1.0, -1.0) 'kanan bawah
'glColor3f(0.0, 0.0, 1.0)
glTexCoord2f(0,0)
glVertex3f(-1.0, -1.0, -1.0) 'kiri bawah
'glColor3f(1.0, 0.0, 1.0)
glTexCoord2f(0,1)
glVertex3f(-1.0, 1.0, -1.0) 'kiri atas
glEnd()
glBegin (GL_QUADS) 'sisi depan
'glColor3f(1.0, 0.0, 0.0)
glTexCoord2f(1,1)
glVertex3f(1.0, 1.0, 1.0) 'kanan atas
'glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(1,0)
glVertex3f(1.0, -1.0, 1.0) 'kanan bawah
'glColor3f(0.0, 0.0, 1.0)
glTexCoord2f(0,0)
glVertex3f(-1.0, -1.0, 1.0) 'kiri bawah
'glColor3f(1.0, 0.0, 1.0)
glTexCoord2f(0,1)
glVertex3f(-1.0, 1.0, 1.0) 'kiri atas
glEnd()
glBegin (GL_QUADS) 'sisi kiri
'glColor3f(1.0, 0.0, 0.0)
glTexCoord2f(0,1)
glVertex3f(-1.0, 1.0, -1.0)
'glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(1,1)
glVertex3f(-1.0, 1.0, 1.0)
'glColor3f(0.0, 0.0, 1.0)
glTexCoord2f(1,0)
glVertex3f(-1.0, -1.0, 1.0)
'glColor3f(1.0, 0.0, 1.0)
glTexCoord2f(0,0)
glVertex3f(-1.0, -1.0, -1.0)
glEnd()
glBegin (GL_QUADS) 'sisi kanan
'glColor3f(1.0, 0.0, 0.0)
glTexCoord2f(0,1)
glVertex3f(1.0, 1.0, -1.0)
'glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(1,1)
glVertex3f(1.0, 1.0, 1.0)
'glColor3f(0.0, 0.0, 1.0)
glTexCoord2f(1,0)
glVertex3f(1.0, -1.0, 1.0)
'glColor3f(1.0, 0.0, 1.0)
glTexCoord2f(0,0)
glVertex3f(1.0, -1.0, -1.0)
glEnd()
glBegin (GL_QUADS) 'sisi bawah1
'glColor3f(1.0, 0.0, 0.0)
glTexCoord2f(1,0)
glVertex3f(2.0, 2.0, 2.0)
'glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(1,1)
glVertex3f(2.0, 2.0, -2.0)
'glColor3f(0.0, 0.0, 1.0)
glTexCoord2f(0,1)
glVertex3f(-2.0, 2.0, -2.0)
'glColor3f(1.0, 0.0, 1.0)
glTexCoord2f(0,0)
glVertex3f(-2.0, 2.0, 2.0)
glEnd()
glBegin (GL_QUADS) 'sisi depan1
'glColor3f(1.0, 0.0, 0.0)
glTexCoord2f(1,1)
glVertex3f(2.0, 2.0, 2.0) 'kanan atas
'glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(1,0)
glVertex3f(-2.0, 2.0, 2.0) 'kanan bawah
'glColor3f(0.0, 0.0, 1.0)
glTexCoord2f(0,0)
glVertex3f(-2.0, 1.0, 2.0) 'kiri bawah
'glColor3f(1.0, 0.0, 1.0)
glTexCoord2f(0,1)
glVertex3f(2.0, 1.0, 2.0) 'kiri atas
glEnd()
glBegin (GL_QUADS) 'sisi belakang1
'glColor3f(1.0, 0.0, 0.0)
glTexCoord2f(1,1)
glVertex3f(2.0, 2.0, -2.0) 'kanan atas
'glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(1,0)
glVertex3f(-2.0, 2.0, -2.0) 'kanan bawah
'glColor3f(0.0, 0.0, 1.0)
glTexCoord2f(0,0)
glVertex3f(-2.0, 1.0, -2.0) 'kiri bawah
'glColor3f(1.0, 0.0, 1.0)
glTexCoord2f(0,1)
glVertex3f(2.0, 1.0, -2.0) 'kiri atas
glEnd()
glBegin (GL_QUADS) 'sisi kiri1
'glColor3f(1.0, 0.0, 0.0)
glTexCoord2f(0,1)
glVertex3f(-2.0, 2.0, 2.0)
'glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(1,1)
glVertex3f(-2.0, 2.0, -2.0)
'glColor3f(0.0, 0.0, 1.0)
glTexCoord2f(1,0)
glVertex3f(-2.0, 1.0, -2.0)
'glColor3f(1.0, 0.0, 1.0)
glTexCoord2f(0,0)
glVertex3f(-2.0, 1.0, 2.0)
glEnd()
glBegin (GL_QUADS) 'sisi kanan1
'glColor3f(1.0, 0.0, 0.0)
glTexCoord2f(0,1)
glVertex3f(2.0, 2.0, 2.0)
'glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(1,1)
glVertex3f(2.0, 2.0, -2.0)
'glColor3f(0.0, 0.0, 1.0)
glTexCoord2f(1,0)
glVertex3f(2.0, 1.0, -2.0)
'glColor3f(1.0, 0.0, 1.0)
glTexCoord2f(0,0)
glVertex3f(2.0, 1.0, 2.0)
glEnd()
glBegin (GL_QUADS) 'sisi bawah
'glColor3f(1.0, 0.0, 0.0)
glTexCoord2f(1,0)
glVertex3f(2.0, 1.0, 2.0)
'glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(1,1)
glVertex3f(2.0, 1.0, -2.0)
'glColor3f(0.0, 0.0, 1.0)
glTexCoord2f(0,1)
glVertex3f(-2.0, 1.0, -2.0)
'glColor3f(1.0, 0.0, 1.0)
glTexCoord2f(0,0)
glVertex3f(-2.0, 1.0, 2.0)
glEnd()
glBegin (GL_QUADS) 'sisi belakang
'glColor3f(1.0, 0.0, 0.0)
glTexCoord2f(1,1)
glVertex3f(1.0, 1.0, -1.0) 'kanan atas
'glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(1,0)
glVertex3f(1.0, -1.0, -1.0) 'kanan bawah
'glColor3f(0.0, 0.0, 1.0)
glTexCoord2f(0,0)
glVertex3f(-1.0, -1.0, -1.0) 'kiri bawah
'glColor3f(1.0, 0.0, 1.0)
glTexCoord2f(0,1)
glVertex3f(-1.0, 1.0, -1.0) 'kiri atas
glEnd()
glBegin (GL_QUADS) 'sisi depan
'glColor3f(1.0, 0.0, 0.0)
glTexCoord2f(1,1)
glVertex3f(1.0, 1.0, 1.0) 'kanan atas
'glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(1,0)
glVertex3f(1.0, -1.0, 1.0) 'kanan bawah
'glColor3f(0.0, 0.0, 1.0)
glTexCoord2f(0,0)
glVertex3f(-1.0, -1.0, 1.0) 'kiri bawah
'glColor3f(1.0, 0.0, 1.0)
glTexCoord2f(0,1)
glVertex3f(-1.0, 1.0, 1.0) 'kiri atas
glEnd()
glBegin (GL_QUADS) 'sisi kiri
'glColor3f(1.0, 0.0, 0.0)
glTexCoord2f(0,1)
glVertex3f(-1.0, 1.0, -1.0)
'glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(1,1)
glVertex3f(-1.0, 1.0, 1.0)
'glColor3f(0.0, 0.0, 1.0)
glTexCoord2f(1,0)
glVertex3f(-1.0, -1.0, 1.0)
'glColor3f(1.0, 0.0, 1.0)
glTexCoord2f(0,0)
glVertex3f(-1.0, -1.0, -1.0)
glEnd()
glBegin (GL_QUADS) 'sisi kanan
'glColor3f(1.0, 0.0, 0.0)
glTexCoord2f(0,1)
glVertex3f(1.0, 1.0, -1.0)
'glColor3f(0.0, 1.0, 0.0)
glTexCoord2f(1,1)
glVertex3f(1.0, 1.0, 1.0)
'glColor3f(0.0, 0.0, 1.0)
glTexCoord2f(1,0)
glVertex3f(1.0, -1.0, 1.0)
'glColor3f(1.0, 0.0, 1.0)
glTexCoord2f(0,0)
glVertex3f(1.0, -1.0, -1.0)
glEnd()
swapBuffers()
if scankeydown(VK_RIGHT) then ' gerak ke kanan
pcamx# = pcamx# + pindah#
elseif scankeydown(VK_LEFT) then ' gerak ke kiri
pcamx# = pcamx# - pindah#
elseif scankeydown(VK_UP) then ' gerak ke atas
pcamy# = pcamy# + pindah#
elseif scankeydown(VK_DOWN) then ' gerak ke bawah
pcamy# = pcamy# - pindah#
endif
wend
Hasil program :