All Projects → zacharycarter → Zengine

zacharycarter / Zengine

2D | 3D Game development library

Programming Languages

nim
578 projects

Projects that are alternatives of or similar to Zengine

Gplayengine
Cross-platform C++ 2D / 3D game engine.
Stars: ✭ 129 (-11.03%)
Mutual labels:  game-development, game-engine, 3d, 2d
Fxgl
Stars: ✭ 2,378 (+1540%)
Mutual labels:  game-development, game-engine, 3d, 2d
Gamedev Resources
🎮 🎲 A wonderful list of Game Development resources.
Stars: ✭ 2,054 (+1316.55%)
Mutual labels:  game-development, game-engine, 3d, 2d
Rapid
A game engine written in Nim, optimized for making cool games fast.
Stars: ✭ 129 (-11.03%)
Mutual labels:  game-development, game-engine, 2d
Babylon.js
Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.
Stars: ✭ 15,479 (+10575.17%)
Mutual labels:  game-development, game-engine, 3d
Limonengine
3D FPS game engine with full dynamic lighting and shadows
Stars: ✭ 331 (+128.28%)
Mutual labels:  game-development, game-engine, 3d
Glas
WebGL in WebAssembly with AssemblyScript
Stars: ✭ 278 (+91.72%)
Mutual labels:  game-development, game-engine, 3d
Cpp 3d Game Tutorial Series
C++ 3D Game Tutorial Series is a YouTube tutorial series, whose purpose is to help all those who want to take their first steps in the game development from scratch.
Stars: ✭ 400 (+175.86%)
Mutual labels:  game-development, game-engine, 3d
Etengine
Realtime 3D Game-Engine with a focus on space sim. Written in C++ 14
Stars: ✭ 408 (+181.38%)
Mutual labels:  game-development, game-engine, 3d
Kaetram Open
An open-source 2D HTML5 adventure based off BrowserQuest (BQ).
Stars: ✭ 138 (-4.83%)
Mutual labels:  game-development, game-engine, 2d
Roygbiv
A 3D engine for the Web
Stars: ✭ 499 (+244.14%)
Mutual labels:  game-development, game-engine, 3d
Pixelvision8
Pixel Vision 8's core philosophy is to teach retro game development with streamlined workflows. PV8 is also a platform that standardizes 8-bit fantasy console limitations built on top of the open-source C# game engine based on MonoGame.
Stars: ✭ 773 (+433.1%)
Mutual labels:  game-development, game-engine, 2d
Obengine
2D Game Engine with Lua Scripting made on top of SFML !
Stars: ✭ 335 (+131.03%)
Mutual labels:  game-development, game-engine, 2d
Engine Native
Native engine for Cocos Creator
Stars: ✭ 488 (+236.55%)
Mutual labels:  game-development, game-engine, 3d
Novelrt
A cross-platform 2D game engine accompanied by a strong toolset for visual novels.
Stars: ✭ 81 (-44.14%)
Mutual labels:  game-development, game-engine, 2d
O2
2D Game Engine with visual WYSIWYG editor
Stars: ✭ 121 (-16.55%)
Mutual labels:  game-development, game-engine, 2d
Radixengine
A free and open game engine.
Stars: ✭ 126 (-13.1%)
Mutual labels:  game-engine, 3d
Cryengine
CRYENGINE is a powerful real-time game development platform created by Crytek.
Stars: ✭ 580 (+300%)
Mutual labels:  game-development, game-engine
Xenko
Old repo for Xenko Game Engine. Please use https://github.com/xenko3d/xenko instead.
Stars: ✭ 1,565 (+979.31%)
Mutual labels:  game-development, game-engine
Openage
Free (as in freedom) open source clone of the Age of Empires II engine 🚀
Stars: ✭ 10,712 (+7287.59%)
Mutual labels:  game-development, game-engine

zengine

2D | 3D Game development library

NOTE - Please run examples from root directory for now

Progress -

3D Skeletal Animation Lit Model Model Loading FPS Camera 2D & 3D Primitive Rendering

Dependencies: Assimp

import zengine, sdl2, opengl

type
  LightKind = enum
    Point, Directional, Spot
  
  Light = ref object
    id: int
    enabled: bool
    kind: LightKind
    position: Vector3
    target: Vector3
    radius: float
    diffuse: ZColor
    intensity: float
    coneAngle: float

