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

Adapt demo to WebGL (GLES 3) #225

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
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
63 changes: 5 additions & 58 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,60 +1,7 @@
.DS_Store
doc/index.html

*.pbxuser
*.perspectivev3
xcshareddata
xcuserdata
project.xcworkspace
DerivedData
build
Chipmunk-Mac
Chipmunk-iOS
ObjectiveChipmunk-Mac
ObjectiveChipmunk-iOS
generated_docs

CMakeCache.txt
CMakeFiles
Makefile
cmake_install.cmake
install_manifest.txt

*.o
*.obj
*.dll
*.so
*.so.*
*.dylib
*.a
Build/
imgui.ini
obj/
*.wdat
*.exe
*.lib
chipmunk_demos

# Visual studio
*.opensdf
*.opendb
*.sdf
*.suo
*.pdb
*.vcxproj.user
msvc/vc10/demo/ipch/
msvc/vc10/chipmunk/Win32/
msvc/vc10/chipmunk/x64/
msvc/vc10/demo/Win32/
msvc/vc10/demo/x64/
msvc/vc12/chipmunk/Win32/
msvc/vc12/chipmunk/x64/
msvc/vc12/demo/Win32/
msvc/vc12/demo/x64/
msvc/vc13/chipmunk/Win32/
msvc/vc13/chipmunk/x64/
msvc/vc13/demo/Win32/
msvc/vc13/demo/x64/
msvc/vc14/demo/Win32/
msvc/vc14/demo/x64/
*.log
*.tlog
*.db

.vscode
_out/
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Chipmunk2D

## Test the demo live under WebGL2:
## [![Screen Shot](WebGL/Chipmunk.png)](https://cwc-lib.github.io/Chipmunk2D/WebGL/Web_Emsc_Default_OS/App)

## How to build
-Grab the last [Cwc](https://github.com/VLiance/Cwc/releases) Release

-Open the executable, the first use it will asscociate **.cwMake** files. *The menu "Config/Set cwc" do the same thing.*

-Download this repo. Some **.cwMake** is avalaible under the cwc folder. Double click on it, the *Toolchains* and *Libs* will be automatically downloaded, then compiled.

***
66 changes: 0 additions & 66 deletions README.textile

This file was deleted.

Binary file added WebGL/Chipmunk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions WebGL/Web_Emsc_Default_OS/App.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!doctypehtml><html lang=en-us><head><meta charset=utf-8><meta content="text/html; charset=utf-8"http-equiv=Content-Type><link href=# rel="shortcut icon"><link href=Shell_Common.css rel=stylesheet><style></style></head><body><div id=Title><div id=TitleText><h1><script>document.title=location.pathname.substring(location.pathname.lastIndexOf("/")+1).replace(".html",""),document.write(document.title)</script></h1></div></div><nav id=main-nav><ul id=main-menu><li><a onclick=Module.requestFullScreen(!1,!0) style=cursor:pointer title=WebGL>Fullscreen</a></li><li><div id=SrcLink></div><script>function SetLinkSrcCode(n){document.getElementById("SrcLink").innerHTML=n}</script></li></ul></nav><div id=FpsDiv></div><div id=outputContainer><div id=sandbox>Console Loading...</div><script id=tplSandbox type=text/template><div id="outputInc">
<pre class="output"></pre>
</div>

<div class="input">
<textarea rows="1" placeholder="<%= placeholder %>"></textarea>
</div></script><script id=tplCommand type=text/template><% if (! _hidden) { %><span class="command"><span class="<%= _class %>"><%= command %></span></span><% } %></script></div><div id=emscriptenCont><div class=emscripten><progress hidden id=progress max=100 value=0></progress><div class=emscripten_border><div id=status class=emscripten>Downloading...</div><div id=spinner class=spinner></div><canvas class=emscripten height=600 id=canvas oncontextmenu=event.preventDefault() width=800></canvas></div></div></div><script src=Shell_Common.js></script><script>window.onload=Shell_OnLoad</script><script src=App.js async></script></body></html>
17 changes: 17 additions & 0 deletions WebGL/Web_Emsc_Default_OS/App.js

Large diffs are not rendered by default.

292 changes: 292 additions & 0 deletions WebGL/Web_Emsc_Default_OS/Shell_Common.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,292 @@
/* This file is a part of VLiance/WebRT, see relative licence */
html {
min-height:100%;
}
header {
background: #445555;
box-shadow: 0px 0px 5px #BBBBBB;
}
#Title{
position: absolute;
top: -15px;
text-align: Left;
// padding-left: 30px;
// padding-right: 30px;
width: 100%;
height:58px;
border-bottom: 2px solid rgb(20, 20, 20);
color: #EFEFEF;
}
#TitleText {
padding-left: 30px;
}

