Created
July 9, 2016 10:01
-
-
Save PifyZ/2aaf853359442cdbc19d44d2eb39bfed to your computer and use it in GitHub Desktop.
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, g, b, a: float | |
lhVec3 {.importc: "lh_vec3_t", header: "<libhang.h>".} = tuple | |
x, y, z: float | |
lhDistance {.importc: "lh_distances_t", header: "<libhang.h>".} = tuple | |
near, 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, 480, 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment