Last active
August 29, 2015 14:26
-
-
Save PifyZ/21b74938a37297e8e6ba to your computer and use it in GitHub Desktop.
TerraNova en Nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
rm Essai01 | |
nim \ | |
--cincludes:libhang/include \ | |
--clibdir:libhang/src \ | |
--passL:-lhang \ | |
--parallelBuild:1 \ | |
c Essai01.nim | |
if [ -f Essai01 ]; then | |
LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:.:./libhang/src" ./Essai01 | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Portage pur | |
# | |
type | |
lhMutex = object | |
id: int64 | |
lhWindow = object | |
id: int64 | |
x: int | |
y: int | |
width: uint | |
height: uint | |
graphic_ctx_mutex: ref lhMutex | |
# core: lh_core_ctx_t | |
# gl: lh_gl_funcs_t | |
lhColor {.importc: "lh_rgba_t", header: "<libhang.h>".} = tuple | |
r: float | |
g: float | |
b: float | |
a: float | |
lhVec3 {.importc: "lh_vec3_t", header: "<libhang.h>".} = tuple | |
x: float | |
y: float | |
z: float | |
lhDistance {.importc: "lh_distances_t", header: "<libhang.h>"} = tuple | |
near: float | |
far: float | |
lhObj = object | |
id: int | |
# lh_obj_class_t *obj_class; | |
# void (*delete_proc)(struct lh_s_window *, struct lh_s_obj *); | |
# void *private_data; | |
pos : lhVec3 | |
angle: lhVec3 | |
is_visible: bool | |
culling_enabled: bool | |
reversed_culling: bool | |
depth_test_enabled: bool | |
is_illuminable: bool | |
custom_textures: ref uint | |
# lh_dynamic_type_t *custom_uniforms_data; | |
# lh_buffer_t custom_buffers[LH_NB_BUFS]; | |
nb_clones: uint | |
# struct s_LinkedList clones; | |
nb_allocated_clones: uint | |
# struct s_LinkedList gc_clones; | |
proc lhInit(): void | |
{.importc, header: "<libhang.h>".} | |
proc lhCreateWindow(title: cstring; x, y: cint; width, height: cuint; depth, dblBuf: cint): ptr lhWindow | |
{.importc, header: "<libhang.h>".} | |
proc lhSetBackColor(window: ptr lhWindow; color: lhColor): void | |
{.importc, header: "<libhang.h>".} | |
proc lhStartDrawing(window: ptr lhWindow): void | |
{.importc, header: "<libhang.h>".} | |
proc lhEnterEventLoop(window: ptr lhWindow): void | |
{.importc, header: "<libhang.h>".} | |
proc lhRegColoredCube(window: ptr lhWindow): int | |
{.importc, header: "<libhang.h>".} | |
proc lhNewColoredCube(window: ptr lhWindow; side: float; pos, angle: lhVec3; color: lhColor; isVisible: bool): ptr lhObj | |
{.importc, header: "<libhang.h>".} | |
proc lhEnableLight(window: ptr lhWindow; num, lightType: cint): void | |
{.importc, header: "<libhang.h>".} | |
proc lhSetCameraPos(window: ptr lhWindow; pos: lhVec3): void | |
{.importc, header: "<libhang.h>".} | |
proc lhSetRenderDistances(window: ptr lhWindow; distance: lhDistance): void | |
{.importc, header: "<libhang.h>".} | |
proc lhSetAmbientLight(window: ptr lhWindow; color: lhColor): void | |
{.importc, header: "<libhang.h>".} | |
proc lhSetLightParameters(window: ptr lhWindow; num: cint; color: lhColor; pos: lhVec3): void | |
{.importc, header: "<libhang.h>".} | |
# | |
# Test | |
# | |
lhInit() | |
var window = lhCreateWindow("TerraNova", 0, 0, 640.cuint, 480.cuint, 1, 1) | |
var color = (r: 0.0, g: 0.0, b: 0.3, a: 1.0).lhColor | |
lhSetBackColor(window, color) | |
lhSetRenderDistances(window, (near: 0.1, far: 100.0).lhDistance) | |
lhSetAmbientLight(window, (r: 0.4, g: 0.4, b: 0.4, a: 1.0).lhColor) | |
lhSetCameraPos(window, (x: 0.0, y: 2.0, z: 0.0).lhVec3) | |
# lhEnableLight(window, 0) | |
# lh_obj_t *cube = lhNewColoredCube( | |
# window, | |
# 1.0, | |
# &LH_VEC3(pos_x, pos_y, pos_z), | |
# &LH_VEC3(angle_x, angle_y, angle_z), | |
# &LH_RGBA(r, g, b, a), | |
# LH_TRUE); | |
discard lhRegColoredCube(window) | |
var cube = lhNewColoredCube( | |
window, | |
1.0, | |
(x: 0.0, y: 0.0, z: 4.0).lhVec3, | |
(x: 0.0, y: 0.0, z: 0.0).lhVec3, | |
(r: 1.0, g: 0.0, b: 0.0, a: 1.0).lhColor, | |
true) | |
lhStartDrawing(window) | |
lhEnterEventLoop(window) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Portage corrigé | |
# | |
type | |
Window = object | |
win: ptr lhWindow | |
Color = tuple | |
r, g, b, a: int | |
proc init() = | |
lhInit() | |
proc newWindow(title: string; x, y: int; width, height: uint): Window = | |
result.win = lhCreateWindow(title.cstring, x.cint, y.cint, width.cuint, height.cuint, 1, 1) | |
proc setBackgroundColor(window: Window, c: Color) = | |
var | |
r = c.r / 255 | |
g = c.g / 255 | |
b = c.b / 255 | |
a = c.a / 100 | |
co = (r: r, g: g, b: b, a: a).lhColor | |
lhSetBackColor(window.win, co) | |
proc run(window: Window) = | |
lhStartDrawing(window.win) | |
lhEnterEventLoop(window.win) | |
# | |
# Test | |
# | |
init() | |
var window = newWindow("TerraNova", 0, 0, 640, 480) | |
window.setBackgroundColor(Color(r: 255, g: 0, b: 0, a: 100)) | |
window.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment