Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Sunday, June 5, 2016

Convert JPG pictures to desired size limits

You clicked a selfie and want to reduce its size from some MBs to few KB as a profile pic? Or a huge scanned document to smaller size? There are software to achieve this task.


1. Jpegoptim

This is free open-source app which optimizes jpg files. You can build it from source for whatever supported Operating system your want. I ported it to Android and with ease it allows JPG optimizations and size reduction without changing resolution. Download it from herer - http://play.google.com/store/apps/details?id=org.greh.imagesizereducer



2. ImageMagick 6.9+

This is free, OpenSource and multiplatform application which is available on almost all latest popular Linux distros and can be downloaded on Windows, Mac. Download it and convert images like this command:

convert -define jpeg:extent=100KB input.png output.jpg


There can be some problem in older versions and jpg to jpg might not work. At-least this is what i encountered while converting from jpg to jpg using extent. ImageMagick 6.8.



3. IrfanView + RIOT plugin
Download IrfanView windows app and using jpg saver plugin we can choose target maximum file size.

Saturday, March 12, 2016

Compiling GraphicsMagick (1.3.23) using Android NDK

Compiling GraphicsMagick (1.3.23) using Android NDK


Before starting read this common guide how to build libpng with Android NDK  for most of 
building process as it will be re-writing of same stuff if I write here as well.

After above guide understood and ensured the NDK and other tools are correctly setup.
Follow these step to build GraphicsMagick 1.3.23.
 

Setup:
  • Create directory GM and extract GraphicsMagick 1.3.23 contents inside it. Go inside extracted GM directory.
  • Create directories "prefix" and "dependencies". Instead of prefix you can give names like bin, binaries etc.
  • Copy lib****.a files in GM/dependencies directory. libjasper.a liblzma.a libtiff.a libfreetype.a libjpeg.a libpng.a libwebp.a. If you don't have these libraries then with help of above libpng, webp, FreeType etc guide you can make them.
  • Create GM/dependencies/include directory and copy APIs i.e. headers from all above libraries inside it.
Below is the script to build GraphicsMagick. It does not build c++ apis.


Android Script

# AndroidBuild.sh START
#!/bin/sh
# http://www.ourinnovativemind.in
# http://www.gamesgreh.in

# use custom build environment
export DEPENDENCIES="`pwd`/dependencies"
export INC_DEPENDENCIES=${DEPENDENCIES}/include
export INC_JPEG=${INC_DEPENDENCIES}/jpeg
export INC_PNG=${INC_DEPENDENCIES}/png
export INC_TIFF=${INC_DEPENDENCIES}/tiff
export INC_WEBP=${INC_DEPENDENCIES}/webp
export INC_TTF=${INC_DEPENDENCIES}/ttf
export INC_JASPER=${INC_DEPENDENCIES}/jasper
export INC_LZMA=${INC_DEPENDENCIES}/lzma


export EXTRA_INCLUDES="-I${INC_DEPENDENCIES} -I${INC_JPEG} -I${INC_PNG} -I${INC_TIFF} -I${INC_WEBP} -I${INC_TTF} -I${INC_JASPER} -I${INC_LZMA}"
export EXTRA_LIBS=$DEPENDENCIES


export CONFIGURATION_OPTIONS="--disable-largefile --disable-openmp --without-magick-plus-plus --disable-installed --without-threads --without-x --without-perl --disable-shared --without-gslib"



# use custom build environment

# installation directory
export PREFIX="`pwd`/prefix"

# Path of NDK. For simplicity make symlinks in home directories
export NDK=/home/bindesh/bin/ndk

# processor specific libraries and includes.
# Suffix for arch-???. arch-arm  arch-arm64  arch-mips  arch-mips64  arch-x86  arch-x86_64
export ARCH=arm

# compiler for processor
export CROSS_COMPILE=arm-linux-androideabi

# Android platform version
export PLATFORM=android-8

# GCC compiler version
export GCC_VERSION=4.8


# Getting toolchain directory inside NDK from variables set above
# Hardcoded for linux running on x86 cpu 64-Bit
export ANDROID_PREFIX="${NDK}/toolchains/$CROSS_COMPILE-$GCC_VERSION/prebuilt/linux-x86_64"

# SYSROOT. usr dir i.e. usr/include, usr/lib
export SYSROOT="${NDK}/platforms/$PLATFORM/arch-$ARCH"
export CROSS_PATH="${ANDROID_PREFIX}/bin/${CROSS_COMPILE}"

# Some compiler and binutils. More might be needed depending on source. 
export CPP=${CROSS_PATH}-cpp
export AR=${CROSS_PATH}-ar
export AS=${CROSS_PATH}-as
export NM=${CROSS_PATH}-nm
export CC=${CROSS_PATH}-gcc
export CXX=${CROSS_PATH}-g++
export LD=${CROSS_PATH}-ld
export RANLIB=${CROSS_PATH}-ranlib

# for C++ extra libs
export CXX_SYSROOT=${NDK}/sources/cxx-stl/gnu-libstdc++/${COMPILER_VERSION}  # standard template library
export CXX_BITS_INCLUDE=${CXX_SYSROOT}/libs/armeabi/include

export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig


# Flags for compiler
export CFLAGS="${CFLAGS} --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include ${EXTRA_INCLUDES}"
export CPPFLAGS="${CFLAGS}"
export LDFLAGS="${LDFLAGS} -L${SYSROOT}/usr/lib -L${ANDROID_PREFIX}/lib -L${EXTRA_LIBS}"


./configure --host=${CROSS_COMPILE} --with-sysroot=${SYSROOT} --prefix=${PREFIX} "$@" $CONFIGURATION_OPTIONS
make
make install
# AndroidBuild.sh END


Copy all lines above and paste in a new file AndroidBuild.sh and save. Then change the 
variables valid for your system. Create folder prefix or whatever name you like. 
Change NDK variable and compiler related values as per your system.
This script copied from web can cause error due to removal of newlines for strange reasons.
Ensure # is ahead of comments. 
 Now run sh AndroidBuild.sh. It should end without errors. This will install all built files
in prefix directory. Now we can copy libpng16.a renamed to libpng.a and headers directory.


Links:

Script file
http://txt.do/5ns57 or http://textuploader.com/5ns57

Friday, March 11, 2016

Building webp library (libwebp-0.4.4) using Android NDK

My setup:
  • OpenSuse Linux Leap 42.1.20151028 x86_64 (64Bit), AMD Athlon X2
  • Android NDK r10e­rc4 (64­bit). Directory name android­ndk­r10e­linux
  • Terminal / Bash shell. On Windows one needs to install binutils, development environment. Just install CodeBlocks windows or other such compiler. They contain most of needed tools.

The title of this post can also be "compile libwebp-0.4.4.tar.gz without Android Studio or without Eclipse". Compile library using ndk-build without android project.


To compile a jni code Android NDK requires a layout of files. We will blind NDK to believe there is an android project and it will compile. Since libwebp (atleast 0.4.4) already contains Android.mk its very easy to compile it.

To create blind NDK assuming there is Android project follow these steps:
  • Create a directory webp. Create jni directory inside it. Extract libweb inside jni. path to libweb Android. mk must be webp/jni/libwebp-0.4.4/Android.mk
  • Create Android.mk & Application.mk files inside jni.
  • Create AndroidManifest.xml above jni directory.


Contents of files:


webp/jni/Android.mk

include  $(call all-subdir-makefiles)


webp/jni/Application.mk

APP_ABI := armeabi-v7a
APP_PLATFORM := android-8
APP_OPTIM := release




webp/AndroidManifest.xml
File content is saved in linked file due to xml getting stripped in this blog.

Link: http://txt.do/5vik0 or http://textuploader.com/5vik0 




Building:
Ensure you have NDK in path environment. It means you can run ndk-build without giving full path. If not then add it in path variable Or simply run /fullpath/ndk-build script from webp/ directory. it will start building webp.


After build is complete the binary files are copied into webp/libs and webp/obj/local. libwebp.a is present in obj/local/armeabi-v7a directory.



Below is the log from my system:


bindesh@linux-k2zc:/mnt/work/work/programming/Android/00_libraries/libwebp/libwebp-0.4.4> ndk-build
[armeabi-v7a] Compile thumb  : cwebp <= cwebp.c
[armeabi-v7a] Compile thumb  : cwebp <= jpegdec.c
[armeabi-v7a] Compile thumb  : cwebp <= metadata.c
[armeabi-v7a] Compile thumb  : cwebp <= pngdec.c
[armeabi-v7a] Compile thumb  : cwebp <= tiffdec.c
[armeabi-v7a] Compile thumb  : cwebp <= webpdec.c
[armeabi-v7a] Compile thumb  : example_util <= example_util.c
[armeabi-v7a] StaticLibrary  : libexample_util.a
[armeabi-v7a] Compile arm    : webp <= enc.c
[armeabi-v7a] Compile arm    : webp <= enc_avx2.c
[armeabi-v7a] Compile arm    : webp <= enc_mips32.c
[armeabi-v7a] Compile arm    : webp <= enc_neon.c
[armeabi-v7a] Compile arm    : webp <= enc_sse2.c
[armeabi-v7a] Compile arm    : webp <= alpha.c
[armeabi-v7a] Compile arm    : webp <= analysis.c
[armeabi-v7a] Compile arm    : webp <= backward_references.c
[armeabi-v7a] Compile arm    : webp <= config.c
[armeabi-v7a] Compile arm    : webp <= cost.c
[armeabi-v7a] Compile arm    : webp <= filter.c
[armeabi-v7a] Compile arm    : webp <= frame.c
[armeabi-v7a] Compile arm    : webp <= histogram.c
[armeabi-v7a] Compile arm    : webp <= iterator.c
[armeabi-v7a] Compile arm    : webp <= picture.c
[armeabi-v7a] Compile arm    : webp <= picture_csp.c
[armeabi-v7a] Compile arm    : webp <= picture_psnr.c
[armeabi-v7a] Compile arm    : webp <= picture_rescale.c
[armeabi-v7a] Compile arm    : webp <= picture_tools.c
[armeabi-v7a] Compile arm    : webp <= quant.c
[armeabi-v7a] Compile arm    : webp <= syntax.c
[armeabi-v7a] Compile arm    : webp <= token.c
[armeabi-v7a] Compile arm    : webp <= tree.c
[armeabi-v7a] Compile arm    : webp <= vp8l.c
[armeabi-v7a] Compile arm    : webp <= webpenc.c
[armeabi-v7a] Compile arm    : webp <= bit_writer.c
[armeabi-v7a] Compile arm    : webp <= huffman_encode.c
[armeabi-v7a] Compile arm    : webp <= quant_levels.c
[armeabi-v7a] StaticLibrary  : libwebp.a
[armeabi-v7a] Compile thumb  : cpufeatures <= cpu-features.c
[armeabi-v7a] StaticLibrary  : libcpufeatures.a
[armeabi-v7a] Compile arm    : webpdecoder_static <= alpha.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= buffer.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= frame.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= idec.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= io.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= quant.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= tree.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= vp8.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= vp8l.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= webp.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= alpha_processing.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= alpha_processing_sse2.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= cpu.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= dec.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= dec_clip_tables.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= dec_mips32.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= dec_neon.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= dec_sse2.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= lossless.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= lossless_mips32.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= lossless_neon.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= lossless_sse2.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= upsampling.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= upsampling_neon.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= upsampling_sse2.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= yuv.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= yuv_mips32.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= yuv_sse2.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= bit_reader.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= color_cache.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= filters.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= huffman.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= quant_levels_dec.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= random.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= rescaler.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= thread.c
[armeabi-v7a] Compile arm    : webpdecoder_static <= utils.c
[armeabi-v7a] StaticLibrary  : libwebpdecoder_static.a
[armeabi-v7a] Executable     : cwebp
[armeabi-v7a] Install        : cwebp => libs/armeabi-v7a/cwebp
[armeabi-v7a] Compile thumb  : dwebp <= dwebp.c
[armeabi-v7a] Executable     : dwebp
[armeabi-v7a] Install        : dwebp => libs/armeabi-v7a/dwebp
[armeabi-v7a] Compile thumb  : webpmux_example <= webpmux.c
[armeabi-v7a] Compile arm    : webpmux <= muxedit.c
[armeabi-v7a] Compile arm    : webpmux <= muxinternal.c
[armeabi-v7a] Compile arm    : webpmux <= muxread.c
[armeabi-v7a] StaticLibrary  : libwebpmux.a
[armeabi-v7a] Executable     : webpmux_example
[armeabi-v7a] Install        : webpmux_example => libs/armeabi-v7a/webpmux_example

Compiling FreeType (2.6.3) using Android NDK.

My setup:

  • OpenSuse Linux Leap 42.1.20151028 x86_64 (64Bit), AMD Athlon X2
  • Android NDK r10e-rc4 (64-bit). Directory name android-ndk-r10e-linux
  • Terminal / Bash shell. On Windows one needs to install binutils, development environment. Just install CodeBlocks windows or other such compiler. They contain most of needed tools.


Before starting please read setup and brief of how libpng is compiled. It is a waste if I write same thing repeatedly.

Link: http://www.ourinnovativemind.in/2016/03/how-to-compile-libpng-using-android-ndk.html


