Skip to content

Commit

Permalink
started win32
Browse files Browse the repository at this point in the history
  • Loading branch information
guzba committed Oct 12, 2021
1 parent 842cb25 commit a7e3acb
Show file tree
Hide file tree
Showing 16 changed files with 791 additions and 42 deletions.
28 changes: 9 additions & 19 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
name: Run tests
name: Github Actions
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]

steps:
- uses: actions/checkout@v1

- name: Cache choosenim
id: cache-choosenim
uses: actions/cache@v1
with:
path: ~/.choosenim
key: ${{ runner.os }}-choosenim-stable

- name: Cache nimble
id: cache-nimble
uses: actions/cache@v1
with:
path: ~/.nimble
key: ${{ runner.os }}-nimble-stable
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v2
- uses: jiro4989/setup-nim-action@v1

- run: nimble test -y
- run: nimble test --gc:orc -y
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ nimcache
*.pdb
*.ilk
.*
*.dll
__pycache__
bindings/generated
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2021 Author
Copyright (c) 2021 Andre von Houck and Ryan Oldenburg

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# You can use this nim template to jump start your nim library or project.
# Windy

This template includes:
* MIT licence
* src directory and a private common.nim
* test directory
* GitHub Actions to run the tests on GitHub
This library is still in development and is not ready to be used.
44 changes: 44 additions & 0 deletions bindings/bindings.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import genny, windy

var lastError: ref WindyError

proc takeError(): string =
result = lastError.msg
lastError = nil

proc checkError(): bool =
result = lastError != nil

proc isVisible(window: Window): bool =
window.visible

proc show(window: Window) =
window.visible = true

proc hide(window: Window) =
window.visible = false

exportProcs:
checkError
takeError

exportRefObject App:
discard

exportRefObject Window:
constructor:
newWindow
procs:
show
hide
isVisible
makeContextCurrent
swapBuffers

exportProcs:
getApp
init

writeFiles("bindings/generated", "Windy")

include generated/internal
31 changes: 31 additions & 0 deletions examples/basic.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import boxy, opengl, windy

let app = getApp()
app.init()

let
windowSize = ivec2(1280, 800)
window = app.newWindow("Windy + Boxy", windowSize.x, windowSize.y)

window.makeContextCurrent()
loadExtensions()

window.visible = true

echo "GL_VERSION: ", cast[cstring](glGetString(GL_VERSION))
echo "GL_VENDOR: ", cast[cstring](glGetString(GL_VENDOR))
echo "GL_RENDERER: ", cast[cstring](glGetString(GL_RENDERER))
echo "GL_SHADING_LANGUAGE_VERSION: ", cast[cstring](glGetString(GL_SHADING_LANGUAGE_VERSION))

let bxy = newBoxy()

proc display() =
bxy.beginFrame(windowSize)
bxy.drawRect(rect(vec2(0, 0), windowSize.vec2), color(1, 1, 1, 1))
bxy.drawRect(rect(vec2(100, 100), vec2(200, 200)), color(1, 0, 1, 1))
bxy.endFrame()
window.swapBuffers()

while true:
# pollEvents()
display()
1 change: 0 additions & 1 deletion examples/example.nim

This file was deleted.

8 changes: 0 additions & 8 deletions nimtemplate.nimble

This file was deleted.

3 changes: 0 additions & 3 deletions src/nimtemplate.nim

This file was deleted.

1 change: 0 additions & 1 deletion src/nimtemplate/common.nim

This file was deleted.

44 changes: 44 additions & 0 deletions src/windy.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import windy/common

export common

when defined(windows):
import windy/platforms/win32/platform

type
App* = ref object
platform: PlatformApp

Window* = ref object
platform: PlatformWindow

let app = App()

proc getApp*(): App =
app

proc init*(app: App) {.raises: [WindyError]} =
if app.platform != nil:
raise newException(WindyError, "Windy is already initialized")
app.platform = newPlatformApp()

proc newWindow*(
app: App, windowTitle: string, width, height: int
): Window {.raises: [WindyError]} =
result = Window()
result.platform = app.platform.newWindow(windowTitle, width, height)

proc makeContextCurrent*(window: Window) {.raises: [WindyError]} =
window.platform.makeContextCurrent()

proc swapBuffers*(window: Window) {.raises: [WindyError]} =
window.platform.swapBuffers()

proc `visible`*(window: Window): bool =
discard

proc `visible=`*(window: Window, visible: bool) =
if visible:
window.platform.show()
else:
window.platform.hide()
1 change: 1 addition & 0 deletions src/windy/common.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
type WindyError* = object of ValueError
Loading

0 comments on commit a7e3acb

Please sign in to comment.