haxiomic / gluon

WebGL implementation for hxcpp
MIT License
24 stars 3 forks source link

Unclear how to compile for c++ #6

Closed nanjizal closed 4 years ago

nanjizal commented 4 years ago

tried linc_glfw and it opens hello world titled window no content on my mac, expected similar with gluon, modified hxml to get something to work...

-main Example
-p ../../
-cpp bin
-cmd ./bin/Example

But the output was purely textual:

haxelib run hxcpp Build.xml haxe -Dhaxe="4.0.2" -Dhaxe3="1" -Dhaxe4="1" -Dhaxe_ver="4.002" -Dhxcpp_api_level="400" -Dhxcpp_smart_strings="1" -Dsource-header="Generated by Haxe 4.0.2" -Dstatic="1" -Dtarget.name="cpp" -Dtarget.static="true" -Dtarget.sys="true" -Dtarget.threaded="true" -Dtarget.unicode="true" -Dtarget.utf16="true" -Dutf16="1" -I"../../" -I"" -I"/usr/local/lib/haxe/extraLibs/" -I"/usr/local/share/haxe/extraLibs/" -I"/usr/local/bin/extraLibs/" -I"/usr/local/lib/haxe/std/cpp/_std/" -I"/usr/local/share/haxe/std/cpp/_std/" -I"/usr/local/bin/std/cpp/_std/" -I"/usr/local/lib/haxe/std/" -I"/usr/local/share/haxe/std/" -I"/usr/local/bin/std/"
Creating /projects/May2019/December/gluon/test/gluon/bin/obj/darwin64/__pch/haxe/hxcpp.h.gch...

Compiling group: haxe
g++ -Iinclude -I/projects/May2019/December/gluon/gluon/es2/impl/include -DGLEW_STATIC -c -fvisibility=hidden -stdlib=libc++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -O2 -I/usr/local/lib/haxeLibrary/hxcpp/git/include -DHX_MACOS -m64 -Wno-parentheses -Wno-unused-value -Wno-format-extra-args -Wno-overflow -DHXCPP_M64 -DHXCPP_VISIT_ALLOCS(haxe) -DHX_SMART_STRINGS(haxe) -DHXCPP_API_LEVEL=400(haxe) ... tags=[haxe,static]
 - src/typedarray/Uint8ArrayImpl.cpp 
 - src/typedarray/_Uint8ClampedArray/Uint8ClampedArray_Impl_.cpp 
 - src/typedarray/_Uint8Array/Uint8Array_Impl_.cpp 
 - src/typedarray/Uint8ClampedArrayImpl.cpp 
 - src/typedarray/Uint32ArrayImpl.cpp 
 - src/typedarray/_Uint32Array/Uint32Array_Impl_.cpp 
 - src/typedarray/Uint16ArrayImpl.cpp 
 - src/typedarray/_Uint16Array/Uint16Array_Impl_.cpp 
 - src/typedarray/Int8ArrayImpl.cpp 
 - src/typedarray/_Int8Array/Int8Array_Impl_.cpp 
 - src/typedarray/Int32ArrayImpl.cpp 
 - src/typedarray/_Int32Array/Int32Array_Impl_.cpp 
 - src/typedarray/Int16ArrayImpl.cpp 
 - src/typedarray/_Int16Array/Int16Array_Impl_.cpp 
 - src/typedarray/Float64ArrayImpl.cpp 
 - src/typedarray/_Float64Array/Float64Array_Impl_.cpp 
 - src/typedarray/Float32ArrayImpl.cpp 
 - src/typedarray/_Float32Array/Float32Array_Impl_.cpp 
 - src/typedarray/_BufferSource/BufferSource_Impl_.cpp 
 - src/typedarray/ArrayBufferViewImplIterator_cpp_UInt8.cpp 
 - src/typedarray/ArrayBufferViewImplIterator_cpp_UInt32.cpp 
 - src/typedarray/ArrayBufferViewImplIterator_cpp_UInt16.cpp 
 - src/typedarray/ArrayBufferViewImplIterator_cpp_Int8.cpp 
 - src/typedarray/ArrayBufferViewImplIterator_cpp_Int32.cpp 
 - src/typedarray/ArrayBufferViewImplIterator_cpp_Int16.cpp 
 - src/typedarray/ArrayBufferViewImplIterator_cpp_Float64.cpp 
 - src/typedarray/ArrayBufferViewImplIterator_cpp_Float32.cpp 
 - src/typedarray/ArrayBufferViewImplIterator.cpp 
 - src/typedarray/ArrayBufferViewBase.cpp 
 - src/typedarray/ArrayBufferView.cpp 
 - src/typedarray/_ArrayBuffer/ArrayBuffer_Impl_.cpp 
 - src/haxe/io/Error.cpp 
 - src/haxe/io/Bytes.cpp 
 - src/gluon/es2/impl/ES2Context.cpp 
 - src/gluon/es2/_GLContext/GLContext_Impl_.cpp 
 - src/Example.cpp 
 - src/__boot__.cpp 