const 
  WIDTH = 960
  HEIGHT = 540
  MAX_LIGHTS = 8

var lights: array[MAX_LIGHTS, Light]
var lightsCount = 0
var lightsLocs: array[MAX_LIGHTS, array[8, int]]

proc createLight(kind: LightKind, position: Vector3, diffuse: ZColor): Light =
  result = nil

  if lightsCount < MAX_LIGHTS:
    result = Light(
      id: lightsCount,
      kind: kind,
      enabled: true,
      position: position,
      target: vectorZero(),
      intensity: 1.0,
      diffuse: diffuse
    )

    lights[lightsCount] = result

    inc(lightsCount)
  else:
    result = lights[lightsCount]

proc setShaderLightsValues(shader: Shader) =
  var tempInt: array[8, GLint]
  var tempFloat: array[8, GLfloat]

  for i in 0..<MAX_LIGHTS:
    if i < lightsCount:
      tempInt[0] = lights[i].enabled.GLint
      setShaderValuei(shader, lightsLocs[i][0].GLint, tempInt, 1)
      
      tempInt[0] = lights[i].kind.GLint
      setShaderValuei(shader, lightsLocs[i][1].GLint, tempInt, 1)

      tempFloat[0] = lights[i].diffuse.r.float/255.0
      tempFloat[1] = lights[i].diffuse.g.float/255.0
      tempFloat[2] = lights[i].diffuse.b.float/255.0
      tempFloat[3] = lights[i].diffuse.a.float/255.0
      setShaderValue(shader, lightsLocs[i][5].GLint, tempFloat, 4)

      tempFloat[0] = lights[i].intensity
      setShaderValue(shader, lightsLocs[i][6].GLint, tempFloat, 1)

      case lights[i].kind:
        of LightKind.Point:
          tempFloat[0] = lights[i].position.x
          tempFloat[1] = lights[i].position.y
          tempFloat[2] = lights[i].position.z
          setShaderValue(shader, lightsLocs[i][2].GLint, tempFloat, 3)

          tempFloat[0] = lights[i].radius
          setShaderValue(shader, lightsLocs[i][4].GLint, tempFloat, 1)
        of LightKind.Directional:
          var direction = vectorSubtract(lights[i].target, lights[i].position)
          vectorNormalize(direction)

          tempFloat[0] = direction.x
          tempFloat[1] = direction.y
          tempFloat[2] = direction.z
          setShaderValue(shader, lightsLocs[i][3].GLint, tempFloat, 3)
        of LightKind.Spot:
          tempFloat[0] = lights[i].position.x
          tempFloat[1] = lights[i].position.y
          tempFloat[2] = lights[i].position.z
          setShaderValue(shader, lightsLocs[i][2].GLint, tempFloat, 3)

          var direction = vectorSubtract(lights[i].target, lights[i].position)
          vectorNormalize(direction)

          tempFloat[0] = direction.x
          tempFloat[1] = direction.y
          tempFloat[2] = direction.z
          setShaderValue(shader, lightsLocs[i][3].GLint, tempFloat, 3)

          tempFloat[0] = lights[i].coneAngle
          setShaderValue(shader, lightsLocs[i][7].GLint, tempFloat, 1)
    else:
      tempInt[0] = 0
      setShaderValuei(shader, lightsLocs[i][0].GLint, tempInt, 1)


proc getShaderLightsLocation(shader: Shader) =
  var locName = "lights[x]."
  var locNameUpdated = newStringOfCap(64)

  for i in 0..<MAX_LIGHTS:
    locName[7] = ('0'.int + i).char

    locNameUpdated = locName
    locNameUpdated &= "enabled"
    lightsLocs[i][0] = getShaderLocation(shader, locNameUpdated)

    locNameUpdated[0] = ' '
    locNameUpdated = locName
    locNameUpdated &= "type"
    lightsLocs[i][1] = getShaderLocation(shader, locNameUpdated)

    locNameUpdated[0] = ' '
    locNameUpdated = locName
    locNameUpdated &= "position"
    lightsLocs[i][2] = getShaderLocation(shader, locNameUpdated)

    locNameUpdated[0] = ' '
    locNameUpdated = locName
    locNameUpdated &= "direction"
    lightsLocs[i][3] = getShaderLocation(shader, locNameUpdated)

    locNameUpdated[0] = ' '
    locNameUpdated = locName
    locNameUpdated &= "radius"
    lightsLocs[i][4] = getShaderLocation(shader, locNameUpdated)

    locNameUpdated[0] = ' '
    locNameUpdated = locName
    locNameUpdated &= "diffuse"
    lightsLocs[i][5] = getShaderLocation(shader, locNameUpdated)

    locNameUpdated[0] = ' '
    locNameUpdated = locName
    locNameUpdated &= "intensity"
    lightsLocs[i][6] = getShaderLocation(shader, locNameUpdated)

    locNameUpdated[0] = ' '
    locNameUpdated = locName
    locNameUpdated &= "coneAngle"
    lightsLocs[i][7] = getShaderLocation(shader, locNameUpdated)