#main-menu {
padding: 0px;
transition: all 0.3s ease-in-out 0s;
max-height: 20px;
}
#main-nav {
margin: 0px 0px 0px 0px;
padding: 0px;
transition: all 1s ease-in-out 0s;
position: absolute;
left: 50%;
transform: translateX(-50%);
color: #FFFFFF;
top:-2px;
}

#main-nav li{
padding-left: 8px;
padding-right: 8px;
display: inline-block;
vertical-align:middle;
}
#main-nav a{
display: block;
width: 100%;
padding-bottom:7px;
color : #BBBBBB;
text-decoration: none;
box-shadow: none;
transition: box-shadow 0.3s ease-in-out;
}
#main-nav a:hover{
color: #5060E8;
box-shadow: 0px 3px 0px 0px #5060E8;
}

body {
font-family: arial;
margin: 0;
padding: none;
height:100%;
width:100%;
background: #333333;
}

#all {
height: 100%;
}

#page-wrapper {
height: 100%;
}

#emscriptenCont{
transition: all 1s ease-in-out 0s;
position: absolute;
left: 50%;
top:60px;
transform: translateX(-50%);
}

.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
div.emscripten { text-align: center; width:100% }
div.emscripten_border { margin-top: 0px; border: 1px solid #333333; box-shadow: 0px 0px 5px #BBBBBB; display:inline-block;}
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
canvas.emscripten { border: 0px none; transition: all 1s ease-in-out;}

.spinner {
height: 30px;
width: 30px;
margin: 0;
margin-top: 140px;
margin-left: 15px;
display: inline-block;
vertical-align: top;

-webkit-animation: rotation .8s linear infinite;
-moz-animation: rotation .8s linear infinite;
-o-animation: rotation .8s linear infinite;
animation: rotation 0.8s linear infinite;

border-left: 5px solid rgb(235, 235, 235);
border-right: 5px solid rgb(235, 235, 235);
border-bottom: 5px solid rgb(235, 235, 235);
border-top: 5px solid rgb(120, 120, 120);

border-radius: 100%;
background-color: rgb(46, 86, 215);
}

@-webkit-keyframes rotation {
from {-webkit-transform: rotate(0deg);}
to {-webkit-transform: rotate(360deg);}
}
@-moz-keyframes rotation {
from {-moz-transform: rotate(0deg);}
to {-moz-transform: rotate(360deg);}
}
@-o-keyframes rotation {
from {-o-transform: rotate(0deg);}
to {-o-transform: rotate(360deg);}
}
@keyframes rotation {
from {transform: rotate(0deg);}
to {transform: rotate(360deg);}
}

#status {

font-weight: bold;
color: rgb(120, 120, 120);
}

#progress {
height: 20px;
width: 30px;
}

#controls {
display: inline-block;
float: right;
vertical-align: top;
margin-top: 30px;
margin-right: 20px;
}

#outputContainer{

position: absolute;
bottom: 0;
margin-right: 20px;
margin-left: 20px;
margin-bottom: 10px;
}

#outputInc{
overflow-y: auto;
}

#output {
// padding-top: 200px;
// top: 200px;
width: 100%;
background-color: black;
r: white;
font-family: 'Lucida Console', Monaco, monospace;
outline: none;
}

#FpsDiv{
margin-left:100%;
//width:110px;
}

#sandbox,
#sandbox pre.output,
#sandbox pre.output span,
#sandbox textarea,
#sandbox textarea:focus {
font-size:14px;
line-height:1.3;
font-weight: normal;
font-family:"Consolas", "Andale Mono", "Courier New", "Courier", monospace;
border:0 none;
outline:0 none;
-webkit-box-shadow:none;
-moz-box-shadow:none;
box-shadow:none;
}
#sandbox {
color: #ccc;

background: rgba(0, 0, 0, 0.5);

padding: 10px 5px 5px 15px;
-webkit-border-radius: 10px;
-moz-border-radius: 10px;
border-radius: 10px;

border: 1px solid #062E3E;
transition: all 0.3s ease-in-out;
box-shadow: 0px 0px 2px #666666;
margin-top: 8px;