Link: Example
Example.hx:7: Hello from haxe!

Some other setups failed due to xcode paths.

I would love to draw a triangle to screen with gluon with hxcpp so that I can attempt to target it with my library - if that's feasible yet? Advise welcome. Mac 10.12.6.

haxiomic commented 4 years ago

Hey @nanjizal, gluon just handles interfacing with OpenGL, rather than window management. To draw to the screen you can use it in combination with glfw

For example, once you’ve created your glfw window, you can do

var gl = new gluon.es2.impl.ES2Context();
gl.clearColor(0, 1, 0, 1);
gl.clear(COLOR_BUFFER_BIT);

To clear it green

nanjizal commented 4 years ago

I have added some basic setup files to my kitGL for gluon and it's compiling. https://github.com/nanjizal/kitGL/tree/master/src/kitGL/gluon I have setup a basic trilateral3 base for gluon. https://github.com/TrilateralX/TrilateralGluonChange/blob/master/src/trilateralGluonChange/AppGL.hx And created a demo. https://github.com/TrilateralX/TrilateralGluonSVG

But I get a bit confused about running it, I don't think it worked, code requires 4.2 haxe. These are dependancy


-cmd haxelib git trilateralGluonChange https://github.com/TrilateralX/TrilateralGluonChange

-cmd echo 'installing geom library for maths matrix functionality'
--next
-cmd haxelib git geom https://github.com/nanjizal/geom.git

-cmd echo 'installing dsHelper some array datastructures'
--next
-cmd haxelib git dsHelper https://github.com/nanjizal/dsHelper.git

-cmd echo 'installing fracs, provides angles and fraction helpers'
--next
-cmd haxelib git fracs https://github.com/nanjizal/fracs.git

-cmd echo 'installing justPath, provides svg path parsing ability'
--next
-cmd haxelib git justPath https://github.com/nanjizal/justPath.git

-cmd echo 'installing trilateral3, provides contour to triangle functionality'
--next
-cmd haxelib git trilateral3 https://github.com/nanjizal/trilateral3.git

-cmd echo 'installing pallette, provides range of useful hex colours'
--next
-cmd haxelib git pallette https://github.com/nanjizal/pallette.git

-cmd echo 'installing kitGL, provides some helpers for working with GL and lime'
--next
-cmd haxelib git kitGL https://github.com/nanjizal/kitGL.git

-cmd echo 'installing a range of fill algorithms, hxPolyK, poly2trihx, hxGeomAlgo.tess2'
--next
-cmd haxelib git hxPolyK https://github.com/nanjizal/hxPolyK.git
-cmd haxelib git poly2trihx https://github.com/nerik/poly2trihx.git
-cmd echo 'if you get troubles with this one you can comment out code in trilateral3/fill as it's not really used on the test'
-cmd haxelib git hxGeomAlgo https://github.com/azrafe7/hxGeomAlgo.git
nanjizal commented 4 years ago

I would be curious if you can run it, need to have another look at setup files, but this could be useful demo of gluon. Note the structures are similar to WebGL and Lime working tests so likely it's not far off.

haxiomic commented 4 years ago

Hey @nanjizal, are you using anything to create a window and native gl surface?

gluon is super minimal – it essentially just calls gl commands (like glClear()) from haxe, it doesn't create an app window with a native OpenGL surface, which is required to call gl commands

You can use linc_glfw to create the window, then once created, use gluon to call OpenGL commands

nanjizal commented 4 years ago

thanks I updated the code but having weird issues with my hxcpp breaking in justPath it seems to be reading utf16 weird - strange because that library is old, so need to add some basic unit tests and dox to it so I can work out if it's a bug in haxe or in just the dev combo I have installed which might be dodgy.

