Misc tweaks (#387)
This commit is contained in:
|
Can't render this file because it is too large.
|
@@ -4,11 +4,11 @@
|
||||
A sample data [European Mammals Red List for 2009] (https://data.europa.eu/euodp/en/data/dataset?res_format=CSV)
|
||||
from EU is being used.
|
||||
|
||||
To build use `./build` script without arguments (or specify `TARGET` variable if cross-compiling).
|
||||
To build use `./build.sh` script without arguments (or specify `TARGET` variable if cross-compiling).
|
||||
|
||||
To run use
|
||||
|
||||
./csvparser.kexe ./European_Mammals_Red_List_Nov_2009.csv 4 100
|
||||
./CsvParser.kexe ./European_Mammals_Red_List_Nov_2009.csv 4 100
|
||||
|
||||
Which will print fifth column (Family, zero-based index) in first 100 rows of the
|
||||
CSV file.
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DIR=.
|
||||
PATH=../../dist/bin:../../bin:$PATH
|
||||
|
||||
if [ x$TARGET == x ]; then
|
||||
case "$OSTYPE" in
|
||||
darwin*) TARGET=macbook ;;
|
||||
linux*) TARGET=linux ;;
|
||||
*) echo "unknown: $OSTYPE" && exit 1;;
|
||||
esac
|
||||
fi
|
||||
|
||||
var=CFLAGS_${TARGET}
|
||||
CFLAGS=${!var}
|
||||
var=LINKER_ARGS_${TARGET}
|
||||
LINKER_ARGS=${!var}
|
||||
var=COMPILER_ARGS_${TARGET}
|
||||
COMPILER_ARGS=${!var} # add -opt for an optimized build.
|
||||
|
||||
interop -def:$DIR/stdio.def -copt:"$CFLAGS" -target:$TARGET || exit 1
|
||||
konanc $COMPILER_ARGS -target $TARGET $DIR/CsvParser.kt stdio -nativelibrary stdiostubs.bc -o CsvParser.kexe || exit 1
|
||||
@@ -1,4 +1,3 @@
|
||||
headers = stdio.h stdlib.h string.h
|
||||
compilerOpts = -D_POSIX_SOURCE
|
||||
linkerOpts =
|
||||
excludedFunctions =
|
||||
@@ -0,0 +1,109 @@
|
||||
import kotlinx.cinterop.*
|
||||
import opengl.*
|
||||
|
||||
// Ported from http://openglsamples.sourceforge.net/projects/index.php/blog/index/
|
||||
|
||||
private var rotation: GLfloat = 0.0f
|
||||
private val rotationSpeed: GLfloat = 0.2f
|
||||
|
||||
private val windowWidth = 640
|
||||
private val windowHeight = 480
|
||||
|
||||
fun display() {
|
||||
// Clear Screen and Depth Buffer
|
||||
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
|
||||
glLoadIdentity()
|
||||
|
||||
// Define a viewing transformation
|
||||
gluLookAt(4.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
|
||||
|
||||
// Push and pop the current matrix stack.
|
||||
// This causes that translations and rotations on this matrix wont influence others.
|
||||
|
||||
glPushMatrix()
|
||||
glColor3f(1.0f, 0.0f, 0.0f)
|
||||
glTranslatef(0.0f, 0.0f, 0.0f)
|
||||
glRotatef(rotation, 0.0f, 1.0f, 0.0f)
|
||||
glRotatef(90.0f, 0.0f, 1.0f, 0.0f)
|
||||
|
||||
// Draw the teapot
|
||||
glutSolidTeapot(1.0)
|
||||
glPopMatrix()
|
||||
|
||||
|
||||
rotation += rotationSpeed
|
||||
glutSwapBuffers()
|
||||
}
|
||||
|
||||
|
||||
fun initialize() {
|
||||
// select projection matrix
|
||||
glMatrixMode(GL_PROJECTION)
|
||||
|
||||
// set the viewport
|
||||
glViewport(0, 0, windowWidth, windowHeight)
|
||||
|
||||
// set matrix mode
|
||||
glMatrixMode(GL_PROJECTION)
|
||||
|
||||
// reset projection matrix
|
||||
glLoadIdentity()
|
||||
val aspect = windowWidth.toDouble() / windowHeight
|
||||
|
||||
// set up a perspective projection matrix
|
||||
gluPerspective(45.0, aspect, 1.0, 500.0)
|
||||
|
||||
// specify which matrix is the current matrix
|
||||
glMatrixMode(GL_MODELVIEW)
|
||||
glShadeModel(GL_SMOOTH)
|
||||
|
||||
// specify the clear value for the depth buffer
|
||||
glClearDepth(1.0)
|
||||
glEnable(GL_DEPTH_TEST)
|
||||
glDepthFunc(GL_LEQUAL)
|
||||
|
||||
// specify implementation-specific hints
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
|
||||
|
||||
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, cValuesOf(0.1f, 0.1f, 0.1f, 1.0f))
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, cValuesOf(0.6f, 0.6f, 0.6f, 1.0f))
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, cValuesOf(0.7f, 0.7f, 0.3f, 1.0f))
|
||||
|
||||
glEnable(GL_LIGHT0)
|
||||
glEnable(GL_COLOR_MATERIAL)
|
||||
glShadeModel(GL_SMOOTH)
|
||||
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE)
|
||||
glDepthFunc(GL_LEQUAL)
|
||||
glEnable(GL_DEPTH_TEST)
|
||||
glEnable(GL_LIGHTING)
|
||||
glEnable(GL_LIGHT0)
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
// initialize and run program
|
||||
memScoped {
|
||||
val argc = alloc<CInt32Var>().apply { value = 0 }
|
||||
glutInit(argc.ptr, null) // TODO: pass real args
|
||||
}
|
||||
|
||||
// Display Mode
|
||||
glutInitDisplayMode(GLUT_RGB or GLUT_DOUBLE or GLUT_DEPTH)
|
||||
|
||||
// Set window size
|
||||
glutInitWindowSize(windowWidth, windowHeight)
|
||||
|
||||
// create Window
|
||||
glutCreateWindow("The GLUT Teapot")
|
||||
|
||||
// register Display Function
|
||||
glutDisplayFunc(staticCFunction(::display))
|
||||
|
||||
// register Idle Function
|
||||
glutIdleFunc(staticCFunction(::display))
|
||||
|
||||
initialize()
|
||||
|
||||
// run GLUT mainloop
|
||||
glutMainLoop()
|
||||
}
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PATH=../../dist/bin:../../bin:$PATH
|
||||
DIR=.
|
||||
|
||||
LINKER_ARGS_macbook="-framework OpenGL -framework GLUT"
|
||||
LINKER_ARGS_linux="-L/usr/lib/x86_64-linux-gnu -lSDL2"
|
||||
|
||||
if [ x$TARGET == x ]; then
|
||||
case "$OSTYPE" in
|
||||
darwin*) TARGET=macbook ;;
|
||||
linux*) TARGET=linux ;;
|
||||
*) echo "unknown: $OSTYPE" && exit 1;;
|
||||
esac
|
||||
fi
|
||||
|
||||
var=CFLAGS_${TARGET}
|
||||
CFLAGS=${!var}
|
||||
var=LINKER_ARGS_${TARGET}
|
||||
LINKER_ARGS=${!var}
|
||||
var=COMPILER_ARGS_${TARGET}
|
||||
COMPILER_ARGS=${!var} # add -opt for an optimized build.
|
||||
|
||||
interop -def:$DIR/opengl.def -target:$TARGET || exit 1
|
||||
konanc -target $TARGET opengl $DIR/OpenGlTeapot.kt -nativelibrary openglstubs.bc -linkerArgs "$LINKER_ARGS" -o OpenGlTeapot.kexe || exit 1
|
||||
@@ -0,0 +1,2 @@
|
||||
headers = GLUT/glut.h
|
||||
compilerOpts = -framework OpenGL -framework GLUT
|
||||
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PATH=../../dist/bin:../../bin:$PATH
|
||||
DIR=.
|
||||
|
||||
if [ x$TARGET == x ]; then
|
||||
case "$OSTYPE" in
|
||||
darwin*) TARGET=macbook ;;
|
||||
linux*) TARGET=linux ;;
|
||||
*) echo "unknown: $OSTYPE" && exit 1;;
|
||||
esac
|
||||
fi
|
||||
|
||||
var=CFLAGS_${TARGET}
|
||||
CFLAGS=${!var}
|
||||
var=LINKER_ARGS_${TARGET}
|
||||
LINKER_ARGS=${!var}
|
||||
var=COMPILER_ARGS_${TARGET}
|
||||
COMPILER_ARGS=${!var} # add -opt for an optimized build.
|
||||
|
||||
interop -def:$DIR/sockets.def -copt:"$CFLAGS" -target:$TARGET || exit 1
|
||||
konanc $COMPILER_ARGS -target $TARGET $DIR/EchoServer.kt sockets -nativelibrary socketsstubs.bc -o EchoServer.kexe || exit 1
|
||||
@@ -6,12 +6,12 @@ of cross-platform game and multimedia applications.
|
||||
|
||||
Start with building compiler by using `dist` and `cross_dist` for cross-targets.
|
||||
To build Tetris application for your host platform use
|
||||
./build
|
||||
./build.sh
|
||||
note that SDL2 must be installed on the host.
|
||||
For cross-compilation to iOS (on Mac host) use
|
||||
TARGET=iphone ./build
|
||||
TARGET=iphone ./build.sh
|
||||
For cross-compilation to Raspberry Pi (on Linux host) use
|
||||
TARGET=raspberrypi ./build
|
||||
TARGET=raspberrypi ./build.sh
|
||||
|
||||
During build process compilation script creates interoperability bindings to SDL2, using SDL C headers,
|
||||
and then compiles an application with the produced bindings.
|
||||
@@ -19,5 +19,5 @@ and then compiles an application with the produced bindings.
|
||||
To deploy executable to iPhone device take Info.plist, then use XCode and your own private signing identity.
|
||||
|
||||
To run on Raspberry Pi one need to install SDL package with `apt-get install libsdl2-2.0.0` on the Pi.
|
||||
Also GLES2 renderer is recommended (use `SDL_RENDER_DRIVER=opengles2 ./tetris.kexe`).
|
||||
Also GLES2 renderer is recommended (use `SDL_RENDER_DRIVER=opengles2 ./Tetris.kexe`).
|
||||
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PATH=../../dist/bin:../../bin:$PATH
|
||||
DIR=.
|
||||
DIST=../../dist
|
||||
DEPS=../../dependencies/all
|
||||
DEPS=$(dirname `type -p konanc`)/../dependencies
|
||||
|
||||
CFLAGS_macbook=-I/Library/Frameworks/SDL2.framework/Headers
|
||||
LINKER_ARGS_macbook="-F /Library/Frameworks -framework SDL2"
|
||||
COMPILER_ARGS_macbook=
|
||||
#CFLAGS_macbook=-I/opt/local/include/SDL2
|
||||
#LINKER_ARGS_macbook="-L/opt/local/lib -lSDL2"
|
||||
CFLAGS_macbook=-I/opt/local/include/SDL2
|
||||
LINKER_ARGS_macbook="-L/opt/local/lib -lSDL2"
|
||||
CFLAGS_linux=-I/usr/include/SDL2
|
||||
LINKER_ARGS_linux="-L/usr/lib/x86_64-linux-gnu -lSDL2"
|
||||
COMPILER_ARGS_linux=
|
||||
@@ -35,6 +35,6 @@ LINKER_ARGS=${!var}
|
||||
var=COMPILER_ARGS_${TARGET}
|
||||
COMPILER_ARGS=${!var} # add -opt for an optimized build.
|
||||
|
||||
$DIST/bin/interop -def:$DIR/sdl.def -copt:"$CFLAGS" -target:$TARGET || exit 1
|
||||
$DIST/bin/konanc $COMPILER_ARGS -target $TARGET sdl $DIR/tetris.kt -nativelibrary sdlstubs.bc -linkerArgs "$LINKER_ARGS" -o tetris.kexe || exit 1
|
||||
#strip tetris.kexe
|
||||
interop -def:$DIR/sdl.def -copt:"$CFLAGS" -target:$TARGET || exit 1
|
||||
konanc $COMPILER_ARGS -target $TARGET sdl $DIR/Tetris.kt -nativelibrary sdlstubs.bc -linkerArgs "$LINKER_ARGS" -o Tetris.kexe || exit 1
|
||||
#strip Tetris.kexe
|
||||
@@ -10,5 +10,3 @@ compilerOpts = -D_POSIX_SOURCE
|
||||
compilerOpts.osx =
|
||||
compilerOpts.linux = -D_REENTRANT
|
||||
compilerOpts.ios =
|
||||
|
||||
linkerOpts.linux = -lm
|
||||
|
||||
Reference in New Issue
Block a user