display: table-cell;
vertical-align: bottom;
width: 100vw;
}
#sandbox pre.output {
display:block;
white-space:pre;
width:100%;
overflow-y:auto;
position:relative;
padding:0;
margin:0 0 10px;
border:0 none;
height: 100%;
max-height: calc(100vh - 250px);
}
#sandbox pre.output span { color:#f7f7f7; }
#sandbox pre.output span.command { color:#ccc; }
#sandbox pre.output span.prefix { color:#777; }
#sandbox pre.output span.undefined { color:#777; }
#sandbox pre.output span.string { color:#99f; }
#sandbox pre.output span.number { color:#7f7; }

#sandbox pre.output span.none { color:#89949D; }
#sandbox pre.output span.trace1 { color:#D1D7FC; }
#sandbox pre.output span.trace2 { color:#D89548; }
#sandbox pre.output span.trace3 { color:#829AF0; }
#sandbox pre.output span.pass { color:#41C100; } /*7f7*/
#sandbox pre.output span.warning { color:#FFDD00; }
#sandbox pre.output span.error { color:#f77; }
#sandbox pre.output span.fatal { color:#FF0000; }

#sandbox .input {
padding:0 0 0 15px;
position:relative;
}
#sandbox .input:before {
content:">";
position:absolute;
top: 1px;
left: 0;
color:#ddd
}
#sandbox textarea {
color:#f7f7f7;
background:#1D2A2A ;
border:0 none;
outline:0 none;
padding:0;
margin:0;
resize: none;
width:100%;
overflow:hidden;
}
#sandbox textarea:focus {
outline:0 none;
}

#sandbox pre.output::-webkit-scrollbar,
#sandbox pre.output::-webkit-scrollbar-button,
#sandbox pre.output::-webkit-scrollbar-track,
#sandbox pre.output::-webkit-scrollbar-track-piece,
#sandbox pre.output::-webkit-scrollbar-thumb,
#sandbox pre.output::-webkit-scrollbar-corner,
#sandbox pre.output::-webkit-resizer {
background: transparent;
}
#sandbox pre.output::-webkit-scrollbar {
width: 7px;
height: 7px;
-webkit-border-radius: 4px;
border-radius: 4px;
}
#sandbox pre.output::-webkit-scrollbar-track-piece {
-webkit-border-radius: 5px;
border-radius: 5px;
}
#sandbox pre.output::-webkit-scrollbar-thumb {
background: #4f4f4f;
border-radius: 5px;
}
#sandbox pre.output::-webkit-scrollbar-button {
width:0;
height:0;
}
610 changes: 610 additions & 0 deletions WebGL/Web_Emsc_Default_OS/Shell_Common.js

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions cwc/Build.cwc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-{vFlag}=""
>
-{sOut}={_sPlatform}_{_sConfig_Type}_{_sOpt}
>
-{vIncl}=
-I ../include/
>
;Build Engine
-c ../src/ !../src/cpHastySpace.c -o obj/{sOut}/lib/Chipmunk/
-{vIncl}
>
;Generate Dynamic Lib
-o obj/{sOut}/lib/ -#To Lib/{sOut}/Chipmunk.{_sDynamic}
>
;Generate Static Lib
-o obj/{sOut}/lib/ -#To Lib/{sOut}/libChipmunk.a
>
;Build an Example
-c ../Demo/ -o obj/{sOut}/
-{vIncl}
-{vOS_Flag}
>
;Generate executable
-o obj/{sOut}/ -#To _out/{sOut}/App.*
{vOS_FlagLink}
>
-#Run
Binary file added cwc/Lib/Web_Emsc_Default_OS/Chipmunk.so
Binary file not shown.
Binary file added cwc/Lib/Web_Emsc_Default_OS/libChipmunk.a
Binary file not shown.
Binary file added cwc/Lib/Windows_Default_Debug/Chipmunk.dll
Binary file not shown.
Binary file added cwc/Lib/Windows_Default_Debug/libChipmunk.a
Binary file not shown.
11 changes: 11 additions & 0 deletions cwc/Make_For_Web (Emscripten).cwMake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
;Register Cwc before using a .cwmake
>
-{_sOpt}="OS"
>
-{vOS_FlagLink}=-s USE_WEBGL2=1 |
-{vOS_Flag}=-DSOKOL_GLES3 -fdeclspec -DNDEBUG
>
-{_sDynamic}="so"
>
-#Run Build.cwc -{_wToolchain}= "VLianceTool/WebRT"
-{vPreloadRc}="--preload-file Rc/@Rc/"
10 changes: 10 additions & 0 deletions cwc/Make_For_Windows [Debug].cwMake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;Register Cwc before using a .cwmake
>
-{_sOpt}="Debug"
>
-{vOS_FlagLink}=-lgdi32 |
-{vOS_Flag}=-DSOKOL_GLCORE33
>
-{_sDynamic}="dll"
>
-#Run Build.cwc -{_wToolchain}= VLianceTool/LibRT
10 changes: 10 additions & 0 deletions cwc/Make_For_Windows [Debug][Clang].cwMake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;Register Cwc before using a .cwmake
>
-{_sOpt}="Debug"
>
-{vOS_FlagLink}=-lgdi32 |
-{vOS_Flag}=-DSOKOL_GLCORE33
>
-{_sDynamic}="dll"
>
-#Run Build.cwc -{_wToolchain}= VLianceTool/LibRT[Clang]
10 changes: 10 additions & 0 deletions cwc/Make_For_Windows [Release].cwMake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;Register Cwc before using a .cwmake
>
-{_sOpt}="O2"
>
-{vOS_FlagLink}=-lgdi32 |
-{vOS_Flag}=-DSOKOL_GLCORE33
>
-{_sDynamic}="dll"
>
-#Run Build.cwc -{_wToolchain}= VLianceTool/LibRT
23 changes: 15 additions & 8 deletions demo/ChipmunkDebugDraw.c
Original file line number Diff line number Diff line change
@@ -23,15 +23,21 @@
#include <stddef.h>
#include <string.h>