Starting steps same as libpng project:
  • Download Android NDK and extract/install to a path without containing space or special characters. If using Linux then make symbolic link to home.
  • Download FreeType package version 2.6.3
  • Create a working directory where package will be compiled. Extract package.


# AndroidBuild.sh START

#!/bin/sh
# http://www.ourinnovativemind.in
# http://www.gamesgreh.in

# Add configure options here
export CONFIGURATION_OPTIONS="--enable-static --disable-shared --with-bzip2=no"

# use custom build environment

# installation directory
export PREFIX=`pwd`/prefix

# Path of NDK. For simplicity make symlinks in home directories
export NDK=/mnt/work/SDK_IDE/android-ndk-r10e-linux/

# processor specific libraries and includes.
# Suffix for arch-???. arch-arm arch-arm64 arch-mips arch-mips64 arch-x86 arch-x86_64
export ARCH=arm

# compiler for processor
export CROSS_COMPILE=arm-linux-androideabi

# Android platform version
export PLATFORM=android-8

# GCC compiler version
export GCC_VERSION=4.8


# Getting toolchain directory inside NDK from variables set above
# Hardcoded for linux running on x86 cpu 64-Bit
export ANDROID_PREFIX=${NDK}/toolchains/$CROSS_COMPILE-$GCC_VERSION/prebuilt/linux-x86_64

# SYSROOT. usr dir i.e. usr/include, usr/lib
export SYSROOT=${NDK}/platforms/$PLATFORM/arch-$ARCH
export CROSS_PATH=${ANDROID_PREFIX}/bin/${CROSS_COMPILE}

# Some compiler and binutils. More might be needed depending on source.
export CPP=${CROSS_PATH}-cpp
export AR=${CROSS_PATH}-ar
export AS=${CROSS_PATH}-as
export NM=${CROSS_PATH}-nm
export CC=${CROSS_PATH}-gcc
export CXX=${CROSS_PATH}-g++
export LD=${CROSS_PATH}-ld
export RANLIB=${CROSS_PATH}-ranlib

# package configuration file save location
export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig

# Flags for compiler
export CFLAGS="${CFLAGS} --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include"
export CPPFLAGS="${CFLAGS}"
export LDFLAGS="${LDFLAGS} -L${SYSROOT}/usr/lib -L${ANDROID_PREFIX}/lib"

#$@
./configure --host=${CROSS_COMPILE} --with-sysroot=${SYSROOT} --prefix=${PREFIX} "$@" $CONFIGURATION_OPTIONS
make
make install

# AndroidBuild.sh END








Copy all lines above and paste in a new file AndroidBuild.sh and save. Then change the variables valid for your system. Create folder prefix or whatever name you like. Change NDK=/mnt/work/SDK_IDE/android-ndk-r10e-linux/ and compiler related values as per your system. This script copied from web can cause error due to removal of newlines for strange reasons. Ensure # is ahead of comments. Now run sh AndroidBuild.sh. It should end without errors. This will install all built files in prefix directory.

Links:
Script file http://txt.do/5vi0z or http://textuploader.com/5vi0z!



Below is output of console if you want to compare it with yours:





bindesh@linux-k2zc:/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3> sh AndroidBuild.sh

FreeType build system -- automatic system detection

The following settings are used:

platform unix
compiler /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
configuration directory ./builds/unix
configuration rules ./builds/unix/unix.mk

