Post by MadMockhaven on Feb 16, 2005 1:47:05 GMT -5
This weekend I decided to make another 3d engine. However apart from my last ones this can load an actual 3d enviroment not just a grid of squares
And the realy simple map I made is written in to a txt file
like this
dim file, poly,x,y,z,map#(1000)(7)(3)
dim camX#, camY#, camZ#, camAng#, texture(20), tex(20)
dim groundTex, skyTex (4), i
groundTex = LoadMipmapTexture ("textures\00006.jpg")
skyTex (0) = LoadMipmapTexture ("textures\t003.jpg")
skyTex (1) = LoadMipmapTexture ("textures\l003.jpg")
skyTex (2) = LoadMipmapTexture ("textures\f003.jpg")
skyTex (3) = LoadMipmapTexture ("textures\r003.jpg")
skyTex (4) = LoadMipmapTexture ("textures\b003.jpg")
file = OpenFileRead ("files\map3.txt")
poly = val (ReadLine (file))
for x = 1 to poly
for y = 0 to 7
for z = 0 to 3
map#(x)(y)(z) = val (ReadText (file, true))
next
next
next
CloseFile (file)
dim vertex#(8)(2)
Tex(1) = LoadMipmapTexture ("textures\wall01.jpg")
Tex(2) = LoadMipmapTexture ("textures\00002.jpg")
Tex(3) = LoadMipmapTexture ("textures\00003.jpg")
Tex(4) = LoadMipmapTexture("textures\00004.jpg")
Tex(5) = LoadMipmapTexture ("textures\wall01.jpg")
Tex(6) = LoadMipmapTexture ("textures\ceil01.jpg")
Tex(7) = LoadTexture ("textures\001.jpg")
Tex(8) = LoadTexture ("Data\cube.bmp")
skyTex (0) = LoadMipmapTexture ("textures\t003.jpg")
glEnable (GL_TEXTURE_2D)
while true
' Clear screen
glClear (GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT)
glLoadIdentity ()
' Position camera
glRotatef (-camAng#, 0, 1, 0)
glTranslatef (-camX#, -camY#, -camZ#)
for x = 1 to poly
vertex#(1) = vec3 (map#(x)(0)(0),map#(x)(0)(1), map#(x)(0)(2))
vertex#(2) = vec3 (map#(x)(1)(0),map#(x)(1)(1), map#(x)(1)(2))
vertex#(3) = vec3 (map#(x)(2)(0),map#(x)(2)(1), map#(x)(2)(2))
vertex#(4) = vec3 (map#(x)(3)(0),map#(x)(3)(1), map#(x)(3)(2))
vertex#(5) = vec3 (map#(x)(4)(0),map#(x)(4)(1), map#(x)(4)(2))
vertex#(6) = vec3 (map#(x)(5)(0),map#(x)(5)(1), map#(x)(5)(2))
vertex#(7) = vec3 (map#(x)(6)(0),map#(x)(6)(1), map#(x)(6)(2))
vertex#(8) = vec3 (map#(x)(7)(0),map#(x)(7)(1), map#(x)(7)(2))
texture(1) = map#(x)(0)(3)
texture(2) = map#(x)(1)(3)
texture(3) = map#(x)(2)(3)
texture(4) = map#(x)(3)(3)
texture(5) = map#(x)(4)(3)
texture(6) = map#(x)(5)(3)
glBindTexture (GL_TEXTURE_2D, tex(texture(2)))
glBegin(GL_QUADS)
' Front face
glTexCoord2f(0.0, 0.0):glVertex3fv(vertex#(5)) ' Bottom left of the texture and quad
glTexCoord2f(0.0, 1.0):glVertex3fv(vertex#(6)) ' Bottom right of the texture and quad
glTexCoord2f(1.0, 1.0):glVertex3fv(vertex#(7)) ' Top right of the texture and quad
glTexCoord2f(1.0, 0.0):glVertex3fv(vertex#(8)) ' Top`
glBegin(GL_QUADS)
glTexCoord2f(0.0, 0.0):glVertex3fv(vertex#(1)) ' Bottom right of the texture and quad
glTexCoord2f(0.0, 1.0):glVertex3fv(vertex#(2)) ' Top right of the texture and quad
glTexCoord2f(1.0, 1.0):glVertex3fv(vertex#(3)) ' Top left of the texture and quad
glTexCoord2f(1.0, 0.0):glVertex3fv(vertex#(4)) ' Bottom left of the texture and quad
' Top face
glend()
glBindTexture (GL_TEXTURE_2D, tex(texture(3)))
glBegin(GL_QUADS)
glTexCoord2f(0.0, 0.0): glVertex3fv(vertex#(1)) ' Top left of the texture and quad
glTexCoord2f(0.0, 1.0): glVertex3fv(vertex#(5)) ' Bottom left of the texture and quad
glTexCoord2f(1.0, 1.0): glVertex3fv(vertex#(8)) ' Bottom right of the texture and quad
glTexCoord2f(1.0, 0.0): glVertex3fv(vertex#(4)) ' Top right of the texture and quad
' Bottom face
glend()
glBindTexture (GL_TEXTURE_2D, tex(texture(4)))
glBegin(GL_QUADS)
glTexCoord2f(0.0, 0.0): glVertex3fv(vertex#(2)) ' Top right of the texture and quad
glTexCoord2f(0.0, 1.0): glVertex3fv(vertex#(3)) ' Top left of the texture and quad
glTexCoord2f(1.0, 1.0): glVertex3fv(vertex#(7)) ' Bottom left of the texture and quad
glTexCoord2f(1.0, 0.0): glVertex3fv(vertex#(6)) ' Bottom right of the texture and quad
' Right face
glend()
glBindTexture (GL_TEXTURE_2D, tex(texture(5)))
glBegin(GL_QUADS)
glTexCoord2f(0.0, 0.0):glVertex3fv(vertex#(3)) ' Bottom right of the texture and quad
glTexCoord2f(0.0, 1.0):glVertex3fv(vertex#(4)) ' Top right of the texture and quad
glTexCoord2f(1.0, 1.0):glVertex3fv(vertex#(8)) ' Top left of the texture and quad
glTexCoord2f(1.0, 0.0):glVertex3fv(vertex#(7)) ' Bottom left of the texture and quad
' Left face
glend()
glBindTexture (GL_TEXTURE_2D, tex(texture(6)))
glBegin(GL_QUADS)
glTexCoord2f(0.0, 0.0):glVertex3fv(vertex#(6)) ' Bottom left of the texture and quad
glTexCoord2f(1.0, 0.0):glVertex3fv(vertex#(2)) ' Bottom right of the texture and quad
glTexCoord2f(1.0, 1.0): glVertex3fv(vertex#(1)) ' Top right of the texture and quad
glTexCoord2f(0.0, 1.0):glVertex3fv(vertex#(5)) ' Top left of the texture and quad
glEnd()
next
SwapBuffers ()
while SyncTimer (10)
if ScanKeyDown (VK_LEFT) then camAng# = camAng# + 1: endif
if ScanKeyDown (VK_RIGHT) then camAng# = camAng# - 1: endif
if ScanKeyDown (VK_UP) then
camX# = camX# - sind (camAng#) * .2
camZ# = camZ# - cosd (camAng#) * .2
endif
if ScanKeyDown (VK_DOWN) then
camX# = camX# + sind (camAng#) * .2
camZ# = camZ# + cosd (camAng#) * .2
endif
wend
wend
And the realy simple map I made is written in to a txt file
like this
2
-1 1 -5 5
-1 -0.99 -5 2
1 -0.99 -5 3
1 1 -5 4
-1 1 -7 5
-1 -0.99 -7 5
1 -0.99 -7 5
1 1 -7 5
-10 -1 -9 5
-10 -2 -9 2
10 -2 -9 3
10 -1 -9 4
-10 -1 5 5
-10 -2 5 5
10 -2 5 5
10 -1 5 5