Skip to content

Commit

Permalink
glad: Improve documentation and test script.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dav1dde committed May 21, 2016
1 parent 18ac5d5 commit 865dd12
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 48 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,24 @@ the functions needed to initialize glad and load the OpenGL functions.
On non-Windows platforms glad requires `libdl`, make sure to link with it (`L-ldl` for dmd)!


## FAQ ##

### glad includes windows.h which breaks my code!

Defining `APIENTRY` before including `glad.h` solves this problem:

```c
#ifdef _WIN32
#define APIENTRY __stdcall
#endif

#include <glad/glad.h>
```

Relevant issue: [#42](https://github.com/Dav1dde/glad/issues/42)



## Contribute ##

Contributing is easy! Found a bug? Message me or make a pull request! Added a new generator backend?
Expand Down
12 changes: 12 additions & 0 deletions example/c++/hellowindow2.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
#include <iostream>


// We don't want windows.h to be included,
// GLAD will include windows.h for APIENTRY if it was not previously defined
#ifdef _WIN32
#define APIENTRY __stdcall
#endif

// GLAD
#include <glad/glad.h>

// confirm that GLAD didn't include windows.h
#ifdef _WINDOWS_
#error windows.h was included!
#endif

// GLFW
#include <GLFW/glfw3.h>

Expand Down
140 changes: 92 additions & 48 deletions utility/compiletest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,97 +16,141 @@ fi
GCC_FLAGS="-o build/tmp.o -Wall -Werror -ansi -c"
GPP_FLAGS="-o build/tmp.o -Wall -Werror -c"


function echorun {
echo $@
$@
}

function mingwc_compile {
echorun i686-w64-mingw32-gcc $@
echorun x86_64-w64-mingw32-gcc $@
}

function c_compile {
echorun gcc $@ -ldl
mingwc_compile $@
}

function mingwcpp_compile {
echorun i686-w64-mingw32-g++ $@
echorun x86_64-w64-mingw32-g++ $@
}

function cpp_compile {
echorun g++ $@ -ldl
mingwcpp_compile $@
}


function download_if_required {
if [ ! -f $1 ]; then
mkdir -p $(dirname "${1}")
filename=$(basename "${1}")
if [ ! -f ${filename} ]; then
wget -O ${filename} $2
fi
cp ${filename} $1
fi
}


# C
echo -e "====================== Generating and compiling C/C++: ======================"

rm -rf build
$PYTHON -m glad --generator=c --spec=egl --out-path=build
gcc -Ibuild/include build/src/glad_egl.c ${GCC_FLAGS}
g++ -Ibuild/include build/src/glad_egl.c ${GPP_FLAGS}
${PYTHON} -m glad --generator=c --spec=egl --out-path=build
download_if_required build/include/EGL/eglplatform.h "https://www.khronos.org/registry/egl/api/EGL/eglplatform.h"
c_compile -Ibuild/include build/src/glad_egl.c ${GCC_FLAGS}
cpp_compile -Ibuild/include build/src/glad_egl.c ${GPP_FLAGS}

rm -rf build
$PYTHON -m glad --generator=c --spec=gl --out-path=build
gcc -Ibuild/include build/src/glad.c ${GCC_FLAGS}
g++ -Ibuild/include build/src/glad.c ${GPP_FLAGS}
${PYTHON} -m glad --generator=c --spec=gl --out-path=build
c_compile -Ibuild/include build/src/glad.c ${GCC_FLAGS}
cpp_compile -Ibuild/include build/src/glad.c ${GPP_FLAGS}

rm -rf build
$PYTHON -m glad --generator=c --spec=gl --out-path=build
$PYTHON -m glad --generator=c --spec=glx --out-path=build
gcc -Ibuild/include build/src/glad_glx.c ${GCC_FLAGS}
g++ -Ibuild/include build/src/glad_glx.c ${GPP_FLAGS}
${PYTHON} -m glad --generator=c --spec=gl --out-path=build
${PYTHON} -m glad --generator=c --spec=glx --out-path=build
echorun gcc -Ibuild/include build/src/glad_glx.c ${GCC_FLAGS}
echorun g++ -Ibuild/include build/src/glad_glx.c ${GPP_FLAGS}

# Example
gcc example/c/simple.c -o build/simple -Ibuild/include build/src/glad.c -lglut -ldl
g++ example/c++/hellowindow2.cpp -o build/hellowindow2 -Ibuild/include build/src/glad.c -lglfw -ldl
echorun gcc example/c/simple.c -o build/simple -Ibuild/include build/src/glad.c -lglut -ldl
mingwc_compile example/c/simple.c -o build/simple -Ibuild/include build/src/glad.c -lfreeglut
echorun g++ example/c++/hellowindow2.cpp -o build/hellowindow2 -Ibuild/include build/src/glad.c -lglfw -ldl
mingwcpp_compile example/c++/hellowindow2.cpp -o build/hellowindow2 -Ibuild/include build/src/glad.c -lglfw3

rm -rf build
$PYTHON -m glad --generator=c --spec=gl --out-path=build
$PYTHON -m glad --generator=c --spec=wgl --out-path=build
i686-w64-mingw32-gcc -Ibuild/include build/src/glad_wgl.c ${GCC_FLAGS}
i686-w64-mingw32-g++ -Ibuild/include build/src/glad_wgl.c ${GPP_FLAGS}
${PYTHON} -m glad --generator=c --spec=gl --out-path=build
${PYTHON} -m glad --generator=c --spec=wgl --out-path=build
mingwc_compile -Ibuild/include build/src/glad_wgl.c ${GCC_FLAGS}
mingwcpp_compile -Ibuild/include build/src/glad_wgl.c ${GPP_FLAGS}


# C-Debug
echo -e "====================== Generating and compiling C/C++ Debug: ======================"

rm -rf build
$PYTHON -m glad --generator=c-debug --spec=egl --out-path=build
gcc -Ibuild/include build/src/glad_egl.c ${GCC_FLAGS}
g++ -Ibuild/include build/src/glad_egl.c ${GPP_FLAGS}
${PYTHON} -m glad --generator=c-debug --spec=egl --out-path=build
download_if_required build/include/EGL/eglplatform.h "https://www.khronos.org/registry/egl/api/EGL/eglplatform.h"
c_compile -Ibuild/include build/src/glad_egl.c ${GCC_FLAGS}
cpp_compile -Ibuild/include build/src/glad_egl.c ${GPP_FLAGS}

rm -rf build
$PYTHON -m glad --generator=c-debug --spec=gl --out-path=build
gcc -Ibuild/include build/src/glad.c ${GCC_FLAGS}
g++ -Ibuild/include build/src/glad.c ${GPP_FLAGS}
${PYTHON} -m glad --generator=c-debug --spec=gl --out-path=build
c_compile -Ibuild/include build/src/glad.c ${GCC_FLAGS}
cpp_compile -Ibuild/include build/src/glad.c ${GPP_FLAGS}

rm -rf build
$PYTHON -m glad --generator=c-debug --spec=gl --out-path=build
$PYTHON -m glad --generator=c-debug --spec=glx --out-path=build
gcc -Ibuild/include build/src/glad_glx.c ${GCC_FLAGS}
g++ -Ibuild/include build/src/glad_glx.c ${GPP_FLAGS}
${PYTHON} -m glad --generator=c-debug --spec=gl --out-path=build
${PYTHON} -m glad --generator=c-debug --spec=glx --out-path=build
echorun gcc -Ibuild/include build/src/glad_glx.c ${GCC_FLAGS}
echorun g++ -Ibuild/include build/src/glad_glx.c ${GPP_FLAGS}

# Example
gcc example/c/simple.c -o build/simple -Ibuild/include build/src/glad.c -lglut -ldl
g++ example/c++/hellowindow2.cpp -o build/hellowindow2 -Ibuild/include build/src/glad.c -lglfw -ldl
echorun gcc example/c/simple.c -o build/simple -Ibuild/include build/src/glad.c -lglut -ldl
mingwc_compile example/c/simple.c -o build/simple -Ibuild/include build/src/glad.c -lfreeglut
echorun g++ example/c++/hellowindow2.cpp -o build/hellowindow2 -Ibuild/include build/src/glad.c -lglfw -ldl
mingwcpp_compile example/c++/hellowindow2.cpp -o build/hellowindow2 -Ibuild/include build/src/glad.c -lglfw3

rm -rf build
$PYTHON -m glad --generator=c-debug --spec=gl --out-path=build
$PYTHON -m glad --generator=c-debug --spec=wgl --out-path=build
i686-w64-mingw32-gcc -Ibuild/include build/src/glad_wgl.c ${GCC_FLAGS}
i686-w64-mingw32-g++ -Ibuild/include build/src/glad_wgl.c ${GPP_FLAGS}
${PYTHON} -m glad --generator=c-debug --spec=gl --out-path=build
${PYTHON} -m glad --generator=c-debug --spec=wgl --out-path=build
mingwc_compile -Ibuild/include build/src/glad_wgl.c ${GCC_FLAGS}
mingwcpp_compile -Ibuild/include build/src/glad_wgl.c ${GPP_FLAGS}


# D
echo -e "\n====================== Generating and compiling D: ======================"

rm -rf build
$PYTHON -m glad --generator=d --spec=egl --out-path=build
dmd -o- build/glad/egl/*.d -c

${PYTHON} -m glad --generator=d --spec=egl --out-path=build
echorun dmd -o- build/glad/egl/*.d -c

rm -rf build
$PYTHON -m glad --generator=d --spec=gl --api="gl=,gles1=,gles2=" --out-path=build
dmd -o- build/glad/gl/*.d -c
${PYTHON} -m glad --generator=d --spec=gl --api="gl=,gles1=,gles2=" --out-path=build
echorun dmd -o- build/glad/gl/*.d -c

rm -rf build
$PYTHON -m glad --generator=d --spec=gl --out-path=build
$PYTHON -m glad --generator=d --spec=glx --out-path=build
dmd -o- build/glad/glx/*.d -c
${PYTHON} -m glad --generator=d --spec=gl --out-path=build
${PYTHON} -m glad --generator=d --spec=glx --out-path=build
echorun dmd -o- build/glad/glx/*.d -c

rm -rf build
$PYTHON -m glad --generator=d --spec=gl --out-path=build
$PYTHON -m glad --generator=d --spec=wgl --out-path=build
dmd -o- build/glad/wgl/*.d -c
${PYTHON} -m glad --generator=d --spec=gl --out-path=build
${PYTHON} -m glad --generator=d --spec=wgl --out-path=build
echorun dmd -o- build/glad/wgl/*.d -c


# Volt TODO
echo -e "\n====================== Generating Volt: ======================"

rm -rf build
$PYTHON -m glad --generator=volt --spec=egl --out-path=build
$PYTHON -m glad --generator=volt --spec=gl --out-path=build
$PYTHON -m glad --generator=volt --spec=glx --out-path=build
$PYTHON -m glad --generator=volt --spec=wgl --out-path=build
${PYTHON} -m glad --generator=volt --spec=egl --out-path=build
${PYTHON} -m glad --generator=volt --spec=gl --out-path=build
${PYTHON} -m glad --generator=volt --spec=glx --out-path=build
${PYTHON} -m glad --generator=volt --spec=wgl --out-path=build


rm -rf build
rm -rf build

0 comments on commit 865dd12

Please sign in to comment.