Skip to content

Commit

Permalink
Implemented Fog system
Browse files Browse the repository at this point in the history
- Implemented fog system
- Added docs for fog system
- Bumped version to v1.4.0a1
  • Loading branch information
not-na committed Oct 14, 2016
1 parent 0499516 commit 1a63fdc
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 19 deletions.
19 changes: 17 additions & 2 deletions docs/configoption.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,24 @@ Fog settings

By default disabled.

.. todo::
.. confval:: graphics.fogSettings["color"]

A 4-Tuple representing an RGB Color.

Note that the values should be 0<=n<=1, not in range(0,256).

For most cases, this value should be set to the clear color, else, visual artifacts may occur.

.. confval:: graphics.fogSettings["start"]
graphics.fogSettings["end"]

Defines start and end of the fog zone.

The end value should be nearer than the far clipping plane to avoid cut-off vertices.

Each value should be a float and is measured in standard OpenGL units.

Implement fog settings
By default, the fog starts at 128 units and ends 32 units further out.

Light settings
^^^^^^^^^^^^^^
Expand Down
34 changes: 20 additions & 14 deletions peng3d/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@

__all__ = ["CFG_FOG_DEFAULT","CFG_LIGHT_DEFAULT","DEFAULT_CONFIG","Config"]

CFG_FOG_DEFAULT = {"enable":False}
"""
Default fog configuration.
This configuration simply disables fog.
"""

CFG_LIGHT_DEFAULT = {"enable":False}
"""
Default lighting configuration.
This configuration simply disables lighting.
"""

class Config(object):
"""
Configuration object imitating a dictionary.
Expand Down Expand Up @@ -78,6 +64,26 @@ def __setitem__(self,key,value):
def __contains__(self,key):
return key in self.config

CFG_FOG_DEFAULT = {
"enable":False,

"color":None,
"start":128,
"end":128+32,
}
"""
Default fog configuration.
This configuration simply disables fog.
"""

CFG_LIGHT_DEFAULT = {"enable":False}
"""
Default lighting configuration.
This configuration simply disables lighting.
"""

DEFAULT_CONFIG = {
# graphics.*
# OpenGL config
Expand Down
4 changes: 2 additions & 2 deletions peng3d/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

__all__ = ["VERSION","RELEASE"]

VERSION = "1.3.0a1"
VERSION = "1.4.0a1"
"""
Full version number of format ``MAJOR.MINOR.BUGFIX(a|b|pre)SUBRELEASE`` where major is increased only on very major feature changes.
Minor is changed if a new feature is introduced or an API change is made, while bugfix only changes if an important bugfix needs to be provided before the next release.
Expand All @@ -38,7 +38,7 @@
"""

RELEASE = "1.3.0"
RELEASE = "1.4.0"
"""
Same as :py:data:`VERSION` but without the subrelease.
Expand Down
22 changes: 22 additions & 0 deletions peng3d/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,28 @@ def setup(self):
self.setupFog()
if self.cfg["graphics.lightSettings"]["enable"]:
self.setupLight()
def setupFog(self):
fogcfg = self.cfg["graphics.fogSettings"]
if not fogcfg["enable"]:
return

glEnable(GL_FOG)

if fogcfg["color"] is None:
fogcfg["color"] = self.cfg["graphics.clearColor"]
# Set the fog color.
glFogfv(GL_FOG_COLOR, (GLfloat * 4)(*fogcfg["color"]))
# Set the performance hint.
glHint(GL_FOG_HINT, GL_DONT_CARE) # TODO: add customization, including headless support
# Specify the equation used to compute the blending factor.
glFogi(GL_FOG_MODE, GL_LINEAR)
# How close and far away fog starts and ends. The closer the start and end,
# the denser the fog in the fog range.
glFogf(GL_FOG_START, fogcfg["start"])
glFogf(GL_FOG_END, fogcfg["end"])

def setupLight(self):
raise NotImplementedError("Currently not implemented")

def run(self):
"""
Expand Down
13 changes: 12 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@
COLORS = [255,0,0, 0,255,0, 0,0,255, 255,255,255]

def main(args):
# Peng engine instance creation and creating the window
peng = peng3d.Peng()
peng.createWindow(caption="Peng3d Test Project",resizable=True,vsync=True)
peng.window.addMenu(peng3d.Menu("main",peng.window,peng))
peng.window.toggle_exclusivity()
# Keybinds
def esc_toggle(symbol,modifiers,release):
if release:
return
Expand All @@ -50,15 +52,21 @@ def test_handler(symbol,modifiers,release):
if release:
return
peng.keybinds.changeKeybind("peng3d:actor.player.controls.forward","space")
peng.keybinds.changeKeybind("peng3d:actor.player.controls.forward.release","release-space")
peng.keybinds.add("f3","testpy:handler.test",test_handler)
# Fog and clear color config
peng.cfg["graphics.clearColor"]=[0.5,0.69,1.0,1.0]
peng.cfg["graphics.fogSettings"]["enable"]=True
peng.cfg["graphics.fogSettings"]["start"]=4
peng.cfg["graphics.fogSettings"]["end"]=8
# Creates world/cam/view/player
world = peng3d.StaticWorld(peng,TERRAIN,COLORS)
#player = peng3d.actor.player.FirstPersonPlayer(peng,world)
player = peng3d.actor.player.BasicPlayer(peng,world)
# Player controllers
player.addController(peng3d.actor.player.FourDirectionalMoveController(player))
player.addController(peng3d.actor.player.EgoMouseRotationalController(player))
player.addController(peng3d.actor.player.BasicFlightController(player))
# Player view/camera
world.addActor(player)
c = peng3d.CameraActorFollower(world,"cam1",player)
world.addCamera(c)
Expand All @@ -70,12 +78,15 @@ def test_handler(symbol,modifiers,release):
peng.window.addMenu(m)
l = peng3d.LayerWorld(m,peng.window,peng,world,"view1")
m.addLayer(l)
# Switch to the main menu
peng.window.changeMenu("main")
# Done!
if CONSOLE:
# Starts a console in seperate Thread, allows interactive debugging and testing stuff easily
t = threading.Thread(target=code.interact,name="REPL Thread",kwargs={"local":locals()})
t.daemon = True
t.start()
# Starts the main loop
peng.run()
return 0

Expand Down

0 comments on commit 1a63fdc

Please sign in to comment.