Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Original NanoVG example port to Lime. #7

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "deps/glew"]
path = deps/glew
url = https://github.com/native-toolkit/glew
url = https://github.com/native-toolkit/glew
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ haxelib dev hx-nanovg hx-nanovg
#### Included Demo:
![hx-nanovg](http://developium.net/pics/nanovg2.png)

#### Include Example from the ported original NanoVG (not perfect):
![hx-nanovg example](https://dl.dropboxusercontent.com/u/79150615/nanovg_example_in_haxe.png)

#### Notes:
* Demo uses Lime (stencil buffer enabled!)
* uses https://github.com/native-toolkit/glew as submodule
Expand Down
4 changes: 2 additions & 2 deletions demo/demo.lime.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<project>

<meta title="NanoVG Demo" package="com.nanovg.demo" version="1.0.0" company="" />
<app main="Demo" path="." file="NanoVG-Demo" />
<meta title="NanoVG Demo" package="com.nanovg.dmo" version="1.0.0" company="" />
<app main="Main" path="." file="NanoVG-Demo" />
<window hardware="true" allow-shaders="true" require-shaders="true" depth-buffer="true" stencil-buffer="true" fps="100"/>

<source path="src" />
Expand Down
53 changes: 0 additions & 53 deletions demo/src/Demo.hx

This file was deleted.

83 changes: 83 additions & 0 deletions demo/src/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package;

import hxnanovg.Nvg;
import lime.app.Application;
import lime.graphics.opengl.GL;
import lime.graphics.RenderContext;
import lime.graphics.GLRenderContext;

using cpp.NativeString;

@:buildXml("&<include name='${haxelib:hx-nanovg}/Build.xml'/>")
class Main extends Application
{
private var ctx:GLRenderContext;

var vg:cpp.Pointer<NvgContext>;
var linearGradient:NvgPaint;
var font:Int;

public function new()
{
super();
}

public override function init(context:RenderContext):Void
{
updateSavedContext(context);

vg = Nvg.createGL(NvgMode.ANTIALIAS);
font = Nvg.createFont(vg, "arial".c_str(), "assets/times.ttf".c_str());
linearGradient = Nvg.linearGradient(vg, 0, 0, 500, 500, Nvg.rgba(255, 192, 0, 255), Nvg.rgba(0, 0, 0, 255));
}

public override function render(context:RenderContext):Void
{
updateSavedContext(context);

GL.viewport(0, 0, config.width, config.height);
GL.clearColor(0.3, 0.3, 0.3, 1.0);
GL.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT | GL.STENCIL_BUFFER_BIT);

Nvg.beginFrame(vg, 800, 600, 1.0);

Nvg.rect(vg, 100, 100, 500, 300);
Nvg.circle(vg, 120, 120, 250);
Nvg.pathWinding(vg, NvgSolidity.HOLE); // Mark circle as a hole.
Nvg.fillPaint(vg, linearGradient);
Nvg.fill(vg);

//*
Nvg.fontSize(vg, 30.0);
Nvg.fontFaceId(vg, font);
Nvg.fillColor(vg, Nvg.rgba(255, 0, 0, 255));
Nvg.text(vg, 50, 50, "This is some text: اقتصادية".c_str(), untyped __cpp__("NULL"));

Nvg.fontSize(vg, 100.0);
Nvg.fontFaceId(vg, font);
Nvg.fillColor(vg, Nvg.rgba(255, 255, 255, 64));
Nvg.textAlign(vg, NvgAlign.ALIGN_LEFT | NvgAlign.ALIGN_MIDDLE);
Nvg.text(vg, 100, 100, "Some other text!".c_str(), untyped __cpp__("NULL"));
//*/
Nvg.closePath(vg);

Nvg.beginPath(vg);
Nvg.moveTo(vg, 0, 400);
Nvg.bezierTo(vg, 50, 100, 300, 600, 400, 50);
Nvg.strokeWidth(vg, 2);
Nvg.strokeColor(vg, Nvg.rgba(0, 255, 255, 255));
Nvg.stroke(vg);

Nvg.endFrame(vg);
}


function updateSavedContext(context:RenderContext):Void
{
switch(context)
{
case RenderContext.OPENGL(gl): ctx = gl;
default: null;
}
}
}
57 changes: 57 additions & 0 deletions example/NanovgDemo.hxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="utf-8"?>
<project version="2">
<!-- Output SWF options -->
<output>
<movie outputType="CustomBuild" />
<movie input="" />
<movie path="project.xml" />
<movie fps="0" />
<movie width="0" />
<movie height="0" />
<movie version="1" />
<movie minorVersion="0" />
<movie platform="Lime" />
<movie background="#FFFFFF" />
<movie preferredSDK=";3;" />
</output>
<!-- Other classes to be compiled into your SWF -->
<classpaths>
<class path="C:\HaxeToolkit\haxe\lib\lime\2,0,6" />
<class path="C:\HaxeToolkit\haxe\lib\hx-nanovg\git" />
<class path="src" />
<class path="windows\cpp\haxe" />
</classpaths>
<!-- Build options -->
<build>
<option directives="lime=2.0.6&#xA;hx-nanovg=0.0.1&#xA;tools=2.0.6&#xA;no-compilation&#xA;lime-native&#xA;windows&#xA;desktop" />
<option flashStrict="False" />
<option noInlineOnDebug="False" />
<option mainClass="ApplicationMain" />
<option enabledebug="True" />
<option additional="#--macro keep(&quot;Main&quot;)" />
</build>
<!-- haxelib libraries -->
<haxelib>
<!-- example: <library name="..." /> -->
</haxelib>
<!-- Class files to compile (other referenced classes will automatically be included) -->
<compileTargets>
<compile path="src\Main.hx" />
</compileTargets>
<!-- Paths to exclude from the Project Explorer tree -->
<hiddenPaths>
<hidden path="obj" />
</hiddenPaths>
<!-- Executed before build -->
<preBuildCommand>"$(CompilerPath)/haxelib" run lime build "$(OutputFile)" $(TargetBuild) -$(BuildConfig) -Dfdb</preBuildCommand>
<!-- Executed after build -->
<postBuildCommand alwaysRun="False" />
<!-- Other project options -->
<options>
<option showHiddenPaths="False" />
<option testMovie="Custom" />
<option testMovieCommand="" />
</options>
<!-- Plugin storage -->
<storage />
</project>
Binary file added example/assets/Roboto-Bold.ttf
Binary file not shown.
Binary file added example/assets/Roboto-Light.ttf
Binary file not shown.
Binary file added example/assets/Roboto-Regular.ttf
Binary file not shown.
Binary file added example/assets/entypo.ttf
Binary file not shown.
Binary file added example/assets/images/image1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/images/image10.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/images/image11.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/images/image12.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/images/image2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/images/image3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/images/image4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/images/image5.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/images/image6.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/images/image7.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/images/image8.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added example/assets/images/image9.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions example/assets/lime.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions example/project.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<project>

<meta title="NanovgDemo" package="com.nanovg.NanovgDemo" version="1.0.0" company="" />
<app main="Main" file="NanovgDemo" path="." />

<window hardware="true" width="1280" height="720" allow-shaders="true" require-shaders="true" depth-buffer="true" stencil-buffer="true" fps="100"/>

<source path="src" />

<android target-sdk-version="19" />

<haxelib name="lime" />
<haxelib name="hx-nanovg" />

<assets path="assets" rename="assets" exclude="*.dll|*.js|*.mp3|*.svg" />
<icon path="assets/lime.svg" />

<set name="-32" />

</project>
Binary file added example/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions example/src/DbgTrace.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package;
import cpp.Pointer;
import cpp.Char;
import cpp.ConstPointer;
import cpp.Pointer;
import hxnanovg.Nvg;

using cpp.NativeString;

/**
* ...
* @author Hortobágyi Tamás
*/
class DbgTrace
{
var text:String = "";

var fontID:Int;

public function new(fontID:Int)
{
this.fontID = fontID;
}

public function log(s:String)
{
text += (text.length > 0 ? "\n" : "") + s;
}

public function render(vg:Pointer<NvgContext>)
{
if (text.length > 0)
{
Nvg.fontSize(vg, 14.0);
Nvg.fontFaceId(vg, fontID);
Nvg.fillColor(vg, Nvg.rgb(255, 0, 0));

Nvg.textAlign(vg, NvgAlign.ALIGN_LEFT | NvgAlign.ALIGN_TOP);
Nvg.textBox(vg, 10, 100, 400, text.c_str(), untyped __cpp__("NULL"));
}
}
}
Loading