#include "sokol/sokol_gfx.h"
#include "sokol/sokol.h"

#include "chipmunk/chipmunk_private.h"
#include "ChipmunkDebugDraw.h"

cpTransform ChipmunkDebugDrawVPMatrix;
float ChipmunkDebugDrawPointLineScale = 1.0f;

#define GLSL33(x) "#version 330\n" #x
#ifdef SOKOL_GLCORE33
#define GLSL(x) "#version 330\n" #x
#endif
#ifdef SOKOL_GLES3
#define GLSL(x) "#version 300 es\n" #x
#endif


static sg_bindings bindings;
static sg_pipeline pipeline;
@@ -84,7 +90,7 @@ ChipmunkDebugDrawInit(void)
.size = sizeof(Uniforms),
.uniforms[0] = {.name = "U_vp_matrix", .type = SG_UNIFORMTYPE_MAT4},
},
.vs.source = GLSL33(
.vs.source = GLSL(
layout(location = 0) in vec2 IN_pos;
layout(location = 1) in vec2 IN_uv;
layout(location = 2) in float IN_radius;
@@ -100,15 +106,16 @@ ChipmunkDebugDrawInit(void)
} FRAG;

void main(){
gl_Position = U_vp_matrix*vec4(IN_pos + IN_radius*IN_uv, 0, 1);
gl_Position = U_vp_matrix*vec4(IN_pos + IN_radius*IN_uv, 0.0, 1.0);
FRAG.uv = IN_uv;
FRAG.fill = IN_fill;
FRAG.fill.rgb *= IN_fill.a;
FRAG.outline = IN_outline;
FRAG.outline.a *= IN_outline.a;
}
),
.fs.source = GLSL33(
.fs.source = GLSL(
precision mediump float;
in struct {
vec2 uv;
vec4 fill;
@@ -119,10 +126,10 @@ ChipmunkDebugDrawInit(void)

void main(){
float len = length(FRAG.uv);
float fw = length(fwidth(FRAG.uv));
float mask = smoothstep(-1, fw - 1, -len);
float fw = length(vec2(dFdx(len), dFdy(len)));
float mask = smoothstep(-1.0, fw - 1.0, -len);

float outline = 1 - fw;
float outline = 1.0 - fw;
float outline_mask = smoothstep(outline - fw, outline, len);
vec4 color = FRAG.fill + (FRAG.outline - FRAG.fill*FRAG.outline.a)*outline_mask;
OUT_color = color*mask;
16 changes: 11 additions & 5 deletions demo/ChipmunkDemoTextSupport.c
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@
#include <stddef.h>
#include <string.h>

#include "sokol/sokol_gfx.h"
#include "sokol/sokol.h"

// #include "chipmunk/chipmunk_private.h"
// #include "ChipmunkDemo.h"
@@ -39,7 +39,12 @@ static int glyph_indexes[256];

cpTransform ChipmunkDemoTextMatrix;

#define GLSL33(x) "#version 330\n" #x
#ifdef SOKOL_GLCORE33
#define GLSL(x) "#version 330\n" #x
#endif
#ifdef SOKOL_GLES3
#define GLSL(x) "#version 300 es\n" #x
#endif

static sg_bindings bindings;
static sg_pipeline pipeline;
@@ -102,7 +107,7 @@ ChipmunkDemoTextInit(void)
.size = sizeof(Uniforms),
.uniforms[0] = {.name = "U_vp_matrix", .type = SG_UNIFORMTYPE_MAT4},
},
.vs.source = GLSL33(
.vs.source = GLSL(
layout(location = 0) in vec2 IN_pos;
layout(location = 1) in vec2 IN_uv;
layout(location = 2) in vec4 IN_color;
@@ -115,13 +120,14 @@ ChipmunkDemoTextInit(void)
} FRAG;

void main(){
gl_Position = U_vp_matrix*vec4(IN_pos, 0, 1);
gl_Position = U_vp_matrix*vec4(IN_pos, 0.0, 1.0);
FRAG.uv = IN_uv;
FRAG.color = IN_color;
}
),
.fs.images[0] = {.name = "U_texture", .type = SG_IMAGETYPE_2D},
.fs.source = GLSL33(
.fs.source = GLSL(
precision mediump float;
in struct {
vec2 uv;
vec4 color;
2 changes: 2 additions & 0 deletions demo/sokol/sokol.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#define SOKOL_WIN32_FORCE_MAIN
#ifndef SOKOL_GLES3
#define SOKOL_GLCORE33
#endif
#include "sokol_app.h"
#include "sokol_time.h"
#include "sokol_gfx.h"
8 changes: 8 additions & 0 deletions include/chipmunk/cpMarch.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright 2013 Howling Moon Software. All rights reserved.
// See http://chipmunk2d.net/legal.php for more information.

#ifdef __cplusplus
extern "C" {
#endif

/// Function type used as a callback from the marching squares algorithm to sample an image function.
/// It passes you the point to sample and your context pointer, and you return the density.
typedef cpFloat (*cpMarchSampleFunc)(cpVect point, void *data);
@@ -26,3 +30,7 @@ CP_EXPORT void cpMarchHard(
cpMarchSegmentFunc segment, void *segment_data,
cpMarchSampleFunc sample, void *sample_data
);

#ifdef __cplusplus
}
#endif
8 changes: 8 additions & 0 deletions include/chipmunk/cpPolyline.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Copyright 2013 Howling Moon Software. All rights reserved.
// See http://chipmunk2d.net/legal.php for more information.

#ifdef __cplusplus
extern "C" {
#endif

// Polylines are just arrays of vertexes.
// They are looped if the first vertex is equal to the last.
// cpPolyline structs are intended to be passed by value and destroyed when you are done with them.
@@ -68,3 +72,7 @@ CP_EXPORT void cpPolylineSetCollectSegment(cpVect v0, cpVect v1, cpPolylineSet *
CP_EXPORT cpPolylineSet *cpPolylineConvexDecomposition(cpPolyline *line, cpFloat tol);

#define cpPolylineConvexDecomposition_BETA cpPolylineConvexDecomposition

#ifdef __cplusplus
}
#endif
6 changes: 3 additions & 3 deletions src/cpBody.c
Original file line number Diff line number Diff line change
@@ -103,9 +103,9 @@ cpBodyFree(cpBody *body)
#ifdef NDEBUG
#define cpAssertSaneBody(body)
#else
static void cpv_assert_nan(cpVect v, char *message){cpAssertHard(v.x == v.x && v.y == v.y, message);}
static void cpv_assert_infinite(cpVect v, char *message){cpAssertHard(cpfabs(v.x) != INFINITY && cpfabs(v.y) != INFINITY, message);}
static void cpv_assert_sane(cpVect v, char *message){cpv_assert_nan(v, message); cpv_assert_infinite(v, message);}
static void cpv_assert_nan(cpVect v, const char *message){cpAssertHard(v.x == v.x && v.y == v.y, message);}
static void cpv_assert_infinite(cpVect v, const char *message){cpAssertHard(cpfabs(v.x) != INFINITY && cpfabs(v.y) != INFINITY, message);}
static void cpv_assert_sane(cpVect v, const char *message){cpv_assert_nan(v, message); cpv_assert_infinite(v, message);}

static void
cpBodySanityCheck(const cpBody *body)