zengine.init(WIDTH, HEIGHT, "zengine example: 00_Initialization")

var 
  evt = sdl2.defaultEvent
  running = true
  camera = Camera(
    position: Vector3(x: 4, y: 2, z: 4),
    target: Vector3(x: 0, y: 1.8, z: 0),
    up: Vector3(x: 0, y: 1, z: 0),
    fovY: 60
  )
  mouseWheelMovement = 0
  mouseXRel = 0
  mouseYRel = 0

camera.setMode(CameraMode.Free)
#camera.setMode(CameraMode.FirstPerson)

let shader = loadShader("examples/data/shaders/glsl330/forward.vs", "examples/data/shaders/glsl330/forward.fs")

var model = loadModel("examples/data/models/mannequin/walking.dae", shader)

getShaderLightsLocation(shader)

var spotLight = createLight(LightKind.Spot, Vector3(x:0.0, y:5.0, z:0.0), ZColor(r:255, g:255, b:255, a:255))
spotLight.target = Vector3(x: 0.0, y: 0.0, z: 0.0)
spotLight.intensity = 2.0
spotlight.diffuse = ZColor(r: 0, g: 0, b: 255, a: 255)
spotLight.coneAngle = 60.0

var dirLight = createLight(LightKind.Directional, Vector3(x:0.0, y: -3.0, z: -3.0), ZColor(r:0, g:0, b:255, a:255))
dirLight.target = Vector3(x: 1.0, y: -2.0, z: -2.0)
dirLight.intensity = 2.0
dirLight.diffuse = ZColor(r: 100, g:255, b:100, a:255)

var pointLight = createLight(LightKind.Point, Vector3(x:0.0, y: 4.0, z: 5.0), ZColor(r:255, g:255, b:255, a:255))
pointLight.intensity = 2.0
pointLight.diffuse = ZColor(r: 100, g:100, b:255, a:255)
pointLight.radius = 3.0

setShaderLightsValues(shader)

while running:
  mouseWheelMovement = 0
  mouseXRel = 0
  mouseYRel = 0
  while sdl2.pollEvent(evt):
    case evt.kind
    of QuitEvent:
      running = false
    of MouseMotion:
      var mouseMoveEvent = cast[MouseMotionEventPtr](addr evt)
      mouseXRel = mouseMoveEvent.xrel
      mouseYRel = mouseMoveEvent.yrel
    of MouseWheel:
      var mouseWheelEvent = cast[MouseWheelEventPtr](addr evt)
      mouseWheelMovement = mouseWheelEvent.y
    else:
      discard

  pollInput()

  camera.update(mouseWheelMovement, mouseXRel, mouseYRel)
  
  beginDrawing()
  clearBackground(ZENGRAY)
  
  begin3dMode(camera)
  drawPlane(Vector3(x: 0.0, y: 0.0, z: 0.0), Vector2(x: 32.0, y: 32.0), GREEN)
  drawCube(Vector3(x: -16.0, y: 2.5, z: 0.0), 1.0, 5.0, 32.0, BLUE)
  drawCube(Vector3(x: 16.0, y: 2.5, z: 0.0), 1.0, 5.0, 32.0, RED)
  drawCube(Vector3(x: 0.0, y: 2.5, z: 16.0), 32.0, 5.0, 1.0, WHITE)
  drawModel(model, WHITE)
  end3dMode()

  drawText("Hello zengine!", 5, 5, 30, ZColor(r: 255, g: 255, b: 255, a: 255))

  endDrawing()

zengine.shutdown()

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].