If this does not correspond to your system or settings please remove the file
`config.mk' from this directory then read the INSTALL file for help.

Otherwise, simply type `make' again to build the library,
or `make refdoc' to build the API reference (this needs python >= 2.6).

cd builds/unix; \
./configure '--host=arm-linux-androideabi' '--with-sysroot=/mnt/work/SDK_IDE/android-ndk-r10e-linux//platforms/android-8/arch-arm' '--prefix=/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix' '--enable-static' '--disable-shared' '--with-bzip2=no'
configure: loading site script /usr/share/site/x86_64-unknown-linux-gnu
checking build system type... x86_64-pc-linux-gnu
checking host system type... arm-unknown-linux-androideabi
checking for arm-linux-androideabi-gcc... /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... yes
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc accepts -g... yes
checking for /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-cpp
checking for arm-linux-androideabi-pkg-config... no
checking for pkg-config... /usr/bin/pkg-config
configure: WARNING: using cross tools not prefixed with host triplet
checking pkg-config is at least version 0.24... yes
checking how to print strings... printf
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc... /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld
checking if the linker (/mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-nm
checking the name lister (/mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-nm) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to arm-unknown-linux-androideabi format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld option to reload object files... -r
checking for arm-linux-androideabi-objdump... no
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for arm-linux-androideabi-dlltool... no
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for arm-linux-androideabi-ar... /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ar
checking for archiver @FILE support... @
checking for arm-linux-androideabi-strip... no
checking for strip... strip
checking for arm-linux-androideabi-ranlib... /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ranlib
checking for gawk... gawk
checking command to parse /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-nm output from /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc object... ok
checking for sysroot... /mnt/work/SDK_IDE/android-ndk-r10e-linux//platforms/android-8/arch-arm
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for arm-linux-androideabi-mt... no
checking for mt... mt
checking if mt is a manifest tool... no
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc supports -fno-rtti -fno-exceptions... no
checking for /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc option to produce PIC... -fPIC -DPIC
checking if /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc PIC flag -fPIC -DPIC works... yes
checking if /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc static flag -static works... yes
checking if /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc supports -c -o file.o... yes
checking if /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc supports -c -o file.o... (cached) yes
checking whether the /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc linker (/mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld) supports shared libraries... yes
checking dynamic linker characteristics... Android linker
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... no
checking whether to build static libraries... yes
checking for x86_64-pc-linux-gnu-gcc... no
checking for gcc... gcc
checking for gcc... (cached) gcc
checking for suffix of native executables...
checking for a BSD-compatible install... /usr/bin/install -c
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for ANSI C header files... (cached) yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking for unistd.h... (cached) yes
checking for an ANSI C-conforming const... yes
checking size of int... 4
checking size of long... 4
checking whether cpp computation of bit length in ftconfig.in works... yes
checking for stdlib.h... (cached) yes
checking for unistd.h... (cached) yes
checking for sys/param.h... yes
checking for getpagesize... no
checking for working mmap... no
checking for memcpy... yes
checking for memmove... yes
checking gcc compiler flag -pedantic to assure ANSI C works correctly... ok, add it to XX_ANSIFLAGS
checking gcc compiler flag -ansi to assure ANSI C works correctly... ok, add it to XX_ANSIFLAGS
checking for ZLIB... yes
checking for LIBPNG... yes
checking for HARFBUZZ... yes
configure: creating ./config.status
config.status: creating unix-cc.mk
config.status: creating unix-def.mk
config.status: creating ftconfig.h
config.status: executing libtool commands
configure:

Library configuration:
external zlib: yes (pkg-config)
bzip2: no
libpng: yes (pkg-config)
harfbuzz: yes (pkg-config)

make: Nothing to be done for 'unix'.
make: Nothing to be done for 'all'.
rm -rf /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/include/freetype2
rm -f /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/include/ft2build.h
/usr/bin/mkdir -p /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/lib \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/lib/pkgconfig \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/include/freetype2/freetype/config \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/bin \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/share/aclocal \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/share/man/man1
./builds/unix/libtool --mode=install /usr/bin/install -c \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/objs/libfreetype.la /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/lib
libtool: install: /usr/bin/install -c /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/objs/.libs/libfreetype.lai /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/lib/libfreetype.la
libtool: install: /usr/bin/install -c /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/objs/.libs/libfreetype.a /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/lib/libfreetype.a
libtool: install: chmod 644 /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/lib/libfreetype.a
libtool: install: /mnt/work/SDK_IDE/android-ndk-r10e-linux//toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ranlib /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/lib/libfreetype.a
for P in /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/tttables.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftoutln.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftstroke.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/t1tables.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/fterrors.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftcid.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftbitmap.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftmodapi.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftsystem.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftcffdrv.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftautoh.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftsynth.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftlcdfil.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftpfr.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftsizes.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftrender.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftlzw.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftfntfmt.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftglyph.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftlist.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftincrem.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftchapters.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftbdf.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftcache.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ttnameid.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftgzip.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftbzip2.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftmac.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/freetype.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftwinfnt.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/fttypes.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftotval.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftbbox.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftmm.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftadvanc.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftttdrv.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftmoderr.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftgasp.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftgxval.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftsnames.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/tttags.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ttunpat.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/fterrdef.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/fttrigon.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/ftimage.h ; do \
/usr/bin/install -c -m 644 \
$P /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/include/freetype2/freetype ; \
done
for P in /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/config/ftstdlib.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/config/ftconfig.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/config/ftmodule.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/config/ftoption.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/freetype/config/ftheader.h /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/objs/ftmodule.h ; do \
/usr/bin/install -c -m 644 \
$P /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/include/freetype2/freetype/config ; \
done
/usr/bin/install -c -m 644 /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/include/ft2build.h \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/include/freetype2/ft2build.h
/usr/bin/install -c -m 644 ./builds/unix/ftconfig.h \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/include/freetype2/freetype/config/ftconfig.h
/usr/bin/install -c -m 644 /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/objs/ftmodule.h \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/include/freetype2/freetype/config/ftmodule.h
/usr/bin/install -c -m 755 ./builds/unix/freetype-config \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/bin/freetype-config
/usr/bin/install -c -m 644 ./builds/unix/freetype2.m4 \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/share/aclocal/freetype2.m4
/usr/bin/install -c -m 644 ./builds/unix/freetype2.pc \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/lib/pkgconfig/freetype2.pc
/usr/bin/install -c -m 644 /mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/docs/freetype-config.1 \
/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3/prefix/share/man/man1/freetype-config.1
bindesh@linux-k2zc:/mnt/work/work/programming/Android/00_libraries/freetype/freetype-2.6.3>

Thursday, March 10, 2016

How to compile libpng using Android NDK?

To build libpng 1.6.28 with Android Studio 2.2 based tools like CMake, Ninja please look at this article.

http://www.ourinnovativemind.in/2017/02/new-building-libpng-1628-using-android.html



Below method uses ndk-build to build libpng.


This page is for you if want to compile libpng for Android or just got a warning mail from Google PlayStore regading libpng vulnerability issue of old versions. "Google Play warning: You are using vulnerable version of libpng". This article/tutorial is about compiling libpng 1..6.19 for Android.



My setup:
  • OpenSuse Linux Leap 42.1.20151028 x86_64 (64Bit), AMD Athlon X2
  • Android NDK r10e-rc4 (64-bit). Directory name android-ndk-r10e-linux
  • Terminal / Bash shell. On Windows one needs to install binutils, development environment. Just install CodeBlocks windows or other such compiler. They contain most of needed tools.


Because my setup is Linux with disk limit due to 128GB SSD i have not installed 2 set of tools for each OS i.e. Linux and Windows. However it will not take more than minute to change the scripts to Windows. Most of my scripts are hard-coded for 64Bit Linux. Kindly change the variables to your NDK to let the scripts run bug free. Or for a person who just needs Android.mk file simply copy the content from end of this article.


Starting steps:
  • Download Android NDK and extract/install to a path without containing space or special characters. If using Linux then make symbolic link to home.
  • Download libpng version 1.6.19 (November 12, 2015)
  • Create a working directory where libpng will be compiled. Extract libpng.

Extracted libpng contains many files like README, TODO etc. One should read them as they contain important information. Before compiling libpng must be made aware of where compiler, other compiler related tools, headers and objects (compiled code) are saved. This information is collected by configure script. If interested open “configure” file in text editor and scroll to end. There are below lines -



# Assembler program.
AS=$lt_AS


# DLL creation program.
DLLTOOL=$lt_DLLTOOL

# Object dumper program.
OBJDUMP=$lt_OBJDUMP

# Whether or not to build shared libraries.
build_libtool_libs=$enable_shared

# The PATH separator for the build system.
PATH_SEPARATOR=$lt_PATH_SEPARATOR

# The host system.
host_alias=$host_alias
host=$host
host_os=$host_os



SED, GREP, FGREP, ECHO etc near end of file. These are the stuff configure script requires to build the final Makefile. We have to provide these things to configure script. After I started building libraries like libpng, FreeType, ImageMagick, GraphicsMagick etc for Android I collected some scripts from various sources like stackoverflow and build this script. It contains some hard-coded values but that takes minute to change as per system.


If project is small and contains few files we can build source without configure script or even Makefile. It is recommended that we understand the basics of this system. For example look at scripts directory there are many makefile.PLATFORM files where PLATFORM = msys, linux etc. We can use those makefiles to build a working Makefile or get information about build flags etc. But that's not easier than configure script.


Android Script

# AndroidBuild.sh START
#!/bin/sh
# remove flag for non neon ARM processors.

export HAS_NEON="--enable-arm-neon"
export CONFIGURATION_OPTIONS="--disable-shared $HAS_NEON"

# use custom build environment
# installation directory
export PREFIX=`pwd`/prefix

# Path of NDK. For simplicity make symlinks in home directories
export NDK=/mnt/work/SDK_IDE/android-ndk-r10e-linux/

#export NDK=/home/bindesh/bin/ndk (SYMLINK)
# processor specific libraries and includes.
# Suffix for arch-???. arch-arm arch-arm64 arch-mips arch-mips64 arch-x86 arch-x86_64
export ARCH=arm
 

# compiler for processor
export CROSS_COMPILE=arm-linux-androideabi

# Android platform version
export PLATFORM=android-8

# GCC compiler version
export GCC_VERSION=4.8

# Getting toolchain directory inside NDK from variables set above
# Hardcoded for linux running on x86 cpu 64-Bit
export ANDROID_PREFIX=${NDK}/toolchains/$CROSS_COMPILE-$GCC_VERSION/prebuilt/linux-x86_64

# SYSROOT. usr dir i.e. usr/include, usr/lib
export SYSROOT=${NDK}/platforms/$PLATFORM/arch-$ARCH
export CROSS_PATH=${ANDROID_PREFIX}/bin/${CROSS_COMPILE}

# Some compiler and binutils. More might be needed depending on source.
export CPP=${CROSS_PATH}-cpp
export AR=${CROSS_PATH}-ar
export AS=${CROSS_PATH}-as
export NM=${CROSS_PATH}-nm
export CC=${CROSS_PATH}-gcc
export CXX=${CROSS_PATH}-g++
export LD=${CROSS_PATH}-ld
export RANLIB=${CROSS_PATH}-ranlib

# package configuration file save location
export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig

# Flags for compiler
export CFLAGS="${CFLAGS} --sysroot=${SYSROOT} -I${SYSROOT}/usr/include -I${ANDROID_PREFIX}/include"

export CPPFLAGS="${CFLAGS}"
export LDFLAGS="${LDFLAGS} -L${SYSROOT}/usr/lib -L${ANDROID_PREFIX}/lib"

./configure --host=${CROSS_COMPILE} --with-sysroot=${SYSROOT} --prefix=${PREFIX} "$@" $CONFIGURATION_OPTIONS

make
make install
 

# AndroidBuild.sh END



Copy all lines above and paste in a new file AndroidBuild.sh and save. Then change the variables valid for your system. Create folder prefix or whatever name you like. Change NDK=/mnt/work/SDK_IDE/android-ndk-r10e-linux/ and compiler related values as per your system. This script copied from web can cause error due to removal of newlines for strange reasons. Ensure # is ahead of comments.

Now run sh AndroidBuild.sh. It should end without errors. This will install all built files in prefix directory. Now we can copy libpng16.a renamed to libpng.a and headers directory.

Links: Script file http://txt.do/5vb70 Or http://textuploader.com/5vb70


Above script is common to most of tasks and is best for building most of C libraries. To add C++support more variables are needed. Some possible errors:

  • Error in running compiler tools. This can be due to incorrect final paths of build tools. Look at config.log and cross check if resulting paths are correct.
  • Error in finding libraries. This can be because of wrong names of libraries and -l parameter to compiler. Ensure path and names are correct. Configure script runs a lot of tests which tests each used libraries with a small sample code. Check the results of these sample codes in config.log.

If everything seems not working then ensure the installation of tools is correct and they do their job. Make simple programs and test them. Test NDK with Android Studio or Eclipse. Do these types of tests. I myself have spent time frustrated with these types of problems. In Linux i even suffered problems like executable flag of executable files were removed due to unknown reason!.



Android.mk


LOCAL_PATH := $(call my-dir)

# $(call my-dir) return path of this Android.mk directory

PNG_SRC_PATH    :=
INC_PNG                := $(LOCAL_PATH)/


include $(CLEAR_VARS)

LOCAL_MODULE    := libpng
LOCAL_CFLAGS    :=
LOCAL_CPPFLAGS  := ${LOCAL_CFLAGS}

LOCAL_C_INCLUDES  :=  \
    ${INC_PNG} \
       
LOCAL_SRC_FILES := \
    ${PNG_SRC_PATH}pngerror.c \
    ${PNG_SRC_PATH}pngwio.c \
    ${PNG_SRC_PATH}pngwrite.c \
    ${PNG_SRC_PATH}pngwutil.c \
    ${PNG_SRC_PATH}pngwtran.c \
    ${PNG_SRC_PATH}pngset.c \
    ${PNG_SRC_PATH}pngtrans.c \
    ${PNG_SRC_PATH}example.c \
    ${PNG_SRC_PATH}png.c \
    ${PNG_SRC_PATH}pngrtran.c \
    ${PNG_SRC_PATH}pngmem.c \
    ${PNG_SRC_PATH}pngpread.c \
    ${PNG_SRC_PATH}pngrutil.c \
    ${PNG_SRC_PATH}pngrio.c \
    ${PNG_SRC_PATH}pngget.c \
    ${PNG_SRC_PATH}pngread.c
   
   
   

ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)

  LOCAL_SRC_FILES += ${PNG_SRC_PATH}arm/arm_init.c
  LOCAL_SRC_FILES += ${PNG_SRC_PATH}arm/filter_neon.S
  LOCAL_SRC_FILES += ${PNG_SRC_PATH}arm/filter_neon_intrinsics.c
endif


LOCAL_LDLIBS    := -llog -L../lib
# -lz -lm

include $(BUILD_STATIC_LIBRARY)

Monday, May 30, 2011

Lots of Linux, OpenSource, games

I was looking for some gimp tutorials and via pics i found this great Linux game collection site, this is a must visit for people demanding games on Linux distros. Below is the link:

http://www.playdeb.net/

Wednesday, March 16, 2011

Smoother motion using Interpolation.

I found this page last year (2010) and would like to recommend as must read if you are related to physics motion by programming.

LINK: http://sol.gfxile.net/interpolation/

Tuesday, January 11, 2011

What are UV / ST texture coordinates and UV mapping ?

I know many of you might be having trouble in understanding what UV/ST are. I too had during beginning of OpenGL texturing. Before eating too much time its just:

(U,V) = (X,Y) of texture.

U = X pixel position of image / image width ;
V = Y pixel position of image / image height ;

And we know how to cap something between 0 to 1 range. Just divide it by the maximum that's why we are dividing pixel position by width and height just to cap it between 0 to 1 range.

Now we do simple maths, multiply U value by 100 and we get pixel position in %age.
suppose U = 0.4 and V = 0.6, it simply means
40% width, and 60% height.

U is pointing to position = 0 + 40% of image width
V is pointing to position = 0 + 60% of image height

That is why texture coordinate system becomes
left = 0 (lowest width), right = 1 (max width)
bottom = 0 (lowest height), top = 1 (max height)


Image Source: = http://paulyg.f2s.com/graphics/uvexp.gif


EDIT:
Now what UV mapping is?
I'll try to explain in lame language.

Assume a triangle as your polygon data and a rectangular, balloon like, nonrigid sheet as texture, here we want to cover the triangle with desired portions of that sheet, what should we do in real world? Of-course we will try to stretch it around triangle in all possible ways,  we can start from wherever we want but limitation is simple, we have got 3 points to staple that sheet. this is exactly what OpenGL does. It asks which part of the texture you want to be mapped into which vertex of polygon. We can't tell OpenGL that hey put this UV in center on the polygon!

That's why the higher the number of vertices we have in polygon the better mapping we can do.

But in actual programming, we can assign almost any UV to any vertex. That would make the triangle with unusual patterns. I haven't tested this :-), try this in 3D modelling programs like Blender if you wanna save your time and experiment quickly on UV mapping. Then export your simple mesh into OBJ format, which you can read on text editors as well.

The best resources for studying OpenGL, OpenGL ES

I learned OpenGL in 2009 and completed my Greh game engine in mid 2010 with my own Game framework for menu, sounds, ai, collision etc.

However i would like to help others in their journey for OpenGL. I strongly recommend reading these resources instead of buying many books. Switching to resources too much without fully giving time to them just wastes time and demoralizes us.:-

1. OpenGL redbook: it's enough for studying OpenGL concepts. Click this link
2. The simplest and nicely described tutorial on OpenGL + shaders (i.e. covers OpenGL ES 2.0 also ).
    Click this link  pointer to http://duriansoftware.com/joe/
3. Nehe (Neon Helium) GL tutorials. Link
4. Going to learn about rendering models, UV mapping etc. Link
5. GLSL, OpenGL ES 2.0. Link
6. Good samples for some of important OpenGL techniques. Link
If you know more links then please let me know.

Friday, December 24, 2010

How to write an emulator?

Well i was just thinking to write a NES emulator since 2008 but that time i could not start due to my game engine. But now after learning these tutorials i must say anyone can make emulators who understands Microprocessors.

Please go through these tutorials to learn emulation. The tutorial is well written, small and very understandable. I will also write tutorials the way i feel simple once i do my NSF player.

Link: http://codeslinger.co.uk/pages/blog/wordpress/