Post by GuppyB on Jul 12, 2004 21:25:42 GMT -5
I updated the other file to include light mapping and it creates quite a stunning effect. Also the earth now rotates the proper way.
Pressing "L" turns lighting on and off
Pressing "T" turns texture on and off
Pressing "B" turns alpha blending on (makes it semi-transparent)
In regards to preparing the texture map, its the same as in last message:
In order for this to work with the texture map you will need to download the "Earth Textures Natural Colors" image from here:
www.oera.net/How2/TextureMaps.htm
You will then need to resize it in a photo program like Photoshop to 1024x512, and save in the Textures folder of Basic4gl with the name "EarthMap_1024x512.jpg"
I know it's a lot to go through be the result is great
Enjoy the code....G
Pressing "L" turns lighting on and off
Pressing "T" turns texture on and off
Pressing "B" turns alpha blending on (makes it semi-transparent)
In regards to preparing the texture map, its the same as in last message:
In order for this to work with the texture map you will need to download the "Earth Textures Natural Colors" image from here:
www.oera.net/How2/TextureMaps.htm
You will then need to resize it in a photo program like Photoshop to 1024x512, and save in the Textures folder of Basic4gl with the name "EarthMap_1024x512.jpg"
I know it's a lot to go through be the result is great
Enjoy the code....G
dim xrot#, yrot#, zrot#
dim spherecircum
dim i , j
dim OldTick, CurrentTick , TimeTick, Frames , FramesSecond#
dim texture
dim one36th# , one18th#
dim LightAmbient#(3): LightAmbient# = vec4 (0.25, 0.25, 0.25, 1.0)
dim LightDiffuse#(3): LightDiffuse# = vec4 (1.0, 1.0, 1.0, 1.0 )
dim LightPosition#(3): LightPosition# = vec4 ( 10.0, 0.0, 0.0, 1.0 )
dim sinarray#(36),cosarray#(36)
dim key$
dim light, blend, textureon
light = true: blend = false: textureon = true
for i = 0 to 36
sinarray#(i) = sind (i*10)
cosarray#(i) = cosd (i*10)
next
texture = LoadMipmapTexture ("Textures/EarthMap_1024x512.jpg")
if texture = 0 then print "Failed to load texture": end: endif
one36th# = 1.0 / 36
one18th# = 1.0 / 18
glEnable (GL_TEXTURE_2D)
TextMode (TEXT_OVERLAID)
glEnable (GL_LIGHTING)
glEnable (GL_DEPTH_TEST)
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient#) ' Setup The Ambient Light
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse#) ' Setup The Diffuse Light
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition#) ' Position The Light
glEnable(GL_LIGHT1)
glBlendFunc(GL_SRC_ALPHA,GL_ONE)
OldTick = TickCount ()
while true
gosub FPSroutine
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
glTranslatef(0.0,0.0,-4.5)
glRotatef(90,1.0,0.0,0.0)
glRotatef(xrot#,1.0,0.0,0.0)
glRotatef(yrot#,0.0,1.0,0.0)
glRotatef(zrot#,0.0,0.0,1.0)
spherecircum = 2
gosub drawsphere
DrawText ()
SwapBuffers ()
zrot# = zrot# - 0.15
Gosub CheckKeys
wend
'********************sphere routine****************************
drawsphere:
glBindTexture(GL_TEXTURE_2D, texture)
for j = 0 to 17
glbegin (GL_Quad_strip)
glColor4f (1.0,1.0,1.0,0.5)
For i = 0 to 36
glTexCoord2f ( ((36 - i) * one36th#),(j * one18th#))
glNormal3f (spherecircum * sinarray# (j) * cosarray#(i), spherecircum * sinarray# (j) * sinarray# (i), spherecircum * cosarray# (j))
glVertex3f (spherecircum * sinarray# (j) * cosarray#(i), spherecircum * sinarray# (j) * sinarray# (i), spherecircum * cosarray# (j)) ' draw top vertex
glTexCoord2f ( ((36 - i) * one36th#) ,((j + 1.0) * one18th#))
glNormal3f (spherecircum * sinarray# (j+1) * cosarray#(i), spherecircum * sinarray# (j+1) * sinarray# (i), spherecircum * cosarray# (j+1))
glVertex3f (spherecircum * sinarray# (j+1) * cosarray#(i), spherecircum * sinarray# (j+1) * sinarray# (i), spherecircum * cosarray# (j+1)) 'draw bottom vertex
next
glend ()
next
return
'*******************FPS routine****************************
FPSroutine:
CurrentTick = TickCount()
TimeTick = CurrentTick - OldTick
if TimeTick >= 1000 then FramesSecond# = Frames * (TimeTick/1000) : Locate 0,0: Print FramesSecond# + " fps": Frames = 0: OldTick = CurrentTick: endif
Frames = Frames + 1
Return
'****************************** Check Key Strokes
CheckKeys:
key$ = Inkey$ ()
if key$ = "L" or key$ = "l" then
light = not light
if not light then
glDisable (GL_LIGHTING)
else
glEnable (GL_LIGHTING)
endif
endif
if key$ = "B" or key$ = "b" then
blend = not blend
if blend then
glEnable (GL_BLEND)
glDisable (GL_DEPTH_TEST)
else
glDisable (GL_BLEND)
glEnable (GL_DEPTH_TEST)
endif
endif
if key$ = "T" or key$ = "t" then
textureon = not textureon
if textureon then
glDisable (GL_TEXTURE_2D)
else
glEnable (GL_TEXTURE_2D)
endif
endif
Return