Updated my base class, is there anything further that you think I might need in the render loop? https://github.com/TrilateralX/TrilateralGluonChange/blob/master/src/trilateralGluonChange/AppGL.hx It's really weird because it's in a while loop the Frame code will never get called. I also had to call it from the inherited class so that the draw function of the inherited class was properly initiated. Really not sure that glfw is really a stable approach it maybe light but if I have to rely on a while loop that blocks the whole code it seem quite iffy. Did you look at linc_sdl would that be much more stable approach?

I think I had to comment out the program build checks, either the shader which now modified is still not right or these bits don't work. https://github.com/nanjizal/kitGL/blob/master/src/kitGL/gluon/HelpGL.hx#L25

haxiomic commented 4 years ago

Hey @nanjizal, sorry on my slow responses, currently working on client projects so my bandwidth for open source is quite low (will pick up again in July however!)

I've attached a gluon demo that uses GLFW which might be useful as a starting point gluon-demo.zip

I've tested haxe 4.0.5 and 4.2.0 on macOS, should also work on Windows but linux is untested. What system are you using?

I know this project doesn't have a lot of details on how to use, this is because this repo is the only public part of a larger closed source project (which does help with windows and things)

Eventually that project will be open source and I'll have full walk-throughs then

nanjizal commented 4 years ago

mac

nanjizal commented 4 years ago

Thanks that code was really useful, I have rebuilt your code to use interleave position and color, and messed with formatting, it helps me learn and if it's in my style I think easier for me to think till I know where I am, hope it's ok public? Probably long way from ideal, I have a slight problem with the data my draw engine is returning - it seems to be just zero but I should be able to debug that a bit later. Currently test repo is here, but need to make approach more generic. The render Loop stuff I may not need all of that but I can pair back when I get real data to render.

https://github.com/nanjizal/glueTest/

haxiomic commented 4 years ago

Cool stuff :), I’ll keep the issue open for now until I’ve got some documentation

nanjizal commented 4 years ago

Currently I am getting... gluon/webgl/GLContextDebug.hx:86: OpenGL Error in "$fnName": $errorName,

I can't try to update Lime without something breaking then I refix everything and gluon is broken, it's very tedious, especially as there is no reliable information on building hxcpp the helper scripts never seem to quite work properly.

Do you have mac build of hxcpp that works with your code against haxe nightly? Do you find it easy to rebuild hxcpp? Do you have eval/jvm approaches perhaps with metal?

haxiomic commented 4 years ago

Look like string interpolation rules have changed in haxe lately, those $variables should be interpolated. I've opened an issue to investigate #10

That trace is trying to tell you that OpenGL has generated an error (these are things like "Framebuffer Invalid"), so it should be independent of hxcpp and haxe, and purely depend on the OpenGL commands being used

Desktop GLSL is slightly different from GLSL ES 2.0, Lime might do something different to shaders that can trigger an OpenGL error in one library and not the other

I'd argue you're best of sticking with a single GPU library because of this, either lime, kha or gluon

nanjizal commented 4 years ago

Haxiomic, what is weird is I don't think I have changed my code from the code posted above, well I was trying to process:

var datum = new Float32Array([
                  0.100, 0.100, 0. , 1, 1, 1, 1
                , 0.500, 0.500, 0. , 1, 1, 1, 1
                , 0.100, 0.500, 0. , 1, 1, 1, 1
                , 0.100, 0.100, 0  , 1, 0, 0, 1
                , 0.500, 0.100, 0  , 1, 0, 0, 1
                , 0.500, 0.500, 0  , 1, 0, 0, 1
                , 0.300, 0.300, 0  , 1, 1, 0, 1
                , 0.400, 0.300, 0  , 1, 1, 0, 1
                , 0.400, 0.400, 0  , 1, 1, 0, 1
            ]);

I don't think the buffer changes you made worked for me, but someone else who tried it seemed to think stuff was now just working and surprised, even with some of my drawing code, but they are on linux?

haxiomic commented 4 years ago

Buffer changes should be working – could it be that an older version of gluon is being used? Maybe uninstall gluon from haxelib and try again from git

Also, check if you have a version in a .haxelib folder that is overriding

Generally I think the local .haxelib/ approach is the best way to manage haxe libraries right now (but a better system is coming soon :))

nanjizal commented 4 years ago

I think it was some changes I made locally in dsHelper, sorry for the noise but I guess it helped find the macro problem. Turns out if I run it with pure webgl I was providing wrong number of vertices.

nanjizal commented 4 years ago

I am going to close this and start clean one.