Post by Very Basic 3d Texture Demo on Oct 22, 2004 3:33:09 GMT -5
Here is a very basic demo for a 3d world with
+ Moving Camera
+ Textured Floor
+ Textured Wall (Can walk through, though)
Download working EXE:
www.freepgs.com/snapperthetwig/Downloads/test0001.zip
Here's the source:
'''''''''''''''''''''''''''''''''''''''''''''''''
' 3D Textured Demo '
' By SnapperTheTwig AKA Liam Twigger '
'''''''''''''''''''''''''''''''''''''''''''''''''
dim camera#(6) 'X,y,z,dir,roll,pitch
dim texture,texture2
glEnable (GL_TEXTURE_2D)
texture=loadtexture("TEXTURES/sprite2.png")
const mapx=30
const mapz=40
dim map(mapx)(mapz)(4)'Create an array for the map
dim x,z,x2,z2
for x=0 to mapx
for z=0 to mapz
map(x)(z)(0)=0 'Assign the Y for all of the points to 0
map(x)(z)(1)=0
map(x)(z)(2)=0
map(x)(z)(3)=0
next
next
camera#(1)=15
camera#(2)=1
camera#(3)=15
camera#(4)=225
'''''''''''''''''''''''''''''''''''''''''''''''''
' Main Loop '
'''''''''''''''''''''''''''''''''''''''''''''''''
while true
glClear (GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT)
glLoadIdentity()
glRotatef(-camera#(6),0,0,1)
glRotatef(-camera#(5),1,0,0)
glRotatef(-camera#(4),0,1,0)
glTranslatef(-camera#(1),-camera#(2),-camera#(3))
glColor3f(1,1,1)
glBindTexture (GL_TEXTURE_2D, texture)
for x=1 to mapx
for z=1 to mapz
x2=x-1
z2=z-1
glBegin(gl_quads) 'Draw the map
'glColor3f(0,0.7,0.1)
glTexCoord2f(0,0):glVertex3f(x,map(mapx)(mapz)(0),z)
glTexCoord2f(1,0):glVertex3f(x2,map(mapx)(mapz)(1),z)
glTexCoord2f(1,1):glVertex3f(x2,map(mapx)(mapz)(2),z2)
glTexCoord2f(0,1):glVertex3f(x,map(mapx)(mapz)(3),z2)
glEnd()
next
next
'Draw the "wall"
glBegin(gl_quads)
glTexCoord2f(1,1):glVertex3f(14,0,15)
glTexCoord2f(0,1):glVertex3f(14,2,15)
glTexCoord2f(0,0):glVertex3f(15,2,15)
glTexCoord2f(1,0):glVertex3f(15,0,15)
glEnd()
'Draw the undreground
glBegin(gl_quads)
glColor3f(1,0.4,0)
glVertex3f(0,-0.01,0)
glVertex3f(mapx,-0.01,0)
glVertex3f(mapx,-0.01,mapz)
glVertex3f(0,-0.01,mapz)
glEnd()
'Position Camera
if ScanKeyDown(vk_left) then camera#(4)= camera#(4)+4 endif
if ScanKeyDown(vk_right) then camera#(4)= camera#(4)-4 endif
if ScanKeyDown(vk_up) then
camera#(1)=camera#(1)-sind(camera#(4))*0.5
camera#(3)=camera#(3)-cosd(camera#(4))*0.5
endif
if ScanKeyDown(vk_down) then
camera#(1)=camera#(1)+sind(camera#(4))*0.5
camera#(3)=camera#(3)+cosd(camera#(4))*0.5
endif
SwapBuffers()
'Fall of the edge of the world!
if camera#(2)<0 or camera#(1)<0 or camera#(1)>mapx or camera#(3)<1 or camera#(3)>mapz then
camera#(2)=camera#(2)-0.5
if camera#(2)<=-25 then
locate 9,10:print "You fell off the edge!!"
sleep(2000)
run
endif
endif
sleep(50)'Restrict the speed
wend
+ Moving Camera
+ Textured Floor
+ Textured Wall (Can walk through, though)
Download working EXE:
www.freepgs.com/snapperthetwig/Downloads/test0001.zip
Here's the source:
'''''''''''''''''''''''''''''''''''''''''''''''''
' 3D Textured Demo '
' By SnapperTheTwig AKA Liam Twigger '
'''''''''''''''''''''''''''''''''''''''''''''''''
dim camera#(6) 'X,y,z,dir,roll,pitch
dim texture,texture2
glEnable (GL_TEXTURE_2D)
texture=loadtexture("TEXTURES/sprite2.png")
const mapx=30
const mapz=40
dim map(mapx)(mapz)(4)'Create an array for the map
dim x,z,x2,z2
for x=0 to mapx
for z=0 to mapz
map(x)(z)(0)=0 'Assign the Y for all of the points to 0
map(x)(z)(1)=0
map(x)(z)(2)=0
map(x)(z)(3)=0
next
next
camera#(1)=15
camera#(2)=1
camera#(3)=15
camera#(4)=225
'''''''''''''''''''''''''''''''''''''''''''''''''
' Main Loop '
'''''''''''''''''''''''''''''''''''''''''''''''''
while true
glClear (GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT)
glLoadIdentity()
glRotatef(-camera#(6),0,0,1)
glRotatef(-camera#(5),1,0,0)
glRotatef(-camera#(4),0,1,0)
glTranslatef(-camera#(1),-camera#(2),-camera#(3))
glColor3f(1,1,1)
glBindTexture (GL_TEXTURE_2D, texture)
for x=1 to mapx
for z=1 to mapz
x2=x-1
z2=z-1
glBegin(gl_quads) 'Draw the map
'glColor3f(0,0.7,0.1)
glTexCoord2f(0,0):glVertex3f(x,map(mapx)(mapz)(0),z)
glTexCoord2f(1,0):glVertex3f(x2,map(mapx)(mapz)(1),z)
glTexCoord2f(1,1):glVertex3f(x2,map(mapx)(mapz)(2),z2)
glTexCoord2f(0,1):glVertex3f(x,map(mapx)(mapz)(3),z2)
glEnd()
next
next
'Draw the "wall"
glBegin(gl_quads)
glTexCoord2f(1,1):glVertex3f(14,0,15)
glTexCoord2f(0,1):glVertex3f(14,2,15)
glTexCoord2f(0,0):glVertex3f(15,2,15)
glTexCoord2f(1,0):glVertex3f(15,0,15)
glEnd()
'Draw the undreground
glBegin(gl_quads)
glColor3f(1,0.4,0)
glVertex3f(0,-0.01,0)
glVertex3f(mapx,-0.01,0)
glVertex3f(mapx,-0.01,mapz)
glVertex3f(0,-0.01,mapz)
glEnd()
'Position Camera
if ScanKeyDown(vk_left) then camera#(4)= camera#(4)+4 endif
if ScanKeyDown(vk_right) then camera#(4)= camera#(4)-4 endif
if ScanKeyDown(vk_up) then
camera#(1)=camera#(1)-sind(camera#(4))*0.5
camera#(3)=camera#(3)-cosd(camera#(4))*0.5
endif
if ScanKeyDown(vk_down) then
camera#(1)=camera#(1)+sind(camera#(4))*0.5
camera#(3)=camera#(3)+cosd(camera#(4))*0.5
endif
SwapBuffers()
'Fall of the edge of the world!
if camera#(2)<0 or camera#(1)<0 or camera#(1)>mapx or camera#(3)<1 or camera#(3)>mapz then
camera#(2)=camera#(2)-0.5
if camera#(2)<=-25 then
locate 9,10:print "You fell off the edge!!"
sleep(2000)
run
endif
endif
sleep(50)'Restrict the speed
wend