Skip to content

Instantly share code, notes, and snippets.

@yorung
yorung / build.gradle
Created February 27, 2015 15:47
build.gradle for specifying outside of project folder for assets and c++ code
android {
sourceSets {
main.jni.srcDirs = ['../../cpp']
main.assets.srcDirs = ['../../assets']
}
}
@yorung
yorung / Helper.java
Last active August 29, 2015 14:16
[Android] load file from assets folder
public class Helper {
private static Context context;
public static void setContext(Context c) { context = c; }
public static byte[] loadIntoBytes(String fileName) {
AssetManager assetManager = context.getAssets();
try {
InputStream is = assetManager.open(fileName);
byte buf[] = new byte[is.available()];
is.read(buf);
@yorung
yorung / Helper.java
Created February 27, 2015 16:05
create OpenGL texture in Java
class Helper {
...
public static int loadTexture(String s){
Bitmap img;
try {
img = BitmapFactory.decodeStream(context.getAssets().open(s));
} catch (IOException e) {
return -1;
@yorung
yorung / tex_man.cpp
Created February 28, 2015 04:45
Load OpenGL textures using GDI+
namespace Gdiplus {
using std::min;
using std::max;
}
#include <gdiplus.h>
#pragma comment(lib, "gdiplus.lib")
static GLuint LoadTextureViaOS(const char* name)
{
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
@yorung
yorung / my_cb.fx
Last active August 29, 2015 14:18
[GLSL and HLSL] Uniform Buffer and Constant Buffer
// HLSL (DirectX11)
cbuffer MyContantBuffer : register(b2)
{
float4x4 matW;
}
@yorung
yorung / DX.cpp
Last active August 29, 2015 14:18
[OpenGL and DirectX11] UBO and Constant Buffer
// DirectX11
#define POS 2
pDeviceContext->VSSetConstantBuffers(POS, 1, &buffer);
@yorung
yorung / layout.cpp
Created April 6, 2015 16:00
Layout shader uniform buffer from C
#define POS 2
glUniformBlockBinding(program, glGetUniformBlockIndex(program, "MyUBO"), POS);
@yorung
yorung / make_mat4_from_vec4.glsl
Last active August 29, 2015 14:20
make mat4 from vec4
uniform vec4 uniformBuffer[9];
void main() {
mat4 matV = mat4(uniformBuffer[0], uniformBuffer[1], uniformBuffer[2], uniformBuffer[3]);
mat4 matP = mat4(uniformBuffer[4], uniformBuffer[5], uniformBuffer[6], uniformBuffer[7]);
float etc1 = uniformBuffer[8].x;
float etc2 = uniformBuffer[8].y;
float etc3 = uniformBuffer[8].z;
}
@yorung
yorung / build.bat
Created May 22, 2015 15:16
build, install, run without Android Studio GUI
call gradlew build
pause
@yorung
yorung / get_time_android.cpp
Created June 7, 2015 13:11
GetTime (older method)
double GetTime()
{
timespec t;
clock_gettime(CLOCK_MONOTONIC, &t);
return (double)t.tv_sec + (double)t.tv_nsec / 1000000000;
}