├── README.md ├── android-app ├── AndroidManifest.xml ├── AndroidManifest.xml.orig ├── build.sh ├── build.xml ├── default.properties ├── jni │ ├── Android.mk │ └── Application.mk ├── local.properties └── res │ ├── drawable │ └── icon.png │ └── values │ └── strings.xml ├── catgl.h ├── catgl_android.h ├── catgl_android_camera.h ├── catgl_android_camera.h.java ├── catgl_android_hardware.h ├── catgl_glfw.h ├── catgl_obj.h ├── catgl_ui.h ├── catgl_ui_button.h ├── catgl_ui_checkbox.h ├── catgl_ui_colorwheel.h ├── catgl_ui_dropdown.h ├── catgl_ui_editbox.h ├── catgl_ui_entypo.h ├── catgl_ui_eyes.h ├── catgl_ui_label.h ├── catgl_ui_msgbox.h ├── catgl_ui_paragraph.h ├── catgl_ui_searchbox.h ├── catgl_ui_slider.h ├── catgl_ui_spinner.h ├── catgl_ui_thumbnail.h ├── catgl_ui_window.h ├── fonts ├── entypo.h ├── icons.h ├── mplus-1c-black-sub.h ├── mplus-1c-light-sub.h └── mplus-1c-regular-sub.h ├── nanovg ├── fontstash.h ├── nanovg.c ├── nanovg.h ├── nanovg_gl.h ├── nanovg_gl_utils.h ├── stb_image.h └── stb_truetype.h └── sample ├── Kikyu! ├── Kikyu!_00.png ├── Kikyu!_01.png ├── Kikyu!_02.png ├── Makefile ├── README.md ├── assets │ ├── 0627a.png │ ├── Balloon.png │ ├── bgm_gameover_1.mp3 │ ├── bgm_maoudamashii_3_theme09.mp3 │ ├── bgm_maoudamashii_4_vehicle01.mp3 │ ├── bgm_maoudamashii_4_vehicle02.mp3 │ ├── bgm_maoudamashii_4_vehicle03.mp3 │ ├── enemy.png │ ├── fontFixed.png │ ├── fontProportional.png │ ├── icon0.png │ ├── itemget.wav │ ├── se_jump_short.mp3 │ ├── se_kusano_06_girl_ikimasu.mp3 │ ├── se_kusano_09_girl_u.mp3 │ ├── side01.jpg │ ├── side02.jpg │ ├── side03.jpg │ ├── side04.jpg │ └── song_shiho_shining_star.mp3 ├── berry_minimp3.h ├── berry_sound.h ├── dr_wav.h ├── font.h └── main.c ├── Makefile.in ├── box_GL1 ├── Makefile ├── box.c ├── box.png └── box_GL1-debug.apk ├── box_line ├── Makefile ├── box_line-debug.apk ├── main.c └── main.c.orig ├── cube_GL1 ├── Makefile ├── cube-debug.apk ├── main.c ├── models.c └── models.h ├── glsl ├── Makefile ├── WebGL │ ├── 00.glsl │ ├── 000.html │ ├── 001.html │ ├── 002.html │ ├── 003.html │ ├── 004.html │ ├── 005.html │ ├── 006.html │ ├── 01.glsl │ ├── 02.glsl │ ├── 70+.jpg │ ├── 70.glsl │ ├── 70.jpg │ ├── 71.glsl │ ├── 71.jpg │ ├── 90.glsl │ ├── 99+.jpg │ ├── 99.glsl │ ├── 99.jpg │ ├── index.html.orig │ ├── index.js │ ├── make_html.sh │ ├── style.css │ └── update_html.sh ├── assets │ ├── AtmosphericScattering.glsl │ ├── Clover.glsl │ ├── Fires.glsl │ ├── HypnoSwirl.glsl │ ├── RayMarchingPrimitivesV2.glsl │ ├── Simplicity.glsl │ ├── TotalNoob.glsl │ ├── blue_pattern.glsl │ ├── circle01.glsl │ ├── circle02.glsl │ ├── circle03.glsl │ ├── circle04.glsl │ ├── flower.glsl │ ├── fly.glsl │ ├── font.glsl │ ├── game.glsl │ ├── gradient.glsl │ ├── invader.glsl │ ├── orb01.glsl │ ├── orb02.glsl │ ├── orb03.glsl │ ├── orb04.glsl │ ├── orb05.glsl │ ├── orb06.glsl │ ├── orb07.glsl │ ├── orb08.glsl │ ├── orb09.glsl │ ├── orb10.glsl │ ├── orb11.glsl │ ├── orb12.glsl │ ├── orb13.glsl │ ├── orb14.glsl │ ├── orb15.glsl │ ├── orb16.glsl │ ├── plasma.glsl │ ├── plasma2.glsl │ ├── race.glsl │ ├── ray_demo.glsl │ ├── ray_engine.glsl │ ├── rayt01.glsl │ ├── rayt02.glsl │ ├── sample1.glsl │ ├── sample10.glsl │ ├── sample11.glsl │ ├── sample12.glsl │ ├── sample2.glsl │ ├── sample3.glsl │ ├── sample4.glsl │ ├── sample5.glsl │ ├── sky.glsl │ ├── star_mark.glsl │ ├── sun.glsl │ ├── table_tennis.glsl │ ├── tex.glsl │ ├── tex.jpg │ ├── tunnel.glsl │ ├── wait.glsl │ ├── wait2.glsl │ ├── water.glsl │ └── waves.glsl ├── glsl00.png ├── glsl01.png ├── glsl02.png └── main.c ├── gui_basic ├── Makefile ├── gui_basic-debug.apk └── main.c ├── gui_basic2 ├── Makefile ├── gui_basic2-debug.apk └── main.c ├── nanovg ├── Makefile ├── assets │ ├── Roboto-Bold.ttf │ ├── Roboto-Light.ttf │ ├── Roboto-Regular.ttf │ ├── entypo.ttf │ └── images │ │ ├── image1.jpg │ │ ├── image10.jpg │ │ ├── image11.jpg │ │ ├── image12.jpg │ │ ├── image2.jpg │ │ ├── image3.jpg │ │ ├── image4.jpg │ │ ├── image5.jpg │ │ ├── image6.jpg │ │ ├── image7.jpg │ │ ├── image8.jpg │ │ └── image9.jpg ├── demo.c ├── demo.h ├── main.c ├── nanovg-debug.apk ├── perf.c ├── perf.h └── stb_image_write.h ├── nanovg_basic ├── Makefile ├── assets │ └── cat.jpg └── main.c ├── nanovg_eyes ├── Makefile ├── eyes-debug.apk ├── eyes.png └── main.c ├── nanovg_font ├── Makefile ├── icons.h ├── main.c ├── mplus1cmedium.h └── mplus1pregular.h ├── nanovg_pic ├── Makefile ├── assets │ └── cat.jpg ├── main.c └── main.cpp.orig ├── nanovg_sprite ├── Makefile ├── assets │ └── cat.jpg └── main.c ├── teapot_GL1 ├── Makefile ├── assets │ └── teapot.obj.dat ├── main.c ├── models.c ├── models.h └── teapot_GL1-debug.apk ├── texture_basic ├── Makefile └── main.c ├── texture_pbo ├── Makefile └── main.c ├── texture_pic ├── Makefile ├── assets │ └── cat.jpg └── main.c ├── triangle ├── Makefile └── triangle.c ├── viewer ├── Makefile ├── assets │ ├── ateneav.obj │ ├── elephal.obj │ ├── eyeM2.bmp │ ├── miku.mtl │ ├── miku.obj │ └── teapot.obj ├── main.c └── viewer.png └── viewer_GL1 ├── Makefile ├── assets ├── ateneav.obj ├── magnolia.obj ├── shuttle.obj └── teapot.obj ├── main.c └── viewer_GL1-debug.apk /README.md: -------------------------------------------------------------------------------- 1 | # catgl 2 | 3 | Catgl is a cross-platform 3D graphics engine intended to be easy-to-use and high performance, which also supports the features for game development, such as animation, input device handling and sound playing. 4 | This application is designed for Android, iOS, Linux, Windows. 5 | 6 | ## Technologies 7 | 8 | - OpenGL / OpenGLES 9 | - GLSL (OpenGL Shading Language) 10 | - NanoVG (https://github.com/memononen/nanovg) 11 | - stb single-file public domain libraries (https://github.com/nothings/stb) 12 | - GLFW (for Linux) 13 | - Android NDK (for Android) 14 | 15 | ## Install 16 | 17 | - for Linux 18 | - dnf install glfw-devel 19 | - for Android 20 | - Download android-sdk-linux and install it. 21 | - tools/android update sdk 22 | - Android SDK Tools 23 | - Android SDK Platform-tools 24 | - Android SDK Build-tools 25 | - API 10 SDK Platform 26 | - Android Support Library 27 | - Download android-ndk 28 | - dnf install ant 29 | 30 | ## Examples 31 | 32 | - Linux 33 | 34 | ```bash 35 | $ cd sample/box 36 | $ make 37 | ``` 38 | 39 | - Android 40 | 41 | ```bash 42 | $ cd sample/box 43 | $ make android 44 | ``` 45 | 46 | ## How to use 47 | 48 | - Skeleton 49 | 50 | ```main.c 51 | #define CATGL_IMPLEMENTATION 52 | #include "catgl.h" 53 | 54 | void caInit(int width, int height) 55 | { 56 | } 57 | 58 | void caRender() 59 | { 60 | } 61 | 62 | void caEnd() 63 | { 64 | } 65 | ``` 66 | 67 | ```bash 68 | $ clang -std=c11 -Os -MMD -MP -Wall -Wextra -Winit-self -Wno-unused-parameter -Wno-float-equal -Wno-missing-braces -I../../ -I../../nanovg -o obj/main.o -c main.c 69 | $ clang++ -o hello obj/main.o /lib/libglfw.so /lib/libGL.so /lib/libm.so 70 | ``` 71 | 72 | - Eyes 73 | 74 | ```main.c 75 | #define CATGL_NANOVG 76 | #define CATGL_IMPLEMENTATION 77 | #include "catgl.h" 78 | 79 | struct NVGcontext* vg; 80 | int width, height; 81 | float pixelRatio; 82 | 83 | int c_action, c_x, c_y; 84 | void mouseEvent(int button, int action, int x, int y) 85 | { 86 | c_action = action; 87 | c_x = x; 88 | c_y = y; 89 | } 90 | 91 | void caInit(int w, int h) 92 | { 93 | width = w; 94 | height = h; 95 | pixelRatio = (float)width / (float)height; 96 | 97 | caMouseEvent = mouseEvent; 98 | 99 | nvgCreateEx(vg, NVG_ANTIALIAS); 100 | } 101 | 102 | void caRender() 103 | { 104 | glViewport(0, 0, width, height); 105 | 106 | glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 107 | glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT); 108 | 109 | glEnable(GL_BLEND); 110 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 111 | glEnable(GL_CULL_FACE); 112 | glDisable(GL_DEPTH_TEST); 113 | 114 | nvgBeginFrame(vg, width, height, pixelRatio); 115 | static int c; 116 | caDrawEyes(vg, 320, 180, 640, 360, c_x, c_y, c/10); 117 | c++; 118 | nvgEndFrame(vg); 119 | } 120 | 121 | void caEnd() 122 | { 123 | nvgDelete(vg); 124 | } 125 | ``` 126 | 127 | ## Screenshot 128 | 129 | ![Screenshot](sample/nanovg_eyes/eyes.png) 130 | ![Screenshot](sample/box_GL1/box.png) 131 | ![Screenshot](sample/viewer/viewer.png) 132 | [![Screenshot](sample/glsl/glsl00.png)](http://yui0.github.io/catgl/sample/glsl/WebGL/000.html) 133 | [![Screenshot](sample/glsl/glsl01.png)](http://yui0.github.io/catgl/sample/glsl/WebGL/001.html) 134 | [![Screenshot](sample/glsl/glsl02.png)](http://yui0.github.io/catgl/sample/glsl/WebGL/002.html) 135 | ![Screenshot](sample/Kikyu!/Kikyu!_00.png) 136 | -------------------------------------------------------------------------------- /android-app/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 14 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /android-app/AndroidManifest.xml.orig: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 17 | 20 | 21 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /android-app/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # sh build.sh (berry.)kikyu Kikyu(.java) kikyu.cpp assets 3 | package=$1 4 | name=$2 5 | source=$3 6 | assets=$4 7 | path=$5 8 | [ -z "${path}" ] && path=/root/Dropbox/prog/catgl 9 | 10 | rm -rf /tmp/android-app 11 | cp -a ${path}/android-app /tmp/ 12 | 13 | [ -r AndroidManifest.xml ] && cp -a AndroidManifest.xml /tmp/android-app/ 14 | [ -r icon.png ] && cp -a icon.png /tmp/android-app/res/drawable/ 15 | 16 | sed -e "s/@@NAME@@/${name}/" -i /tmp/android-app/build.xml 17 | sed -e "s:~/android-ndk:$HOME/android-ndk:" -i /tmp/android-app/build.xml 18 | sed -e "s/@@NAME@@/${name}/" -i /tmp/android-app/AndroidManifest.xml 19 | sed -e "s/@@PACKAGE@@/${package}/" -i /tmp/android-app/AndroidManifest.xml 20 | sed -e "s/native-activity/CatNative/" -i /tmp/android-app/AndroidManifest.xml 21 | sed -e "s/@@NAME@@/${name}/" -i /tmp/android-app/res/values/strings.xml 22 | 23 | #if [ -r /tmp/android-app/src ]; then 24 | # mv /tmp/android-app/src/berry/package /tmp/android-app/src/berry/${package} 25 | # mv /tmp/android-app/src/berry/${package}/Act.java /tmp/android-app/src/berry/${package}/${name}.java 26 | # sed -e "s/@@NAME@@/${name}/" -i /tmp/android-app/src/berry/${package}/${name}.java 27 | # sed -e "s/@@PACKAGE@@/${package}/" -i /tmp/android-app/src/berry/${package}/${name}.java 28 | #fi 29 | 30 | [ -r ${assets} ] && cp -a ${assets} /tmp/android-app/assets 31 | cp -a ${path}/*.h ${path}/nanovg/* ${path}/fonts *.[ch]* /tmp/android-app/jni/ 32 | sed -e "s:@@SOURCE@@:${source}:" -i /tmp/android-app/jni/Android.mk 33 | #sed -e "s:@@INCLUDES@@:${path}/include:" -i /tmp/android-app/jni/Android.mk 34 | sed -e 's:@@INCLUDES@@:$(LOCAL_PATH)/include:' -i /tmp/android-app/jni/Android.mk 35 | sed -e "s:@@LIBS@@:${path}/project/android/lib -L${path}/project/android/obj/local/armeabi -L\$(LOCAL_PATH)/lib -lcutils:" -i /tmp/android-app/jni/Android.mk 36 | 37 | 38 | pushd /tmp/android-app/ 39 | #date=`date '+%Y.%m.%d'` 40 | #sed -e "s/%%DATE%%/$date/" assets/help.html.orig > assets/help.html 41 | 42 | export PATH=$PATH:~/android-sdk-linux/platform-tools/ 43 | 44 | ant debug 45 | #ant release 46 | adb install -r bin/${name}-debug.apk 47 | popd 48 | 49 | mv /tmp/android-app/bin/${name}-*.apk . 50 | -------------------------------------------------------------------------------- /android-app/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /android-app/default.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "build.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | # Project target. 11 | target=android-10 12 | -------------------------------------------------------------------------------- /android-app/jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | #LOCAL_CFLAGS += -fPIE 6 | #LOCAL_LDFLAGS += -fPIE -pie 7 | 8 | LOCAL_MODULE := CatNative 9 | LOCAL_CFLAGS := -std=c++11 10 | LOCAL_SRC_FILES := @@SOURCE@@ 11 | LOCAL_C_INCLUDES := @@INCLUDES@@ 12 | LOCAL_CXXFLAGS := -DNDEBUG -DCK_ANDROID 13 | LOCAL_LDLIBS := -L@@LIBS@@ -llog -landroid -lEGL -lGLESv1_CM -lGLESv2 -lOpenSLES 14 | LOCAL_STATIC_LIBRARIES := android_native_app_glue 15 | 16 | include $(BUILD_SHARED_LIBRARY) 17 | 18 | $(call import-module,android/native_app_glue) 19 | -------------------------------------------------------------------------------- /android-app/jni/Application.mk: -------------------------------------------------------------------------------- 1 | #APP_ABI := all 2 | APP_ABI := armeabi-v7a 3 | APP_PLATFORM := android-10 4 | -------------------------------------------------------------------------------- /android-app/local.properties: -------------------------------------------------------------------------------- 1 | sdk.dir=/root/android-sdk-linux 2 | -------------------------------------------------------------------------------- /android-app/res/drawable/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/android-app/res/drawable/icon.png -------------------------------------------------------------------------------- /android-app/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | @@NAME@@ 4 | 5 | -------------------------------------------------------------------------------- /catgl_android_camera.h.java: -------------------------------------------------------------------------------- 1 | void caCameraInit(struct android_app* app) 2 | { 3 | JNIEnv* env = app->activity->env; 4 | JavaVM* vm = app->activity->vm; 5 | (*vm)->AttachCurrentThread(vm, &env, NULL); 6 | 7 | jclass activityClass = (*env)->GetObjectClass(env, app->activity->clazz);//android/app/NativeActivity 8 | jmethodID method = (*env)->GetMethodID(env, activityClass, "cameraOpen", "()V;"); 9 | /* (*env)->CallVoidMethod(env, app->activity->clazz, method);*/ 10 | // (*env)->CallObjectMethod(env, app->activity->clazz, method); 11 | 12 | // jclass jcls = (*env)->FindClass(env, "berry/catgl/CameraView"); 13 | // jclass jcls = (*env)->FindClass(env, "berry/catgl/Catgl"); 14 | // jmethodID mj = (*env)->GetMethodID(env, jcls, "FlashOn", "()V"); 15 | // jmethodID mj = (*env)->GetMethodID(env, jcls, "cameraOpen", "()V"); 16 | // jobject jobj = (*env)->NewObject(env, jcls, mj); 17 | // (*env)->CallObjectMethod(env, jobj, mj); 18 | // (*env)->CallVoidMethod(env, app->activity->clazz, method); 19 | 20 | (*vm)->DetachCurrentThread(vm); 21 | } 22 | -------------------------------------------------------------------------------- /catgl_glfw.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------- 2 | // catgl 3 | // 4 | // ©2015,2018 Yuichiro Nakada 5 | //--------------------------------------------------------- 6 | 7 | #define GLFW_INCLUDE_GLU 8 | #include 9 | 10 | #ifndef SCREEN_WIDTH 11 | #define SCREEN_TITLE "Catgl" 12 | #define SCREEN_WIDTH 1280 13 | #define SCREEN_HEIGHT 720 14 | #endif 15 | 16 | extern void caInit(int width, int height); 17 | extern void caRender(); 18 | extern void caEnd(); 19 | 20 | #include 21 | char *caGetPath(char *path) 22 | { 23 | static char s[BUFSIZ]; 24 | strncpy(s, "assets/", BUFSIZ); 25 | strncat(s, path, BUFSIZ); 26 | return s; 27 | } 28 | 29 | int _button/*, _action*/; 30 | void mouseButtonCallback(GLFWwindow* window, const int button, const int action, const int mods) 31 | { 32 | // int xpos, ypos; 33 | // glfwGetMousePos(&xpos, &ypos); 34 | double xpos, ypos; 35 | glfwGetCursorPos(window, &xpos, &ypos); 36 | if (caMouseEvent) { 37 | _button = button; 38 | // _action = action; 39 | caMouseEvent(button, action, xpos, ypos); 40 | } 41 | } 42 | void mouseMoveCallback(GLFWwindow* window, const double xpos, const double ypos) 43 | { 44 | if (caMouseEvent) caMouseEvent(_button, /*_action*/2, xpos, ypos); 45 | } 46 | 47 | void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) 48 | { 49 | if (caKeyEvent) { 50 | caKeyEvent(key, action); 51 | } //else { 52 | if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) { 53 | glfwSetWindowShouldClose(window, GL_TRUE); 54 | } 55 | // } 56 | } 57 | 58 | int main() 59 | { 60 | GLFWwindow* window; 61 | 62 | if (!glfwInit()) return -1; 63 | 64 | //glfwWindowHint(GLFW_DECORATED, /*false*/0); 65 | 66 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); 67 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); 68 | 69 | glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); 70 | // glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 71 | // glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); 72 | // glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 73 | // glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); 74 | 75 | //glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); 76 | /*glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); 77 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); 78 | glfwWindowHint(GLFW_RED_BITS, 8); 79 | glfwWindowHint(GLFW_GREEN_BITS, 8); 80 | glfwWindowHint(GLFW_BLUE_BITS, 8); 81 | glfwWindowHint(GLFW_ALPHA_BITS, 8); 82 | glfwWindowHint(GLFW_DEPTH_BITS, 24); 83 | glfwWindowHint(GLFW_STENCIL_BITS, 8);*/ 84 | //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); 85 | //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); 86 | 87 | window = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE, 0, 0); 88 | if (!window) { 89 | //printf("Error at glfwCreateWindow!\n"); 90 | glfwTerminate(); 91 | return -1; 92 | } 93 | 94 | glfwMakeContextCurrent(window); 95 | glfwSetMouseButtonCallback(window, mouseButtonCallback); 96 | glfwSetCursorPosCallback(window, mouseMoveCallback); 97 | glfwSetKeyCallback(window, keyCallback); 98 | caInit(SCREEN_WIDTH, SCREEN_HEIGHT); 99 | while (!glfwWindowShouldClose(window)) { 100 | caRender(); 101 | 102 | glfwSwapBuffers(window); 103 | glfwPollEvents(); 104 | 105 | /*if (glfwGetKey(window, GLFW_KEY_P)) caMode = CATGL_MODE_POINT; 106 | if (glfwGetKey(window, GLFW_KEY_W)) caMode = CATGL_MODE_LINE; 107 | if (glfwGetKey(window, GLFW_KEY_T)) caMode = CATGL_MODE_TRIANGLES; 108 | if (glfwGetKey(window, GLFW_KEY_ESCAPE)) break;*/ 109 | } 110 | caEnd(); 111 | glfwTerminate(); 112 | } 113 | -------------------------------------------------------------------------------- /catgl_ui_button.h: -------------------------------------------------------------------------------- 1 | void caDrawButton(NVGcontext* vg, int preicon, const char* text, float x, float y, float w, float h, NVGcolor col, int f) 2 | { 3 | NVGpaint bg; 4 | char icon[8]; 5 | float cornerRadius = 4.0f; 6 | float tw = 0, iw = 0; 7 | 8 | if (!f) { 9 | bg = nvgLinearGradient(vg, x,y,x,y+h, nvgRGBA(255,255,255,isBlack(col)?16:32), nvgRGBA(0,0,0,isBlack(col)?16:32)); 10 | } else { 11 | bg = nvgLinearGradient(vg, x,y,x,y+h, nvgRGBA(0,0,0,isBlack(col)?16:32), nvgRGBA(255,255,255,isBlack(col)?16:32)); 12 | } 13 | nvgBeginPath(vg); 14 | nvgRoundedRect(vg, x+1,y+1, w-2,h-2, cornerRadius-1); 15 | if (!isBlack(col)) { 16 | nvgFillColor(vg, col); 17 | nvgFill(vg); 18 | } 19 | nvgFillPaint(vg, bg); 20 | nvgFill(vg); 21 | 22 | nvgBeginPath(vg); 23 | nvgRoundedRect(vg, x+0.5f,y+0.5f, w-1,h-1, cornerRadius-0.5f); 24 | nvgStrokeColor(vg, nvgRGBA(0,0,0,48)); 25 | nvgStroke(vg); 26 | 27 | nvgFontSize(vg, 20.0f); 28 | nvgFontFace(vg, "sans-bold"); 29 | tw = nvgTextBounds(vg, 0,0, text, NULL, NULL); 30 | if (preicon != 0) { 31 | nvgFontSize(vg, h*1.3f); 32 | nvgFontFace(vg, "icons"); 33 | iw = nvgTextBounds(vg, 0,0, cpToUTF8(preicon,icon), NULL, NULL); 34 | iw += h*0.15f; 35 | 36 | nvgFontSize(vg, h*1.3f); 37 | nvgFontFace(vg, "icons"); 38 | nvgFillColor(vg, nvgRGBA(255,255,255,96)); 39 | nvgTextAlign(vg,NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE); 40 | nvgText(vg, x+w*0.5f-tw*0.5f-iw*0.75f, y+h*0.5f, cpToUTF8(preicon,icon), NULL); 41 | } 42 | 43 | nvgFontSize(vg, 20.0f); 44 | nvgFontFace(vg, "sans-bold"); 45 | nvgTextAlign(vg, NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE); 46 | nvgFillColor(vg, nvgRGBA(0,0,0,160)); 47 | nvgText(vg, x+w*0.5f-tw*0.5f+iw*0.25f,y+h*0.5f-1,text, NULL); 48 | nvgFillColor(vg, nvgRGBA(255,255,255,160)); 49 | nvgText(vg, x+w*0.5f-tw*0.5f+iw*0.25f,y+h*0.5f,text, NULL); 50 | } 51 | -------------------------------------------------------------------------------- /catgl_ui_checkbox.h: -------------------------------------------------------------------------------- 1 | void caDrawCheckBox(NVGcontext* vg, const char* text, float x, float y, float w, float h, int f) 2 | { 3 | NVGpaint bg; 4 | char icon[8]; 5 | NVG_NOTUSED(w); 6 | 7 | nvgFontSize(vg, 18.0f); 8 | nvgFontFace(vg, "sans"); 9 | nvgFillColor(vg, nvgRGBA(255,255,255,160)); 10 | 11 | nvgTextAlign(vg, NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE); 12 | nvgText(vg, x+28, y+h*0.5f,text, NULL); 13 | 14 | bg = nvgBoxGradient(vg, x+1, y+(int)(h*0.5f)-9+1, 18, 18, 3, 3, nvgRGBA(0,0,0,32), nvgRGBA(0,0,0,92)); 15 | nvgBeginPath(vg); 16 | nvgRoundedRect(vg, x+1, y+(int)(h*0.5f)-9, 18, 18, 3); 17 | nvgFillPaint(vg, bg); 18 | nvgFill(vg); 19 | 20 | if (f) { 21 | nvgFontSize(vg, 40); 22 | nvgFontFace(vg, "icons"); 23 | nvgFillColor(vg, nvgRGBA(255,255,255,128)); 24 | nvgTextAlign(vg, NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE); 25 | nvgText(vg, x+9+2, y+h*0.5f, cpToUTF8(CATGL_ICON_CHECK, icon), NULL); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /catgl_ui_colorwheel.h: -------------------------------------------------------------------------------- 1 | void caDrawColorwheel(NVGcontext* vg, float x, float y, float w, float h, float t) 2 | { 3 | int i; 4 | float r0, r1, ax,ay, bx,by, cx,cy, aeps, r; 5 | float hue = sinf(t * 0.12f); 6 | NVGpaint paint; 7 | 8 | nvgSave(vg); 9 | 10 | /* nvgBeginPath(vg); 11 | nvgRect(vg, x,y,w,h); 12 | nvgFillColor(vg, nvgRGBA(255,0,0,128)); 13 | nvgFill(vg);*/ 14 | 15 | cx = x + w*0.5f; 16 | cy = y + h*0.5f; 17 | r1 = (w < h ? w : h) * 0.5f - 5.0f; 18 | r0 = r1 - 20.0f; 19 | aeps = 0.5f / r1; // half a pixel arc length in radians (2pi cancels out). 20 | 21 | for (i = 0; i < 6; i++) { 22 | float a0 = (float)i / 6.0f * NVG_PI * 2.0f - aeps; 23 | float a1 = (float)(i+1.0f) / 6.0f * NVG_PI * 2.0f + aeps; 24 | nvgBeginPath(vg); 25 | nvgArc(vg, cx,cy, r0, a0, a1, NVG_CW); 26 | nvgArc(vg, cx,cy, r1, a1, a0, NVG_CCW); 27 | nvgClosePath(vg); 28 | ax = cx + cosf(a0) * (r0+r1)*0.5f; 29 | ay = cy + sinf(a0) * (r0+r1)*0.5f; 30 | bx = cx + cosf(a1) * (r0+r1)*0.5f; 31 | by = cy + sinf(a1) * (r0+r1)*0.5f; 32 | paint = nvgLinearGradient(vg, ax,ay, bx,by, nvgHSLA(a0/(NVG_PI*2),1.0f,0.55f,255), nvgHSLA(a1/(NVG_PI*2),1.0f,0.55f,255)); 33 | nvgFillPaint(vg, paint); 34 | nvgFill(vg); 35 | } 36 | 37 | nvgBeginPath(vg); 38 | nvgCircle(vg, cx,cy, r0-0.5f); 39 | nvgCircle(vg, cx,cy, r1+0.5f); 40 | nvgStrokeColor(vg, nvgRGBA(0,0,0,64)); 41 | nvgStrokeWidth(vg, 1.0f); 42 | nvgStroke(vg); 43 | 44 | // Selector 45 | nvgSave(vg); 46 | nvgTranslate(vg, cx,cy); 47 | nvgRotate(vg, hue*NVG_PI*2); 48 | 49 | // Marker on 50 | nvgStrokeWidth(vg, 2.0f); 51 | nvgBeginPath(vg); 52 | nvgRect(vg, r0-1,-3,r1-r0+2,6); 53 | nvgStrokeColor(vg, nvgRGBA(255,255,255,192)); 54 | nvgStroke(vg); 55 | 56 | paint = nvgBoxGradient(vg, r0-3,-5,r1-r0+6,10, 2,4, nvgRGBA(0,0,0,128), nvgRGBA(0,0,0,0)); 57 | nvgBeginPath(vg); 58 | nvgRect(vg, r0-2-10,-4-10,r1-r0+4+20,8+20); 59 | nvgRect(vg, r0-2,-4,r1-r0+4,8); 60 | nvgPathWinding(vg, NVG_HOLE); 61 | nvgFillPaint(vg, paint); 62 | nvgFill(vg); 63 | 64 | // Center triangle 65 | r = r0 - 6; 66 | ax = cosf(120.0f/180.0f*NVG_PI) * r; 67 | ay = sinf(120.0f/180.0f*NVG_PI) * r; 68 | bx = cosf(-120.0f/180.0f*NVG_PI) * r; 69 | by = sinf(-120.0f/180.0f*NVG_PI) * r; 70 | nvgBeginPath(vg); 71 | nvgMoveTo(vg, r,0); 72 | nvgLineTo(vg, ax,ay); 73 | nvgLineTo(vg, bx,by); 74 | nvgClosePath(vg); 75 | paint = nvgLinearGradient(vg, r,0, ax,ay, nvgHSLA(hue,1.0f,0.5f,255), nvgRGBA(255,255,255,255)); 76 | nvgFillPaint(vg, paint); 77 | nvgFill(vg); 78 | paint = nvgLinearGradient(vg, (r+ax)*0.5f,(0+ay)*0.5f, bx,by, nvgRGBA(0,0,0,0), nvgRGBA(0,0,0,255)); 79 | nvgFillPaint(vg, paint); 80 | nvgFill(vg); 81 | nvgStrokeColor(vg, nvgRGBA(0,0,0,64)); 82 | nvgStroke(vg); 83 | 84 | // Select circle on triangle 85 | ax = cosf(120.0f/180.0f*NVG_PI) * r*0.3f; 86 | ay = sinf(120.0f/180.0f*NVG_PI) * r*0.4f; 87 | nvgStrokeWidth(vg, 2.0f); 88 | nvgBeginPath(vg); 89 | nvgCircle(vg, ax,ay,5); 90 | nvgStrokeColor(vg, nvgRGBA(255,255,255,192)); 91 | nvgStroke(vg); 92 | 93 | paint = nvgRadialGradient(vg, ax,ay, 7,9, nvgRGBA(0,0,0,64), nvgRGBA(0,0,0,0)); 94 | nvgBeginPath(vg); 95 | nvgRect(vg, ax-20,ay-20,40,40); 96 | nvgCircle(vg, ax,ay,7); 97 | nvgPathWinding(vg, NVG_HOLE); 98 | nvgFillPaint(vg, paint); 99 | nvgFill(vg); 100 | 101 | nvgRestore(vg); 102 | 103 | nvgRestore(vg); 104 | } 105 | -------------------------------------------------------------------------------- /catgl_ui_dropdown.h: -------------------------------------------------------------------------------- 1 | void caDrawDropDown(NVGcontext* vg, const char* text, float x, float y, float w, float h) 2 | { 3 | NVGpaint bg; 4 | char icon[8]; 5 | float cornerRadius = 4.0f; 6 | 7 | bg = nvgLinearGradient(vg, x,y,x,y+h, nvgRGBA(255,255,255,16), nvgRGBA(0,0,0,16)); 8 | nvgBeginPath(vg); 9 | nvgRoundedRect(vg, x+1,y+1, w-2,h-2, cornerRadius-1); 10 | nvgFillPaint(vg, bg); 11 | nvgFill(vg); 12 | 13 | nvgBeginPath(vg); 14 | nvgRoundedRect(vg, x+0.5f,y+0.5f, w-1,h-1, cornerRadius-0.5f); 15 | nvgStrokeColor(vg, nvgRGBA(0,0,0,48)); 16 | nvgStroke(vg); 17 | 18 | nvgFontSize(vg, 20.0f); 19 | nvgFontFace(vg, "sans"); 20 | nvgFillColor(vg, nvgRGBA(255,255,255,160)); 21 | nvgTextAlign(vg, NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE); 22 | nvgText(vg, x+h*0.3f, y+h*0.5f, text, NULL); 23 | 24 | nvgFontSize(vg, h*1.3f); 25 | nvgFontFace(vg, "icons"); 26 | nvgFillColor(vg, nvgRGBA(255,255,255,64)); 27 | nvgTextAlign(vg, NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE); 28 | nvgText(vg, x+w-h*0.5f, y+h*0.5f, cpToUTF8(CATGL_ICON_CHEVRON_RIGHT, icon), NULL); 29 | } 30 | -------------------------------------------------------------------------------- /catgl_ui_editbox.h: -------------------------------------------------------------------------------- 1 | void caDrawEditBoxBase(NVGcontext* vg, float x, float y, float w, float h) 2 | { 3 | NVGpaint bg; 4 | // Edit 5 | bg = nvgBoxGradient(vg, x+1,y+1+1.5f, w-2,h-2, 3,4, nvgRGBA(255,255,255,32), nvgRGBA(32,32,32,32)); 6 | nvgBeginPath(vg); 7 | nvgRoundedRect(vg, x+1,y+1, w-2,h-2, 4-1); 8 | nvgFillPaint(vg, bg); 9 | nvgFill(vg); 10 | 11 | nvgBeginPath(vg); 12 | nvgRoundedRect(vg, x+0.5f,y+0.5f, w-1,h-1, 4-0.5f); 13 | nvgStrokeColor(vg, nvgRGBA(0,0,0,48)); 14 | nvgStroke(vg); 15 | } 16 | 17 | void caDrawEditBox(NVGcontext* vg, const char* text, float x, float y, float w, float h) 18 | { 19 | caDrawEditBoxBase(vg, x,y, w,h); 20 | 21 | nvgFontSize(vg, 20.0f); 22 | nvgFontFace(vg, "sans"); 23 | nvgFillColor(vg, nvgRGBA(255,255,255,64)); 24 | nvgTextAlign(vg,NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE); 25 | nvgText(vg, x+h*0.3f,y+h*0.5f,text, NULL); 26 | } 27 | 28 | void caDrawEditBoxNum(NVGcontext* vg, const char* text, const char* units, float x, float y, float w, float h) 29 | { 30 | float uw; 31 | 32 | caDrawEditBoxBase(vg, x,y, w,h); 33 | 34 | uw = nvgTextBounds(vg, 0,0, units, NULL, NULL); 35 | 36 | nvgFontSize(vg, 18.0f); 37 | nvgFontFace(vg, "sans"); 38 | nvgFillColor(vg, nvgRGBA(255,255,255,64)); 39 | nvgTextAlign(vg,NVG_ALIGN_RIGHT|NVG_ALIGN_MIDDLE); 40 | nvgText(vg, x+w-h*0.3f,y+h*0.5f,units, NULL); 41 | 42 | nvgFontSize(vg, 20.0f); 43 | nvgFontFace(vg, "sans"); 44 | nvgFillColor(vg, nvgRGBA(255,255,255,128)); 45 | nvgTextAlign(vg,NVG_ALIGN_RIGHT|NVG_ALIGN_MIDDLE); 46 | nvgText(vg, x+w-uw-h*0.5f,y+h*0.5f,text, NULL); 47 | } 48 | -------------------------------------------------------------------------------- /catgl_ui_eyes.h: -------------------------------------------------------------------------------- 1 | void caDrawEyes(NVGcontext* vg, float x, float y, float w, float h, float mx, float my, float t) 2 | { 3 | NVGpaint gloss, bg; 4 | float ex = w *0.23f; 5 | float ey = h * 0.5f; 6 | float lx = x + ex; 7 | float ly = y + ey; 8 | float rx = x + w - ex; 9 | float ry = y + ey; 10 | float dx,dy,d; 11 | float br = (ex < ey ? ex : ey) * 0.5f; 12 | float blink = 1 - pow(sinf(t*0.5f),200)*0.8f; 13 | 14 | bg = nvgLinearGradient(vg, x,y+h*0.5f,x+w*0.1f,y+h, nvgRGBA(0,0,0,32), nvgRGBA(0,0,0,16)); 15 | nvgBeginPath(vg); 16 | nvgEllipse(vg, lx+3.0f,ly+16.0f, ex,ey); 17 | nvgEllipse(vg, rx+3.0f,ry+16.0f, ex,ey); 18 | nvgFillPaint(vg, bg); 19 | nvgFill(vg); 20 | 21 | bg = nvgLinearGradient(vg, x,y+h*0.25f,x+w*0.1f,y+h, nvgRGBA(220,220,220,255), nvgRGBA(128,128,128,255)); 22 | nvgBeginPath(vg); 23 | nvgEllipse(vg, lx,ly, ex,ey); 24 | nvgEllipse(vg, rx,ry, ex,ey); 25 | nvgFillPaint(vg, bg); 26 | nvgFill(vg); 27 | 28 | dx = (mx - rx) / (ex * 10); 29 | dy = (my - ry) / (ey * 10); 30 | d = sqrtf(dx*dx+dy*dy); 31 | if (d > 1.0f) { 32 | dx /= d; dy /= d; 33 | } 34 | dx *= ex*0.4f; 35 | dy *= ey*0.5f; 36 | nvgBeginPath(vg); 37 | nvgEllipse(vg, lx+dx,ly+dy+ey*0.25f*(1-blink), br,br*blink); 38 | nvgFillColor(vg, nvgRGBA(32,32,32,255)); 39 | nvgFill(vg); 40 | 41 | dx = (mx - rx) / (ex * 10); 42 | dy = (my - ry) / (ey * 10); 43 | d = sqrtf(dx*dx+dy*dy); 44 | if (d > 1.0f) { 45 | dx /= d; dy /= d; 46 | } 47 | dx *= ex*0.4f; 48 | dy *= ey*0.5f; 49 | nvgBeginPath(vg); 50 | nvgEllipse(vg, rx+dx,ry+dy+ey*0.25f*(1-blink), br,br*blink); 51 | nvgFillColor(vg, nvgRGBA(32,32,32,255)); 52 | nvgFill(vg); 53 | 54 | gloss = nvgRadialGradient(vg, lx-ex*0.25f,ly-ey*0.5f, ex*0.1f,ex*0.75f, nvgRGBA(255,255,255,128), nvgRGBA(255,255,255,0)); 55 | nvgBeginPath(vg); 56 | nvgEllipse(vg, lx,ly, ex,ey); 57 | nvgFillPaint(vg, gloss); 58 | nvgFill(vg); 59 | 60 | gloss = nvgRadialGradient(vg, rx-ex*0.25f,ry-ey*0.5f, ex*0.1f,ex*0.75f, nvgRGBA(255,255,255,128), nvgRGBA(255,255,255,0)); 61 | nvgBeginPath(vg); 62 | nvgEllipse(vg, rx,ry, ex,ey); 63 | nvgFillPaint(vg, gloss); 64 | nvgFill(vg); 65 | } 66 | -------------------------------------------------------------------------------- /catgl_ui_label.h: -------------------------------------------------------------------------------- 1 | void caDrawLabel(NVGcontext* vg, const char* text, float x, float y, float w, float h) 2 | { 3 | NVG_NOTUSED(w); 4 | 5 | nvgFontSize(vg, 18.0f); 6 | nvgFontFace(vg, "sans"); 7 | nvgFillColor(vg, nvgRGBA(255,255,255,128)); 8 | 9 | nvgTextAlign(vg,NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE); 10 | nvgText(vg, x,y+h*0.5f,text, NULL); 11 | } 12 | -------------------------------------------------------------------------------- /catgl_ui_msgbox.h: -------------------------------------------------------------------------------- 1 | void onOK(int action, int x, int y) 2 | { 3 | // LOGD("(%d,%d) %d\n", x, y, action); 4 | // nvgBeginPath(vg); 5 | nvgText(vg, 350, 120, "Push OK button!", NULL); 6 | // nvgFill(vg); 7 | } 8 | void onCancel(int action, int x, int y) 9 | { 10 | // LOGD("(%d,%d) %d\n", x, y, action); 11 | // nvgBeginPath(vg); 12 | nvgText(vg, 350, 120, "Push Cancel button!", NULL); 13 | // nvgFill(vg); 14 | } 15 | CATGL_UI confirm[] = { 16 | { CATGL_UI_WINDOW, 350, 300, 200, 150, "Confirm", 0, 0, 0,0,0,0, 0 }, 17 | { CATGL_UI_LABEL, -1, -1, 180, 20, "これでよろしいですか?", 0, 0, 0,0,0,0, 0 }, 18 | { CATGL_UI_BUTTON, -1, -1, 180, 40, "OK!", 0, CATGL_ICON_HEART, 0,96,128,255, onOK }, 19 | { CATGL_UI_BUTTON, -1, -1, 180, 40, "CANCEL!", 0, CATGL_ICON_CIRCLED_CROSS, 128,16,8,255, onCancel }, 20 | }; 21 | 22 | -------------------------------------------------------------------------------- /catgl_ui_paragraph.h: -------------------------------------------------------------------------------- 1 | void drawParagraph(NVGcontext* vg, float x, float y, float width, float height, float mx, float my) 2 | { 3 | NVGtextRow rows[3]; 4 | NVGglyphPosition glyphs[100]; 5 | const char* text = "This is longer chunk of text.\n \n Would have used lorem ipsum but she was busy jumping over the lazy dog with the fox and all the men who came to the aid of the party."; 6 | const char* start; 7 | const char* end; 8 | int nrows, i, nglyphs, j, lnum = 0; 9 | float lineh; 10 | float caretx, px; 11 | float bounds[4]; 12 | float a; 13 | float gx,gy; 14 | int gutter = 0; 15 | NVG_NOTUSED(height); 16 | 17 | nvgSave(vg); 18 | 19 | nvgFontSize(vg, 18.0f); 20 | nvgFontFace(vg, "sans"); 21 | nvgTextAlign(vg, NVG_ALIGN_LEFT|NVG_ALIGN_TOP); 22 | nvgTextMetrics(vg, NULL, NULL, &lineh); 23 | 24 | // The text break API can be used to fill a large buffer of rows, 25 | // or to iterate over the text just few lines (or just one) at a time. 26 | // The "next" variable of the last returned item tells where to continue. 27 | start = text; 28 | end = text + strlen(text); 29 | while ((nrows = nvgTextBreakLines(vg, start, end, width, rows, 3))) { 30 | for (i = 0; i < nrows; i++) { 31 | NVGtextRow* row = &rows[i]; 32 | int hit = mx > x && mx < (x+width) && my >= y && my < (y+lineh); 33 | 34 | nvgBeginPath(vg); 35 | nvgFillColor(vg, nvgRGBA(255,255,255,hit?64:16)); 36 | nvgRect(vg, x, y, row->width, lineh); 37 | nvgFill(vg); 38 | 39 | nvgFillColor(vg, nvgRGBA(255,255,255,255)); 40 | nvgText(vg, x, y, row->start, row->end); 41 | 42 | if (hit) { 43 | caretx = (mx < x+row->width/2) ? x : x+row->width; 44 | px = x; 45 | nglyphs = nvgTextGlyphPositions(vg, x, y, row->start, row->end, glyphs, 100); 46 | for (j = 0; j < nglyphs; j++) { 47 | float x0 = glyphs[j].x; 48 | float x1 = (j+1 < nglyphs) ? glyphs[j+1].x : x+row->width; 49 | float gx = x0 * 0.3f + x1 * 0.7f; 50 | if (mx >= px && mx < gx) 51 | caretx = glyphs[j].x; 52 | px = gx; 53 | } 54 | nvgBeginPath(vg); 55 | nvgFillColor(vg, nvgRGBA(255,192,0,255)); 56 | nvgRect(vg, caretx, y, 1, lineh); 57 | nvgFill(vg); 58 | 59 | gutter = lnum+1; 60 | gx = x - 10; 61 | gy = y + lineh/2; 62 | } 63 | lnum++; 64 | y += lineh; 65 | } 66 | // Keep going... 67 | start = rows[nrows-1].next; 68 | } 69 | 70 | if (gutter) { 71 | char txt[16]; 72 | snprintf(txt, sizeof(txt), "%d", gutter); 73 | nvgFontSize(vg, 13.0f); 74 | nvgTextAlign(vg, NVG_ALIGN_RIGHT|NVG_ALIGN_MIDDLE); 75 | 76 | nvgTextBounds(vg, gx,gy, txt, NULL, bounds); 77 | 78 | nvgBeginPath(vg); 79 | nvgFillColor(vg, nvgRGBA(255,192,0,255)); 80 | nvgRoundedRect(vg, (int)bounds[0]-4,(int)bounds[1]-2, (int)(bounds[2]-bounds[0])+8, (int)(bounds[3]-bounds[1])+4, ((int)(bounds[3]-bounds[1])+4)/2-1); 81 | nvgFill(vg); 82 | 83 | nvgFillColor(vg, nvgRGBA(32,32,32,255)); 84 | nvgText(vg, gx,gy, txt, NULL); 85 | } 86 | 87 | y += 20.0f; 88 | 89 | nvgFontSize(vg, 13.0f); 90 | nvgTextAlign(vg, NVG_ALIGN_LEFT|NVG_ALIGN_TOP); 91 | nvgTextLineHeight(vg, 1.2f); 92 | 93 | nvgTextBoxBounds(vg, x,y, 150, "Hover your mouse over the text to see calculated caret position.", NULL, bounds); 94 | 95 | // Fade the tooltip out when close to it. 96 | gx = fabsf((mx - (bounds[0]+bounds[2])*0.5f) / (bounds[0] - bounds[2])); 97 | gy = fabsf((my - (bounds[1]+bounds[3])*0.5f) / (bounds[1] - bounds[3])); 98 | a = maxf(gx, gy) - 0.5f; 99 | a = clampf(a, 0, 1); 100 | nvgGlobalAlpha(vg, a); 101 | 102 | nvgBeginPath(vg); 103 | nvgFillColor(vg, nvgRGBA(220,220,220,255)); 104 | nvgRoundedRect(vg, bounds[0]-2,bounds[1]-2, (int)(bounds[2]-bounds[0])+4, (int)(bounds[3]-bounds[1])+4, 3); 105 | px = (int)((bounds[2]+bounds[0])/2); 106 | nvgMoveTo(vg, px,bounds[1] - 10); 107 | nvgLineTo(vg, px+7,bounds[1]+1); 108 | nvgLineTo(vg, px-7,bounds[1]+1); 109 | nvgFill(vg); 110 | 111 | nvgFillColor(vg, nvgRGBA(0,0,0,220)); 112 | nvgTextBox(vg, x,y, 150, "Hover your mouse over the text to see calculated caret position.", NULL); 113 | 114 | nvgRestore(vg); 115 | } 116 | -------------------------------------------------------------------------------- /catgl_ui_searchbox.h: -------------------------------------------------------------------------------- 1 | void caDrawSearchBox(NVGcontext* vg, const char* text, float x, float y, float w, float h) 2 | { 3 | NVGpaint bg; 4 | char icon[8]; 5 | float cornerRadius = h/2-1; 6 | 7 | // Edit 8 | bg = nvgBoxGradient(vg, x,y+1.5f, w,h, h/2,5, nvgRGBA(0,0,0,16), nvgRGBA(0,0,0,92)); 9 | nvgBeginPath(vg); 10 | nvgRoundedRect(vg, x,y, w,h, cornerRadius); 11 | nvgFillPaint(vg, bg); 12 | nvgFill(vg); 13 | 14 | /* nvgBeginPath(vg); 15 | nvgRoundedRect(vg, x+0.5f,y+0.5f, w-1,h-1, cornerRadius-0.5f); 16 | nvgStrokeColor(vg, nvgRGBA(0,0,0,48)); 17 | nvgStroke(vg);*/ 18 | 19 | nvgFontSize(vg, h*1.3f); 20 | nvgFontFace(vg, "icons"); 21 | nvgFillColor(vg, nvgRGBA(255,255,255,64)); 22 | nvgTextAlign(vg, NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE); 23 | nvgText(vg, x+h*0.55f, y+h*0.55f, cpToUTF8(CATGL_ICON_SEARCH, icon), NULL); 24 | 25 | nvgFontSize(vg, 20.0f); 26 | nvgFontFace(vg, "sans"); 27 | nvgFillColor(vg, nvgRGBA(255,255,255,32)); 28 | 29 | nvgTextAlign(vg, NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE); 30 | nvgText(vg, x+h*1.05f, y+h*0.5f, text, NULL); 31 | 32 | nvgFontSize(vg, h*1.3f); 33 | nvgFontFace(vg, "icons"); 34 | nvgFillColor(vg, nvgRGBA(255,255,255,32)); 35 | nvgTextAlign(vg, NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE); 36 | nvgText(vg, x+w-h*0.55f, y+h*0.55f, cpToUTF8(CATGL_ICON_CIRCLED_CROSS, icon), NULL); 37 | } 38 | -------------------------------------------------------------------------------- /catgl_ui_slider.h: -------------------------------------------------------------------------------- 1 | void caDrawSlider(NVGcontext* vg, float pos, float x, float y, float w, float h) 2 | { 3 | NVGpaint bg, knob; 4 | float cy = y+(int)(h*0.5f); 5 | float kr = (int)(h*0.25f); 6 | 7 | nvgSave(vg); 8 | // nvgClearState(vg); 9 | 10 | // Slot 11 | bg = nvgBoxGradient(vg, x,cy-2+1, w,4, 2,2, nvgRGBA(0,0,0,32), nvgRGBA(0,0,0,128)); 12 | nvgBeginPath(vg); 13 | nvgRoundedRect(vg, x,cy-2, w,4, 2); 14 | nvgFillPaint(vg, bg); 15 | nvgFill(vg); 16 | 17 | // Knob Shadow 18 | bg = nvgRadialGradient(vg, x+(int)(pos*w),cy+1, kr-3,kr+3, nvgRGBA(0,0,0,64), nvgRGBA(0,0,0,0)); 19 | nvgBeginPath(vg); 20 | nvgRect(vg, x+(int)(pos*w)-kr-5,cy-kr-5,kr*2+5+5,kr*2+5+5+3); 21 | nvgCircle(vg, x+(int)(pos*w),cy, kr); 22 | nvgPathWinding(vg, NVG_HOLE); 23 | nvgFillPaint(vg, bg); 24 | nvgFill(vg); 25 | 26 | // Knob 27 | knob = nvgLinearGradient(vg, x,cy-kr,x,cy+kr, nvgRGBA(255,255,255,16), nvgRGBA(0,0,0,16)); 28 | nvgBeginPath(vg); 29 | nvgCircle(vg, x+(int)(pos*w),cy, kr-1); 30 | nvgFillColor(vg, nvgRGBA(40,43,48,255)); 31 | nvgFill(vg); 32 | nvgFillPaint(vg, knob); 33 | nvgFill(vg); 34 | 35 | nvgBeginPath(vg); 36 | nvgCircle(vg, x+(int)(pos*w),cy, kr-0.5f); 37 | nvgStrokeColor(vg, nvgRGBA(0,0,0,92)); 38 | nvgStroke(vg); 39 | 40 | nvgRestore(vg); 41 | } 42 | -------------------------------------------------------------------------------- /catgl_ui_spinner.h: -------------------------------------------------------------------------------- 1 | void caDrawSpinner(NVGcontext* vg, float cx, float cy, float r, float t) 2 | { 3 | float a0 = 0.0f + t*6; 4 | float a1 = NVG_PI + t*6; 5 | float r0 = r; 6 | float r1 = r * 0.75f; 7 | float ax,ay, bx,by; 8 | NVGpaint paint; 9 | 10 | nvgSave(vg); 11 | 12 | nvgBeginPath(vg); 13 | nvgArc(vg, cx,cy, r0, a0, a1, NVG_CW); 14 | nvgArc(vg, cx,cy, r1, a1, a0, NVG_CCW); 15 | nvgClosePath(vg); 16 | ax = cx + cosf(a0) * (r0+r1)*0.5f; 17 | ay = cy + sinf(a0) * (r0+r1)*0.5f; 18 | bx = cx + cosf(a1) * (r0+r1)*0.5f; 19 | by = cy + sinf(a1) * (r0+r1)*0.5f; 20 | paint = nvgLinearGradient(vg, ax,ay, bx,by, nvgRGBA(0,0,0,0), nvgRGBA(0,0,0,128)); 21 | nvgFillPaint(vg, paint); 22 | nvgFill(vg); 23 | 24 | nvgRestore(vg); 25 | } 26 | -------------------------------------------------------------------------------- /catgl_ui_thumbnail.h: -------------------------------------------------------------------------------- 1 | void caDrawThumbnail(NVGcontext* vg, float x, float y, float w, float h, const int image/*, float t*/) 2 | { 3 | // float cornerRadius = 3.0f; 4 | NVGpaint shadowPaint, imgPaint/*, fadePaint*/; 5 | float ix,iy,iw,ih; 6 | float thumb = 60.0f; 7 | // float arry = 30.5f; 8 | int imgw, imgh; 9 | // float stackh = (nimages/2) * (thumb+10) + 10; 10 | // int i; 11 | // float u = (1+cosf(t*0.5f))*0.5f; 12 | // float u2 = (1-cosf(t*0.2f))*0.5f; 13 | // float scrollh, dv; 14 | 15 | nvgSave(vg); 16 | // nvgScissor(vg, x,y,w,h); 17 | // nvgTranslate(vg, 0, -(stackh - h)*u); 18 | 19 | // dv = 1.0f / (float)(nimages-1); 20 | 21 | float tx, ty/*, v, a*/; 22 | tx = x+10; 23 | ty = y+10; 24 | // tx += (i%2) * (thumb+10); 25 | // ty += (i/2) * (thumb+10); 26 | nvgImageSize(vg, image, &imgw, &imgh); 27 | if (imgw < imgh) { 28 | iw = thumb; 29 | ih = iw * (float)imgh/(float)imgw; 30 | ix = 0; 31 | iy = -(ih-thumb)*0.5f; 32 | } else { 33 | ih = thumb; 34 | iw = ih * (float)imgw/(float)imgh; 35 | ix = -(iw-thumb)*0.5f; 36 | iy = 0; 37 | } 38 | 39 | // v = i * dv; 40 | // a = clampf((u2-v) / dv, 0, 1); 41 | 42 | // if (a < 1.0f) 43 | // drawSpinner(vg, tx+thumb/2,ty+thumb/2, thumb*0.25f, t); 44 | 45 | imgPaint = nvgImagePattern(vg, tx+ix, ty+iy, iw,ih, 0.0f/180.0f*NVG_PI, image, /*a*/1); 46 | nvgBeginPath(vg); 47 | nvgRoundedRect(vg, tx,ty, thumb,thumb, 5); 48 | nvgFillPaint(vg, imgPaint); 49 | nvgFill(vg); 50 | 51 | shadowPaint = nvgBoxGradient(vg, tx-1,ty, thumb+2,thumb+2, 5, 3, nvgRGBA(0,0,0,128), nvgRGBA(0,0,0,0)); 52 | nvgBeginPath(vg); 53 | nvgRect(vg, tx-5,ty-5, thumb+10,thumb+10); 54 | nvgRoundedRect(vg, tx,ty, thumb,thumb, 6); 55 | nvgPathWinding(vg, NVG_HOLE); 56 | nvgFillPaint(vg, shadowPaint); 57 | nvgFill(vg); 58 | 59 | nvgBeginPath(vg); 60 | nvgRoundedRect(vg, tx+0.5f,ty+0.5f, thumb-1,thumb-1, 4-0.5f); 61 | nvgStrokeWidth(vg,1.0f); 62 | nvgStrokeColor(vg, nvgRGBA(255,255,255,192)); 63 | nvgStroke(vg); 64 | 65 | nvgRestore(vg); 66 | } 67 | 68 | -------------------------------------------------------------------------------- /catgl_ui_window.h: -------------------------------------------------------------------------------- 1 | void caDrawWindow(NVGcontext* vg, const char* title, float x, float y, float w, float h) 2 | { 3 | float cornerRadius = 3.0f; 4 | NVGpaint shadowPaint; 5 | NVGpaint headerPaint; 6 | 7 | nvgSave(vg); 8 | // nvgClearState(vg); 9 | 10 | // Window 11 | nvgBeginPath(vg); 12 | nvgRoundedRect(vg, x,y, w,h, cornerRadius); 13 | nvgFillColor(vg, nvgRGBA(28,30,34,192)); 14 | // nvgFillColor(vg, nvgRGBA(0,0,0,128)); 15 | nvgFill(vg); 16 | 17 | // Drop shadow 18 | shadowPaint = nvgBoxGradient(vg, x,y+2, w,h, cornerRadius*2, 10, nvgRGBA(0,0,0,128), nvgRGBA(0,0,0,0)); 19 | nvgBeginPath(vg); 20 | nvgRect(vg, x-10,y-10, w+20,h+30); 21 | nvgRoundedRect(vg, x,y, w,h, cornerRadius); 22 | nvgPathWinding(vg, NVG_HOLE); 23 | nvgFillPaint(vg, shadowPaint); 24 | nvgFill(vg); 25 | 26 | // Header 27 | headerPaint = nvgLinearGradient(vg, x,y,x,y+15, nvgRGBA(255,255,255,8), nvgRGBA(0,0,0,16)); 28 | nvgBeginPath(vg); 29 | nvgRoundedRect(vg, x+1,y+1, w-2,30, cornerRadius-1); 30 | nvgFillPaint(vg, headerPaint); 31 | nvgFill(vg); 32 | nvgBeginPath(vg); 33 | nvgMoveTo(vg, x+0.5f, y+0.5f+30); 34 | nvgLineTo(vg, x+0.5f+w-1, y+0.5f+30); 35 | nvgStrokeColor(vg, nvgRGBA(0,0,0,32)); 36 | nvgStroke(vg); 37 | 38 | nvgFontSize(vg, 18.0f); 39 | nvgFontFace(vg, "sans-bold"); 40 | nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE); 41 | 42 | nvgFontBlur(vg,2); 43 | nvgFillColor(vg, nvgRGBA(0,0,0,128)); 44 | nvgText(vg, x+w/2,y+16+1, title, NULL); 45 | 46 | nvgFontBlur(vg,0); 47 | nvgFillColor(vg, nvgRGBA(220,220,220,160)); 48 | nvgText(vg, x+w/2,y+16, title, NULL); 49 | 50 | nvgRestore(vg); 51 | } 52 | -------------------------------------------------------------------------------- /sample/Kikyu!/Kikyu!_00.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/Kikyu!_00.png -------------------------------------------------------------------------------- /sample/Kikyu!/Kikyu!_01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/Kikyu!_01.png -------------------------------------------------------------------------------- /sample/Kikyu!/Kikyu!_02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/Kikyu!_02.png -------------------------------------------------------------------------------- /sample/Kikyu!/Makefile: -------------------------------------------------------------------------------- 1 | SRC = ../../nanovg/nanovg.c 2 | INCLUDE = -I../../ -I../../nanovg 3 | #LIBS = -lglfw -lGL -ldl -lpthread 4 | LIBS = -lglfw -lGL -lasound -lpthread 5 | 6 | include ../Makefile.in 7 | -------------------------------------------------------------------------------- /sample/Kikyu!/README.md: -------------------------------------------------------------------------------- 1 | # Kikyu! 2 | 3 | a game. 4 | 5 | ![Screenshot](Kikyu!_00.png) 6 | ![Screenshot](Kikyu!_01.png) 7 | ![Screenshot](Kikyu!_02.png) 8 | 9 | ## How to use 10 | 11 | ```bash 12 | $ clang -std=c11 -Os -ffunction-sections -fdata-sections -MMD -MP -Wall -Wextra -Winit-self -Wno-unused-parameter -Wno-float-equal -Wno-missing-braces -I../../ -I../../nanovg -o obj/main.o -c main.c 13 | $ clang++ -o Kikyu! obj/main.o obj/../../nanovg/nanovg.o /usr/lib64/libglfw.so /usr/lib64/libGL.so -Wl,-s -Wl,--gc-sections 14 | $ ./Kikyu\! 15 | ``` 16 | 17 | ## Other versions 18 | 19 | - https://github.com/yui0/Kikyu 20 | - https://github.com/yui0/Kikyu-SoftPixel 21 | -------------------------------------------------------------------------------- /sample/Kikyu!/assets/0627a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/assets/0627a.png -------------------------------------------------------------------------------- /sample/Kikyu!/assets/Balloon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/assets/Balloon.png -------------------------------------------------------------------------------- /sample/Kikyu!/assets/bgm_gameover_1.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/assets/bgm_gameover_1.mp3 -------------------------------------------------------------------------------- /sample/Kikyu!/assets/bgm_maoudamashii_3_theme09.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/assets/bgm_maoudamashii_3_theme09.mp3 -------------------------------------------------------------------------------- /sample/Kikyu!/assets/bgm_maoudamashii_4_vehicle01.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/assets/bgm_maoudamashii_4_vehicle01.mp3 -------------------------------------------------------------------------------- /sample/Kikyu!/assets/bgm_maoudamashii_4_vehicle02.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/assets/bgm_maoudamashii_4_vehicle02.mp3 -------------------------------------------------------------------------------- /sample/Kikyu!/assets/bgm_maoudamashii_4_vehicle03.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/assets/bgm_maoudamashii_4_vehicle03.mp3 -------------------------------------------------------------------------------- /sample/Kikyu!/assets/enemy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/assets/enemy.png -------------------------------------------------------------------------------- /sample/Kikyu!/assets/fontFixed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/assets/fontFixed.png -------------------------------------------------------------------------------- /sample/Kikyu!/assets/fontProportional.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/assets/fontProportional.png -------------------------------------------------------------------------------- /sample/Kikyu!/assets/icon0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/assets/icon0.png -------------------------------------------------------------------------------- /sample/Kikyu!/assets/itemget.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/assets/itemget.wav -------------------------------------------------------------------------------- /sample/Kikyu!/assets/se_jump_short.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/assets/se_jump_short.mp3 -------------------------------------------------------------------------------- /sample/Kikyu!/assets/se_kusano_06_girl_ikimasu.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/assets/se_kusano_06_girl_ikimasu.mp3 -------------------------------------------------------------------------------- /sample/Kikyu!/assets/se_kusano_09_girl_u.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/assets/se_kusano_09_girl_u.mp3 -------------------------------------------------------------------------------- /sample/Kikyu!/assets/side01.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/assets/side01.jpg -------------------------------------------------------------------------------- /sample/Kikyu!/assets/side02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/assets/side02.jpg -------------------------------------------------------------------------------- /sample/Kikyu!/assets/side03.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/assets/side03.jpg -------------------------------------------------------------------------------- /sample/Kikyu!/assets/side04.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/assets/side04.jpg -------------------------------------------------------------------------------- /sample/Kikyu!/assets/song_shiho_shining_star.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/Kikyu!/assets/song_shiho_shining_star.mp3 -------------------------------------------------------------------------------- /sample/Makefile.in: -------------------------------------------------------------------------------- 1 | # ©2015,2018 YUICHIRO NAKADA 2 | 3 | CATGL=/root/Dropbox/prog/catgl 4 | 5 | CC = clang 6 | CXX = clang++ 7 | CFLAGS = -Os -ffunction-sections -fdata-sections -MMD -MP -Wall -Wextra -Winit-self -Wno-unused-parameter -Wno-float-equal -Wno-missing-braces 8 | LDFLAGS = -Wl,-s -Wl,--gc-sections 9 | TARGET = $(shell basename `readlink -f .`) 10 | OBJDIR = ./obj 11 | ifeq "$(strip $(OBJDIR))" "" 12 | OBJDIR = . 13 | endif 14 | SOURCES = $(wildcard *.cpp) 15 | CSOURCES= $(wildcard *.c) 16 | CSRCS = $(notdir $(SRC)) 17 | OBJECTS = $(addprefix $(OBJDIR)/, $(SOURCES:.cpp=.o)) 18 | COBJECTS= $(addprefix $(OBJDIR)/, $(CSOURCES:.c=.o)) $(addprefix $(OBJDIR)/, $($(notdir SRC):.c=.o)) 19 | #COBJECTS= $(addprefix $(OBJDIR)/, $(CSOURCES:.c=.o)) 20 | #COBJS = $(addprefix $(OBJDIR)/, $(CSRCS:.c=.o)) 21 | DEPENDS = $(OBJECTS:.o=.d) $(COBJECTS:.o=.d) $(COBJS:.o=.d) 22 | 23 | $(TARGET): $(OBJECTS) $(COBJECTS) $(COBJS) $(LIBS) 24 | $(CXX) -o $@ $^ $(LDFLAGS) 25 | 26 | $(OBJDIR)/%.o: %.cpp 27 | @[ -d $(OBJDIR) ] || mkdir -p $(OBJDIR) 28 | $(CXX) -std=c++11 $(CFLAGS) $(INCLUDE) -o $@ -c $< 29 | 30 | $(OBJDIR)/%.o: %.c 31 | @[ -d $(OBJDIR) ] || mkdir -p $(OBJDIR) 32 | $(CC) -std=c11 $(CFLAGS) $(INCLUDE) -o $@ -c $< 33 | 34 | all: clean $(TARGET) 35 | 36 | clean: 37 | rm -f $(OBJECTS) $(COBJECTS) $(DEPENDS) $(TARGET) 38 | @rmdir --ignore-fail-on-non-empty `readlink -f $(OBJDIR)` 39 | 40 | -include $(DEPENDS) 41 | 42 | android: 43 | sh $(CATGL)/android-app/build.sh $(TARGET) $(TARGET) "$(SOURCES) $(CSOURCES) $(CSRCS)" assets $(CATGL) 44 | -------------------------------------------------------------------------------- /sample/box_GL1/Makefile: -------------------------------------------------------------------------------- 1 | INCLUDE = -I../../ -I../../nanovg 2 | LIBS = -lglfw -lGL -lm 3 | 4 | include ../Makefile.in 5 | -------------------------------------------------------------------------------- /sample/box_GL1/box.c: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------- 2 | // catgl 3 | // 4 | // ©2015 Yuichiro Nakada 5 | //--------------------------------------------------------- 6 | 7 | #include 8 | #ifndef M_PI 9 | #define M_PI 3.141592653589793238 10 | #endif 11 | 12 | #define CATGL_GLES_IMPLEMENTATION // Use OpenGL ES1 13 | #include "catgl.h" 14 | 15 | static float angle = 0; 16 | 17 | // 透視投影の設定 18 | void gluPerspective(double fovy, double aspect, double zNear, double zFar) 19 | { 20 | GLfloat xmin, xmax, ymin, ymax; 21 | ymax = zNear * tan(fovy * M_PI / 360.0); 22 | ymin = -ymax; 23 | xmin = ymin * aspect; 24 | xmax = ymax * aspect; 25 | // glFrustumf(xmin, xmax, ymin, ymax, zNear, zFar); 26 | glFrustum(xmin, xmax, ymin, ymax, zNear, zFar); 27 | } 28 | 29 | // 頂点リスト 30 | #define LENGTH (15) 31 | short triangleBuffer[] = { 32 | /* X Y Z */ 33 | -LENGTH / 2, -LENGTH / 2, 0, 34 | LENGTH - LENGTH / 2, -LENGTH / 2, 0, 35 | -LENGTH / 2, LENGTH - LENGTH / 2, 0, 36 | LENGTH - LENGTH / 2, LENGTH - LENGTH / 2, 0, 37 | }; 38 | 39 | // 頂点カラーリスト 40 | float colorBuffer[] = { 41 | /* R G B A */ 42 | 1.0, 0.0, 0.0, 1.0, 43 | 0.0, 1.0, 0.0, 1.0, 44 | 0.0, 0.0, 1.0, 1.0, 45 | 0.5, 0.5, 0.0, 1.0, 46 | }; 47 | 48 | // 表示の初期化 49 | void caInit(int width, int height) 50 | { 51 | // 光源処理無効化 52 | glDisable(GL_LIGHTING); 53 | // 背面処理無効化 54 | glDisable(GL_CULL_FACE); 55 | // デプスバッファ無効化 56 | glDisable(GL_DEPTH_BUFFER_BIT); 57 | // デプステスト無効化 58 | glDisable(GL_DEPTH_TEST); 59 | // 塗りつぶし色設定 60 | glClearColor(.7f, .7f, .9f, 1.f); 61 | // 陰影モード設定 62 | glShadeModel(GL_SMOOTH); 63 | 64 | // 縦横比の設定 65 | float ratio = (float)width / (float)height; 66 | glViewport(0, 0, (int)width, (int)height); 67 | 68 | // 行列演算のモード設定 69 | glMatrixMode(GL_PROJECTION); 70 | // 単位行列のロード 71 | glLoadIdentity(); 72 | // 透視投影の設定 73 | gluPerspective(40.0, ratio, 0.1, 100); 74 | } 75 | 76 | // 四角形の描画 77 | void caRender() 78 | { 79 | // 行列演算のモード設定 80 | glMatrixMode(GL_MODELVIEW); 81 | // 単位行列のロード 82 | glLoadIdentity(); 83 | // 平行移動 84 | glTranslatef(0.0, 0.0, -50.0); 85 | // 角度を演算 86 | angle = (angle + 2); 87 | if (angle > 360) { 88 | angle = 0; 89 | } 90 | // 角度を設定 91 | glRotatef(angle, 0, 0, 1.0f); 92 | 93 | // バッファをクリアー 94 | glClear(GL_COLOR_BUFFER_BIT); 95 | // 頂点リスト指定 96 | glVertexPointer(3, GL_SHORT, 0, triangleBuffer); 97 | // 頂点リストの有効化 98 | glEnableClientState(GL_VERTEX_ARRAY); 99 | // 頂点カラーリスト指定 100 | glColorPointer(4, GL_FLOAT, 0, colorBuffer); 101 | // 頂点カラーリストの有効化 102 | glEnableClientState(GL_COLOR_ARRAY); 103 | // 三角形 描画 104 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 105 | glDisableClientState(GL_VERTEX_ARRAY); 106 | } 107 | 108 | void caEnd() 109 | { 110 | } 111 | -------------------------------------------------------------------------------- /sample/box_GL1/box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/box_GL1/box.png -------------------------------------------------------------------------------- /sample/box_GL1/box_GL1-debug.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/box_GL1/box_GL1-debug.apk -------------------------------------------------------------------------------- /sample/box_line/Makefile: -------------------------------------------------------------------------------- 1 | #SRC = ../glfw/glfw.c 2 | INCLUDE = -I../../ 3 | LIBS = -lglfw -lGL -lGLU -lm 4 | 5 | include ../Makefile.in 6 | -------------------------------------------------------------------------------- /sample/box_line/box_line-debug.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/box_line/box_line-debug.apk -------------------------------------------------------------------------------- /sample/box_line/main.c: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------- 2 | // catgl 3 | // 4 | // ©2015 Yuichiro Nakada 5 | //--------------------------------------------------------- 6 | 7 | #define CATGL_IMPLEMENTATION 8 | #include "catgl.h" 9 | 10 | GLuint program; 11 | GLuint vao; 12 | 13 | // バーテックスシェーダのソースプログラム 14 | static const GLchar vsrc[] = 15 | "#version 120\n" 16 | "attribute vec2 position;" 17 | "void main() {" 18 | " gl_Position = vec4(position, 0.0, 1.0);" 19 | "}"; 20 | 21 | // フラグメントシェーダのソースプログラム 22 | static const GLchar fsrc[] = 23 | "#version 120\n" 24 | "void main() {" 25 | " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);" 26 | "}"; 27 | 28 | // 図形データ 29 | static const GLfloat position[][2] = 30 | { 31 | { -0.5f, -0.5f }, 32 | { 0.5f, -0.5f }, 33 | { 0.5f, 0.5f }, 34 | { -0.5f, 0.5f } 35 | }; 36 | 37 | int vertices; 38 | 39 | GLuint _caCreateObject(const GLfloat *position, int size, GLuint num) 40 | { 41 | GLuint vao; 42 | glGenVertexArrays(1, &vao); 43 | glBindVertexArray(vao); 44 | 45 | GLuint vbo; 46 | glGenBuffers(1, &vbo); 47 | glBindBuffer(GL_ARRAY_BUFFER, vbo); 48 | glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * size * num, position, GL_STATIC_DRAW); 49 | 50 | glVertexAttribPointer(0, size, GL_FLOAT, GL_FALSE, 0, 0); 51 | glEnableVertexAttribArray(0); 52 | 53 | glBindBuffer(GL_ARRAY_BUFFER, 0); 54 | glBindVertexArray(0); 55 | 56 | return vao; 57 | } 58 | 59 | // 表示の初期化 60 | void caInit(int width, int height) 61 | { 62 | vertices = sizeof position / sizeof position[0]; 63 | 64 | program = caCreateProgram(vsrc, "position", fsrc, "gl_FragColor"); 65 | vao = _caCreateObject(position, 2, vertices); 66 | } 67 | 68 | // 描画 69 | void caRender() 70 | { 71 | glClearColor(1.0f, 1.0f, 1.0f, 0.0f); 72 | glClear(GL_COLOR_BUFFER_BIT); 73 | 74 | glUseProgram(program); 75 | 76 | glBindVertexArray(vao); 77 | glDrawArrays(GL_LINE_LOOP, 0, vertices); 78 | glBindVertexArray(0); 79 | 80 | glUseProgram(0); 81 | } 82 | 83 | void caEnd() 84 | { 85 | glDeleteProgram(program); 86 | } 87 | -------------------------------------------------------------------------------- /sample/box_line/main.c.orig: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------- 2 | // catgl 3 | // 4 | // ©2015 Yuichiro Nakada 5 | //--------------------------------------------------------- 6 | 7 | #define CATGL_IMPLEMENTATION 8 | #include "catgl.h" 9 | 10 | GLuint program; 11 | GLuint vao; 12 | 13 | #include 14 | // シェーダオブジェクトのコンパイル結果を表示する 15 | static GLboolean printShaderInfoLog(GLuint shader, const char *str) 16 | { 17 | // コンパイル結果を取得する 18 | GLint status; 19 | glGetShaderiv(shader, GL_COMPILE_STATUS, &status); 20 | if (status == GL_FALSE) fprintf(stderr, "Compile Error in %s\n", str); 21 | 22 | // シェーダのコンパイル時のログの長さを取得する 23 | GLsizei bufSize; 24 | glGetShaderiv(shader, GL_INFO_LOG_LENGTH , &bufSize); 25 | 26 | if (bufSize > 1) { 27 | // シェーダのコンパイル時のログの内容を取得する 28 | GLchar infoLog[bufSize]; 29 | GLsizei length; 30 | glGetShaderInfoLog(shader, bufSize, &length, infoLog); 31 | fprintf(stderr, "%s\n", infoLog); 32 | } 33 | 34 | return (GLboolean)status; 35 | } 36 | 37 | // プログラムオブジェクトのリンク結果を表示する 38 | static GLboolean printProgramInfoLog(GLuint program) 39 | { 40 | // リンク結果を取得する 41 | GLint status; 42 | glGetProgramiv(program, GL_LINK_STATUS, &status); 43 | if (status == GL_FALSE) fprintf(stderr, "Link Error\n"); 44 | 45 | // シェーダのリンク時のログの長さを取得する 46 | GLsizei bufSize; 47 | glGetProgramiv(program, GL_INFO_LOG_LENGTH , &bufSize); 48 | 49 | if (bufSize > 1) { 50 | // シェーダのリンク時のログの内容を取得する 51 | GLchar infoLog[bufSize]; 52 | GLsizei length; 53 | glGetProgramInfoLog(program, bufSize, &length, infoLog); 54 | fprintf(stderr, "%s\n", infoLog); 55 | } 56 | 57 | return (GLboolean)status; 58 | } 59 | 60 | // プログラムオブジェクトの作成 61 | GLuint createProgram(const char *vsrc, const char *pv, const char *fsrc, const char *fc) 62 | { 63 | // バーテックスシェーダのシェーダオブジェクト 64 | GLuint vobj = glCreateShader(GL_VERTEX_SHADER); 65 | glShaderSource(vobj, 1, &vsrc, NULL); 66 | glCompileShader(vobj); 67 | printShaderInfoLog(vobj, "vertex shader"); 68 | 69 | // フラグメントシェーダのシェーダオブジェクトの作成 70 | GLuint fobj = glCreateShader(GL_FRAGMENT_SHADER); 71 | glShaderSource(fobj, 1, &fsrc, NULL); 72 | glCompileShader(fobj); 73 | printShaderInfoLog(fobj, "fragment shader"); 74 | 75 | // シェーダオブジェクトの取り付け 76 | GLuint program = glCreateProgram(); 77 | glAttachShader(program, vobj); 78 | glDeleteShader(vobj); 79 | glAttachShader(program, fobj); 80 | glDeleteShader(fobj); 81 | 82 | // プログラムオブジェクトのリンク 83 | glBindAttribLocation(program, 0, pv); 84 | glBindFragDataLocation(program, 0, fc); 85 | glLinkProgram(program); 86 | printProgramInfoLog(program); 87 | 88 | return program; 89 | } 90 | 91 | // 頂点配列オブジェクトの作成 92 | GLuint createObject(GLuint vertices, const GLfloat (*position)[2]) 93 | { 94 | // 頂点配列オブジェクト 95 | GLuint vao; 96 | glGenVertexArrays(1, &vao); 97 | glBindVertexArray(vao); 98 | 99 | // 頂点バッファオブジェクト 100 | GLuint vbo; 101 | glGenBuffers(1, &vbo); 102 | glBindBuffer(GL_ARRAY_BUFFER, vbo); 103 | glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 2 * vertices, position, GL_STATIC_DRAW); 104 | 105 | // 結合されている頂点バッファオブジェクトを attribute 変数から参照できるようにする 106 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); 107 | glEnableVertexAttribArray(0); 108 | 109 | // 頂点バッファオブジェクトと頂点配列オブジェクトの結合を解除する 110 | glBindBuffer(GL_ARRAY_BUFFER, 0); 111 | glBindVertexArray(0); 112 | 113 | return vao; 114 | } 115 | 116 | int vertices; 117 | // 表示の初期化 118 | void caInit(int width, int height) 119 | { 120 | // バーテックスシェーダのソースプログラム 121 | static const GLchar vsrc[] = 122 | "#version 120\n" 123 | "attribute vec2 position;" 124 | "void main() {" 125 | " gl_Position = vec4(position, 0.0, 1.0);" 126 | "}"; 127 | 128 | // フラグメントシェーダのソースプログラム 129 | static const GLchar fsrc[] = 130 | "#version 120\n" 131 | "void main() {" 132 | " gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);" 133 | "}"; 134 | 135 | // プログラムオブジェクトの作成 136 | program = createProgram(vsrc, "position", fsrc, "gl_FragColor"); 137 | 138 | // 図形データ 139 | static const GLfloat position[][2] = 140 | { 141 | { -0.5f, -0.5f }, 142 | { 0.5f, -0.5f }, 143 | { 0.5f, 0.5f }, 144 | { -0.5f, 0.5f } 145 | }; 146 | vertices = sizeof position / sizeof position[0]; 147 | 148 | // 頂点配列オブジェクトの作成 149 | vao = createObject(vertices, position); 150 | } 151 | 152 | // 描画 153 | void caRender() 154 | { 155 | glClearColor(1.0f, 1.0f, 1.0f, 0.0f); 156 | glClear(GL_COLOR_BUFFER_BIT); 157 | 158 | glUseProgram(program); 159 | 160 | glBindVertexArray(vao); 161 | glDrawArrays(GL_LINE_LOOP, 0, vertices); 162 | glBindVertexArray(0); 163 | 164 | glUseProgram(0); 165 | } 166 | 167 | void caEnd() 168 | { 169 | glDeleteProgram(program); 170 | } 171 | -------------------------------------------------------------------------------- /sample/cube_GL1/Makefile: -------------------------------------------------------------------------------- 1 | #SRC = ../glfw/glfw.c 2 | INCLUDE = -I../../ 3 | LIBS = -lglfw -lGL -lGLU -lm 4 | 5 | include ../Makefile.in 6 | -------------------------------------------------------------------------------- /sample/cube_GL1/cube-debug.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/cube_GL1/cube-debug.apk -------------------------------------------------------------------------------- /sample/cube_GL1/main.c: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------- 2 | // catgl 3 | // 4 | // ©2015 Yuichiro Nakada 5 | //--------------------------------------------------------- 6 | 7 | #include 8 | 9 | #define CATGL_GLES_IMPLEMENTATION // Use OpenGL ES1 10 | #include "catgl.h" 11 | 12 | static float angle = 0; 13 | 14 | // 透視投影の設定 15 | void gluPerspective(double fovy, double aspect, double zNear, double zFar) 16 | { 17 | GLfloat xmin, xmax, ymin, ymax; 18 | ymax = zNear * tan(fovy * CATGL_PI / 360.0); 19 | ymin = -ymax; 20 | xmin = ymin * aspect; 21 | xmax = ymax * aspect; 22 | // glFrustumf(xmin, xmax, ymin, ymax, zNear, zFar); 23 | glFrustum(xmin, xmax, ymin, ymax, zNear, zFar); 24 | } 25 | 26 | #include "models.h" 27 | MODEL_T m; 28 | // 表示の初期化 29 | void caInit(int width, int height) 30 | { 31 | // Set background color and clear buffers 32 | glClearColor((0.3922f+7*0.5f)/8, (0.1176f+7*0.5f)/8, (0.5882f+7*0.5f)/8, 1.0f); 33 | 34 | // Enable back face culling. 35 | glEnable(GL_CULL_FACE); 36 | 37 | glEnable(GL_DEPTH_TEST); 38 | glClearDepthf(1.0); 39 | glDepthFunc(GL_LEQUAL); 40 | 41 | float noAmbient[] = {1.0f, 1.0f, 1.0f, 1.0f}; 42 | glLightfv(GL_LIGHT0, GL_AMBIENT, noAmbient); 43 | glEnable(GL_LIGHT0); 44 | glEnable(GL_LIGHTING); 45 | 46 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); 47 | glEnableClientState(GL_VERTEX_ARRAY); 48 | 49 | // 縦横比の設定 50 | float ratio = (float)width / (float)height; 51 | glViewport(0, 0, (int)width, (int)height); 52 | 53 | // 行列演算のモード設定 54 | glMatrixMode(GL_PROJECTION); 55 | // 単位行列のロード 56 | glLoadIdentity(); 57 | // 透視投影の設定 58 | gluPerspective(40.0, ratio, 0.1, 100); 59 | 60 | m = cube_wavefront(); 61 | } 62 | 63 | // 四角形の描画 64 | void caRender() 65 | { 66 | // 行列演算のモード設定 67 | glMatrixMode(GL_MODELVIEW); 68 | // 単位行列のロード 69 | glLoadIdentity(); 70 | // 平行移動 71 | glTranslatef(0.0, 0.0, -2.0); 72 | // 角度を演算 73 | angle = (angle + 2); 74 | if (angle >= 360) { 75 | angle = 0; 76 | } 77 | // 角度を設定 78 | glRotatef(angle, angle, angle, 1.0f); 79 | 80 | // バッファをクリアー 81 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 82 | 83 | draw_wavefront(m, 0); 84 | } 85 | 86 | void caEnd() 87 | { 88 | } 89 | -------------------------------------------------------------------------------- /sample/cube_GL1/models.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Broadcom Europe Ltd 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the copyright holder nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef MODELS_T 29 | #define MODELS_T 30 | typedef struct opqaue_model_s * MODEL_T; 31 | 32 | MODEL_T load_wavefront(const char *modelname, const char *texturename); 33 | MODEL_T cube_wavefront(void); 34 | void unload_wavefront(MODEL_T m); 35 | int draw_wavefront(MODEL_T m, GLuint texture); 36 | #endif 37 | -------------------------------------------------------------------------------- /sample/glsl/Makefile: -------------------------------------------------------------------------------- 1 | SRC = 2 | INCLUDE = -I../../ -I../../nanovg 3 | LIBS = -lglfw -lGL -lm 4 | 5 | include ../Makefile.in 6 | -------------------------------------------------------------------------------- /sample/glsl/WebGL/004.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | GLSL - WebGL 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 24 | 154 | 155 | 156 | 157 | 158 | 159 |
Prev 160 | /Next 161 | 162 | 163 | -------------------------------------------------------------------------------- /sample/glsl/WebGL/005.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | GLSL - WebGL 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 24 | 66 | 67 | 68 | 69 | 70 | 71 |
Prev 72 | /Next 73 | 74 | 75 | -------------------------------------------------------------------------------- /sample/glsl/WebGL/006.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | GLSL - WebGL 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 24 | 122 | 123 | 124 | 125 | 126 | 127 |
Prev 128 | /Next 129 | 130 | 131 | -------------------------------------------------------------------------------- /sample/glsl/WebGL/70+.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/glsl/WebGL/70+.jpg -------------------------------------------------------------------------------- /sample/glsl/WebGL/70.glsl: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------- 2 | // Ray marching engine 3 | // 4 | // ©2015 Yuichiro Nakada 5 | //--------------------------------------------------------- 6 | 7 | uniform float time; 8 | uniform vec2 mouse; 9 | uniform vec2 resolution; 10 | uniform sampler2D iChannel0; 11 | uniform sampler2D iChannel1; 12 | uniform sampler2D iChannel2; 13 | 14 | float iGlobalTime = time; 15 | //vec4 iMouse = vec4(mouse.xy*resolution.xy, mouse.z., 0.); 16 | uniform vec4 iMouse; 17 | vec2 iResolution = resolution; 18 | 19 | #define PI 3.14159265358979 20 | 21 | float sdPlane(vec3 p, vec4 n) 22 | { 23 | // n must be normalized 24 | return dot(p, n.xyz) + n.w; 25 | } 26 | float sdBox(vec3 p, vec3 b) 27 | { 28 | vec3 d = abs(p) - b; 29 | return min(max(d.x, max(d.y, d.z)), 0.) + length(max(d, 0.)); 30 | } 31 | float sdSphere(vec3 p, float s) 32 | { 33 | return length(p)-s; 34 | } 35 | float sdCylinder(vec3 p, vec2 r) 36 | { 37 | vec2 d = abs(vec2(length(p.xy), p.z)) - r; 38 | return min(max(d.x, d.y), 0.) + length(max(d, 0.)) - 0.1; 39 | } 40 | 41 | const float ADC = 0.1; // 0.0-1.0 42 | const float alpha = .25; // 0.0-1.0 43 | const float maxDist = 80.; // 0.0-?.? 44 | 45 | float s, c; 46 | #define rotate(p, a) mat2(c=cos(a), s=-sin(a), -s, c) * p 47 | 48 | #define GLOBE 10. 49 | void mainImage(out vec4 fragColor, in vec2 fragCoord) 50 | { 51 | vec2 uv = (gl_FragCoord.xy - .5*resolution) / resolution.y; 52 | vec2 mPos = 3.5 * (iMouse.xy-.5*resolution) / resolution.y; 53 | 54 | vec3 ro = vec3(.0, .0, -15.); 55 | //vec3 ro = vec3(.0, .0, -1.5); // GLOBE 10. 56 | vec3 rd = normalize(vec3(uv, .5)); 57 | 58 | //vec2 nav = iMouse.z>0. ? mPos.yx : vec2(.45, .3*iGlobalTime); 59 | vec2 nav = iMouse.z>0. ? mPos.yx : vec2(-.45, .3*iGlobalTime); 60 | ro.yz = rotate(ro.yz, nav.x); 61 | ro.xz = rotate(ro.xz, nav.y); 62 | rd.yz = rotate(rd.yz, nav.x); 63 | rd.xz = rotate(rd.xz, nav.y); 64 | 65 | // light pos, background 66 | vec3 lPos = normalize(vec3(.5, 1., .25)); 67 | vec3 bg = vec3(.3, .5, 1.) + pow(length(rd+lPos)/2.5, 2.); 68 | 69 | vec4 RGBA = vec4(vec3(0.), 1.); 70 | 71 | float dist; 72 | float t = 0.1; 73 | for (int i=0; i<150; i++) { 74 | vec3 pos = ro+rd*t; 75 | // vec4 r = map(ro, rd, t); 76 | 77 | // vec4 depth = texture2D(iChannel0, vec2(mod(pos.x, 5.)/5., 1.-mod(pos.y, 5.)/5.)); // 1/4 78 | // vec4 depth = texture2D(iChannel0, vec2(mod(pos.x+5., 10.)/10., 1.-mod(pos.y+5., 10.)/10.)); 79 | // dist = sdBox(pos, vec3(5., 5., 5.)) - depth.r*2.; 80 | 81 | // vec2 tpos = vec2(mod(pos.x+5., 10.)/10., 1.-mod(pos.y+5., 10.)/10.); 82 | // vec2 tpos = vec2(mod(pos.x, 20.)/20., 1.-mod(pos.y, 10.)/10.); 83 | //vec2 tpos = vec2(mod(pos.x+5., (PI*5.))/(PI*5.), 1.-mod(pos.y, 10.)/10.); 84 | // vec2 tpos = vec2((atan(pos.z, pos.x)+PI)/(2.*PI), 1.-mod(pos.y, 10.)/10.); 85 | 86 | //vec2 tpos = vec2(atan(pos.z, pos.x)/(2.*PI)+.5, atan(-pos.y, sqrt(pos.z*pos.z+pos.x*pos.x))/PI+.5); 87 | //vec2 tpos = vec2(atan(pos.z, pos.x)/(2.*PI)+.5, asin(-pos.y/GLOBE)/PI+.5); 88 | dist = sdSphere(pos, GLOBE); 89 | 90 | //vec2 tpos = vec2(asin(pos.x/10.)/PI+.5, asin(pos.y/10.)/PI+.5); 91 | //vec2 tpos = vec2((pos.x/10.)*.5+.5, (pos.y/10.)*.5+.5); 92 | 93 | /*float phi = acos(pos.z); 94 | vec2 tpos = vec2(phi/PI, acos(pos.y/sin(phi)/(2.*PI)));*/ 95 | 96 | if (dist>maxDist || RGBA.a0. ? mPos.yx : vec2(.45, .3*iGlobalTime); 59 | vec2 nav = iMouse.z>0. ? mPos.yx : vec2(-.45, .3*iGlobalTime); 60 | ro.yz = rotate(ro.yz, nav.x); 61 | ro.xz = rotate(ro.xz, nav.y); 62 | rd.yz = rotate(rd.yz, nav.x); 63 | rd.xz = rotate(rd.xz, nav.y); 64 | 65 | // light pos, background 66 | vec3 lPos = normalize(vec3(.5, 1., .25)); 67 | vec3 bg = vec3(.3, .5, 1.) + pow(length(rd+lPos)/2.5, 2.); 68 | 69 | vec4 RGBA = vec4(vec3(0.), 1.); 70 | 71 | float dist; 72 | float t = 0.1; 73 | for (int i=0; i<150; i++) { 74 | vec3 pos = ro+rd*t; 75 | // vec4 r = map(ro, rd, t); 76 | 77 | // vec4 depth = texture2D(iChannel0, vec2(mod(pos.x, 5.)/5., 1.-mod(pos.y, 5.)/5.)); // 1/4 78 | // vec4 depth = texture2D(iChannel0, vec2(mod(pos.x+5., 10.)/10., 1.-mod(pos.y+5., 10.)/10.)); 79 | // dist = sdBox(pos, vec3(5., 5., 5.)) - depth.r*2.; 80 | 81 | // vec2 tpos = vec2(mod(pos.x+5., 10.)/10., 1.-mod(pos.y+5., 10.)/10.); 82 | // vec2 tpos = vec2(mod(pos.x, 20.)/20., 1.-mod(pos.y, 10.)/10.); 83 | 84 | //vec2 tpos = vec2(atan(pos.z, pos.x)/(2.*PI)+.5, atan(-pos.y, sqrt(pos.z*pos.z+pos.x*pos.x))/PI+.5); 85 | // dist = sdSphere(pos, GLOBE); 86 | dist = -sdSphere(pos, GLOBE); 87 | 88 | if (dist>maxDist || RGBA.a0. ? mPos.yx : vec2(.45, -.3*iGlobalTime); 40 | ro.yz = rotate(ro.yz, nav.x); 41 | ro.xz = rotate(ro.xz, nav.y); 42 | rd.yz = rotate(rd.yz, nav.x); 43 | rd.xz = rotate(rd.xz, nav.y); 44 | 45 | vec3 adj, xV, yV, zV, V_; 46 | vec3 po = sign(rd); 47 | vec3 V = ro, LV; 48 | float dist; 49 | 50 | // light pos, background 51 | vec3 lPos = normalize(vec3(.5, 1., .25)); 52 | vec3 bg = vec3(.3, .5, 1.) + pow(length(rd+lPos)/2.5, 2.); 53 | 54 | vec4 RGBA = vec4(vec3(0.), 1.); 55 | 56 | float t = 0.1; 57 | for (int i=0; i<150; i++) { 58 | vec3 pos = ro+rd*t; 59 | // vec4 r = map(ro, rd, t); 60 | 61 | // vec4 depth = texture2D(iChannel0, vec2(mod(pos.x, 5.)/5., 1.-mod(pos.y, 5.)/5.)); // 1/4 62 | vec4 depth = texture2D(iChannel0, vec2(mod(pos.x+5., 10.)/10., 1.-mod(pos.y+5., 10.)/10.)); 63 | dist = sdBox(pos, vec3(5., 5., 5.)) - depth.r*2.; 64 | 65 | if (dist>maxDist || RGBA.a 2 | 3 | 4 | 5 | 6 | 7 | GLSL - WebGL 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 23 | 24 | 31 | 32 | 33 | 34 | 35 | 36 | @@PREV@@ 37 | @@NEXT@@ 38 | 39 | 40 | -------------------------------------------------------------------------------- /sample/glsl/WebGL/index.js: -------------------------------------------------------------------------------- 1 | var currentProgram; 2 | var c, gl; 3 | var aLoc = []; 4 | var uLoc = []; 5 | var texture = []; 6 | 7 | function initWebGL() { 8 | c = document.getElementById("c"); 9 | gl = c.getContext("experimental-webgl"); 10 | } 11 | 12 | function initShaders() { 13 | var p = gl.createProgram(); 14 | var v = document.getElementById("vs").textContent; 15 | var f = document.getElementById("fs").textContent; 16 | var vs = gl.createShader(gl.VERTEX_SHADER); 17 | var fs = gl.createShader(gl.FRAGMENT_SHADER); 18 | gl.shaderSource(vs, v); 19 | gl.shaderSource(fs, f); 20 | gl.compileShader(vs); 21 | gl.compileShader(fs); 22 | gl.attachShader(p, vs); 23 | gl.attachShader(p, fs); 24 | gl.linkProgram(p); 25 | gl.useProgram(p); 26 | aLoc[0] = gl.getAttribLocation(p, "position"); 27 | //aLoc[1] = gl.getAttribLocation(p, "color"); 28 | gl.enableVertexAttribArray(aLoc[0]); 29 | //gl.enableVertexAttribArray(aLoc[1]); 30 | currentProgram = p; 31 | } 32 | 33 | function checkSize(img) { 34 | var w = img.naturalWidth, h = img.naturalHeight; 35 | var size = Math.pow(2, Math.log(Math.min(w, h)) / Math.LN2 | 0); // largest 2^n integer that does not exceed s 36 | if (w !== h || w !== size) { 37 | var canv = document.createElement('canvas'); 38 | canv.height = canv.width = size; 39 | canv.getContext('2d').drawImage(img, 0, 0, w, h, 0, 0, size, size); 40 | img = canv; 41 | } 42 | return img; 43 | } 44 | function create_texture(n, source) { 45 | var img = new Image(); 46 | 47 | img.onload = function() { 48 | var tex = gl.createTexture(); 49 | gl.bindTexture(gl.TEXTURE_2D, tex); 50 | //gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, true); 51 | // gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img); 52 | gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, checkSize(img)); 53 | //gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); 54 | //gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); 55 | gl.generateMipmap(gl.TEXTURE_2D); 56 | gl.bindTexture(gl.TEXTURE_2D, null); 57 | texture[n] = tex; 58 | }; 59 | 60 | img.src = source; 61 | } 62 | 63 | function render() { 64 | parameters.time = Date.now() - parameters.startTime; 65 | 66 | gl.useProgram( currentProgram ); 67 | gl.uniform1f( gl.getUniformLocation(currentProgram, 'time'), parameters.time / 1000 ); 68 | gl.uniform2f( gl.getUniformLocation(currentProgram, 'mouse'), parameters.mouseX, parameters.mouseY ); 69 | gl.uniform2f( gl.getUniformLocation(currentProgram, 'resolution'), parameters.screenWidth, parameters.screenHeight ); 70 | 71 | if (texture[0]!=null) { 72 | gl.activeTexture(gl.TEXTURE0); 73 | gl.bindTexture(gl.TEXTURE_2D, texture[0]); 74 | gl.uniform1i(gl.getUniformLocation(currentProgram, 'iChannel0'), 0); 75 | } 76 | if (texture[1]!=null) { 77 | gl.activeTexture(gl.TEXTURE1); 78 | gl.bindTexture(gl.TEXTURE_2D, texture[1]); 79 | gl.uniform1i(gl.getUniformLocation(currentProgram, 'iChannel1'), 1); 80 | } 81 | 82 | // Create vertex buffer (2 triangles) 83 | buffer = gl.createBuffer(); 84 | gl.bindBuffer( gl.ARRAY_BUFFER, buffer ); 85 | gl.bufferData( gl.ARRAY_BUFFER, new Float32Array( [ -1.0, -1.0, 0.0, 1.0, -1.0, 0.0, -1.0, 1.0, 0.0, 1.0, -1.0, 0.0, 1.0, 1.0, 0.0, -1.0, 1.0, 0.0 ] ), gl.STATIC_DRAW ); 86 | gl.vertexAttribPointer( aLoc[0], 3, gl.FLOAT, false, 0, 0 ); 87 | gl.clear( gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT ); 88 | gl.drawArrays( gl.TRIANGLES, 0, 6 ); 89 | // gl.flush(); 90 | } 91 | 92 | //var canvas = document.createElement('canvas'); 93 | var canvas = $('c'); 94 | var parameters = { startTime: Date.now(), time: 0, mouseX: 0.5, mouseY: 0.5, screenWidth: 0, screenHeight: 0 }; 95 | parameters.screenWidth = canvas.width; 96 | parameters.screenHeight = canvas.height; 97 | 98 | initWebGL(); 99 | initShaders(); 100 | 101 | function $(e) { return document.getElementById(e); } 102 | if ($('webgljs').getAttribute('data-texture0')) { 103 | gl.activeTexture(gl.TEXTURE0); 104 | create_texture(0, $('webgljs').getAttribute('data-texture0')); 105 | } 106 | if ($('webgljs').getAttribute('data-texture1')) { 107 | gl.activeTexture(gl.TEXTURE1); 108 | create_texture(1, $('webgljs').getAttribute('data-texture1')); 109 | } 110 | 111 | document.addEventListener( 'mousemove', function ( event ) { 112 | var clientX = event.clientX; 113 | var clientY = event.clientY; 114 | 115 | parameters.mouseX = clientX / window.innerWidth; 116 | parameters.mouseY = 1 - clientY / window.innerHeight; 117 | }, false ); 118 | 119 | if ( !window.requestAnimationFrame ) { 120 | window.requestAnimationFrame = ( function() { 121 | return window.webkitRequestAnimationFrame || 122 | window.mozRequestAnimationFrame || 123 | window.oRequestAnimationFrame || 124 | window.msRequestAnimationFrame || 125 | function ( callback, element ) { 126 | window.setTimeout( callback, 1000 / 60 ); 127 | }; 128 | } )(); 129 | } 130 | function animate() { 131 | requestAnimationFrame( animate ); 132 | render(); 133 | } 134 | animate(); 135 | -------------------------------------------------------------------------------- /sample/glsl/WebGL/make_html.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | TEMPLATE_FILE=index.html.orig 3 | 4 | mv *.html /tmp/ 5 | 6 | make_html() { 7 | out=`printf "%03d.html" ${count}` 8 | prev=`printf "%03d.html" $((${count}-1))` 9 | next=`printf "%03d.html" $((${count}+1))` 10 | 11 | k=1 12 | while read line 13 | do 14 | if [[ "${line}" =~ "@@GLSL@@" ]]; then 15 | ((k++)) 16 | while read include_line 17 | do 18 | echo -e "$include_line" >> ${out} 19 | done < ${name} 20 | elif [[ "${line}" =~ "@@PREV@@" ]]; then 21 | echo '
Prev' >> ${out} 22 | elif [[ "${line}" =~ "@@NEXT@@" ]]; then 23 | echo '/Next' >> ${out} 24 | else 25 | echo ${line} >> ${out} 26 | fi 27 | done < ${TEMPLATE_FILE} 28 | 29 | basename=${name##*/} 30 | filename=${basename%.*} 31 | args= 32 | # tex=`printf "%03d.jpg" ${count}` 33 | tex=${filename}".jpg" 34 | [ -r ${tex} ] && args='data-texture0="'${tex}'"' 35 | tex=${filename}"+.jpg" 36 | [ -r ${tex} ] && args=${args}' data-texture1="'${tex}'"' 37 | sed -e "s/@@ARGS@@/${args}/" -i ${out} 38 | } 39 | 40 | count=0 41 | for name in *.glsl 42 | do 43 | make_html 44 | ((count++)) 45 | done 46 | -------------------------------------------------------------------------------- /sample/glsl/WebGL/style.css: -------------------------------------------------------------------------------- 1 | * { 2 | margin: 0; 3 | padding: 0; 4 | border: 0; 5 | overflow: hidden; 6 | } 7 | 8 | body { 9 | background: #fff; 10 | font: sans-serif; 11 | } 12 | -------------------------------------------------------------------------------- /sample/glsl/WebGL/update_html.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | #git checkout -b gh-pages (初回のみ) 3 | 4 | git checkout gh-pages 5 | git rebase master 6 | git push origin gh-pages 7 | 8 | git checkout master 9 | 10 | -------------------------------------------------------------------------------- /sample/glsl/assets/AtmosphericScattering.glsl: -------------------------------------------------------------------------------- 1 | uniform float time; 2 | uniform vec2 mouse; 3 | uniform vec2 resolution; 4 | 5 | float iGlobalTime = time; 6 | vec4 iMouse = vec4(mouse, 0.0, 0.0); 7 | vec2 iResolution = resolution; 8 | 9 | // Written by GLtracy 10 | 11 | // math const 12 | const float PI = 3.14159265359; 13 | const float DEG_TO_RAD = PI / 180.0; 14 | const float MAX = 10000.0; 15 | 16 | // scatter const 17 | const float K_R = 0.166; 18 | const float K_M = 0.0025; 19 | const float E = 14.3; // light intensity 20 | const vec3 C_R = vec3( 0.3, 0.7, 1.0 ); // 1 / wavelength ^ 4 21 | const float G_M = -0.85; // Mie g 22 | 23 | const float R = 1.0; 24 | const float R_INNER = 0.7; 25 | const float SCALE_H = 4.0 / ( R - R_INNER ); 26 | const float SCALE_L = 1.0 / ( R - R_INNER ); 27 | 28 | const int NUM_OUT_SCATTER = 10; 29 | const float FNUM_OUT_SCATTER = 10.0; 30 | 31 | const int NUM_IN_SCATTER = 10; 32 | const float FNUM_IN_SCATTER = 10.0; 33 | 34 | // angle : pitch, yaw 35 | mat3 rot3xy( vec2 angle ) { 36 | vec2 c = cos( angle ); 37 | vec2 s = sin( angle ); 38 | 39 | return mat3( 40 | c.y , 0.0, -s.y, 41 | s.y * s.x, c.x, c.y * s.x, 42 | s.y * c.x, -s.x, c.y * c.x 43 | ); 44 | } 45 | 46 | // ray direction 47 | vec3 ray_dir( float fov, vec2 size, vec2 pos ) { 48 | vec2 xy = pos - size * 0.5; 49 | 50 | float cot_half_fov = tan( ( 90.0 - fov * 0.5 ) * DEG_TO_RAD ); 51 | float z = size.y * 0.5 * cot_half_fov; 52 | 53 | return normalize( vec3( xy, -z ) ); 54 | } 55 | 56 | // ray intersects sphere 57 | // e = -b +/- sqrt( b^2 - c ) 58 | vec2 ray_vs_sphere( vec3 p, vec3 dir, float r ) { 59 | float b = dot( p, dir ); 60 | float c = dot( p, p ) - r * r; 61 | 62 | float d = b * b - c; 63 | if ( d < 0.0 ) { 64 | return vec2( MAX, -MAX ); 65 | } 66 | d = sqrt( d ); 67 | 68 | return vec2( -b - d, -b + d ); 69 | } 70 | 71 | // Mie 72 | // g : ( -0.75, -0.999 ) 73 | // 3 * ( 1 - g^2 ) 1 + c^2 74 | // F = ----------------- * ------------------------------- 75 | // 2 * ( 2 + g^2 ) ( 1 + g^2 - 2 * g * c )^(3/2) 76 | float phase_mie( float g, float c, float cc ) { 77 | float gg = g * g; 78 | 79 | float a = ( 1.0 - gg ) * ( 1.0 + cc ); 80 | 81 | float b = 1.0 + gg - 2.0 * g * c; 82 | b *= sqrt( b ); 83 | b *= 2.0 + gg; 84 | 85 | return 1.5 * a / b; 86 | } 87 | 88 | // Reyleigh 89 | // g : 0 90 | // F = 3/4 * ( 1 + c^2 ) 91 | float phase_reyleigh( float cc ) { 92 | return 0.75 * ( 1.0 + cc ); 93 | } 94 | 95 | float density( vec3 p ){ 96 | return exp( -( length( p ) - R_INNER ) * SCALE_H ); 97 | } 98 | 99 | float optic( vec3 p, vec3 q ) { 100 | vec3 step = ( q - p ) / FNUM_OUT_SCATTER; 101 | vec3 v = p + step * 0.5; 102 | 103 | float sum = 0.0; 104 | for ( int i = 0; i < NUM_OUT_SCATTER; i++ ) { 105 | sum += density( v ); 106 | v += step; 107 | } 108 | sum *= length( step ) * SCALE_L; 109 | 110 | return sum; 111 | } 112 | 113 | vec3 in_scatter( vec3 o, vec3 dir, vec2 e, vec3 l ) { 114 | float len = ( e.y - e.x ) / FNUM_IN_SCATTER; 115 | vec3 step = dir * len; 116 | vec3 p = o + dir * e.x; 117 | vec3 v = p + dir * ( len * 0.5 ); 118 | 119 | vec3 sum = vec3( 0.0 ); 120 | for ( int i = 0; i < NUM_IN_SCATTER; i++ ) { 121 | vec2 f = ray_vs_sphere( v, l, R ); 122 | vec3 u = v + l * f.y; 123 | 124 | float n = ( optic( p, v ) + optic( v, u ) ) * ( PI * 4.0 ); 125 | 126 | sum += density( v ) * exp( -n * ( K_R * C_R + K_M ) ); 127 | 128 | v += step; 129 | } 130 | sum *= len * SCALE_L; 131 | 132 | float c = dot( dir, -l ); 133 | float cc = c * c; 134 | 135 | return sum * ( K_R * C_R * phase_reyleigh( cc ) + K_M * phase_mie( G_M, c, cc ) ) * E; 136 | } 137 | 138 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 139 | { 140 | // default ray dir 141 | vec3 dir = ray_dir( 45.0, iResolution.xy, fragCoord.xy ); 142 | 143 | // default ray origin 144 | vec3 eye = vec3( 0.0, 0.0, 2.4 ); 145 | 146 | // rotate camera 147 | mat3 rot = rot3xy( vec2( 0.0, iGlobalTime * 0.5 ) ); 148 | dir = rot * dir; 149 | eye = rot * eye; 150 | 151 | // sun light dir 152 | vec3 l = vec3( 0, 0, 1 ); 153 | 154 | vec2 e = ray_vs_sphere( eye, dir, R ); 155 | if ( e.x > e.y ) { 156 | discard; 157 | } 158 | 159 | vec2 f = ray_vs_sphere( eye, dir, R_INNER ); 160 | e.y = min( e.y, f.x ); 161 | 162 | vec3 I = in_scatter( eye, dir, e, l ); 163 | 164 | fragColor = vec4( I, 1.0 ); 165 | } 166 | 167 | void main() 168 | { 169 | vec4 color = vec4(0.0,0.0,0.0,1.0); 170 | mainImage( color, gl_FragCoord.xy ); 171 | color.w = 1.0; 172 | gl_FragColor = color; 173 | } 174 | -------------------------------------------------------------------------------- /sample/glsl/assets/Clover.glsl: -------------------------------------------------------------------------------- 1 | // 2 | uniform float time; 3 | uniform vec2 mouse; 4 | uniform vec2 resolution; 5 | 6 | float iGlobalTime = time; 7 | vec4 iMouse = vec4(mouse, 0.0, 0.0); 8 | vec2 iResolution = resolution; 9 | 10 | // Created by inigo quilez - iq/2013 11 | // License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. 12 | 13 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 14 | { 15 | vec2 q = 0.6 * (2.0*fragCoord.xy-iResolution.xy)/min(iResolution.y,iResolution.x); 16 | 17 | float a = atan(q.x,q.y); 18 | float r = length(q); 19 | float s = 0.5 + 0.5*sin(3.0*a + iGlobalTime); 20 | float g = sin(1.57+3.0*a+iGlobalTime); 21 | float d = 0.15 + 0.3*sqrt(s) + 0.15*g*g; 22 | float h = r/d; 23 | float f = 1.0-smoothstep( 0.95, 1.0, h ); 24 | h *= 1.0-0.5*(1.0-h)*smoothstep(0.95+0.05*h,1.0,sin(3.0*a+iGlobalTime)); 25 | 26 | vec3 bcol = vec3(0.9+0.1*q.y,1.0,0.9-0.1*q.y); 27 | bcol *= 1.0 - 0.5*r; 28 | h = 0.1 + h; 29 | vec3 col = mix( bcol, 1.2*vec3(0.6*h,0.2+0.5*h,0.0), f ); 30 | 31 | fragColor = vec4( col, 1.0 ); 32 | } 33 | 34 | void main() 35 | { 36 | vec4 color = vec4(0.0,0.0,0.0,1.0); 37 | mainImage( color, gl_FragCoord.xy ); 38 | color.w = 1.0; 39 | gl_FragColor = color; 40 | } 41 | -------------------------------------------------------------------------------- /sample/glsl/assets/Fires.glsl: -------------------------------------------------------------------------------- 1 | // 2 | uniform float time; 3 | uniform vec2 mouse; 4 | uniform vec2 resolution; 5 | 6 | float iGlobalTime = time; 7 | vec4 iMouse = vec4(mouse, 0.0, 0.0); 8 | vec2 iResolution = resolution; 9 | 10 | ////////////////////// 11 | // Fire Flame shader 12 | 13 | // procedural noise from IQ 14 | vec2 hash( vec2 p ) 15 | { 16 | p = vec2( dot(p,vec2(127.1,311.7)), 17 | dot(p,vec2(269.5,183.3)) ); 18 | return -1.0 + 2.0*fract(sin(p)*43758.5453123); 19 | } 20 | 21 | float noise( in vec2 p ) 22 | { 23 | const float K1 = 0.366025404; // (sqrt(3)-1)/2; 24 | const float K2 = 0.211324865; // (3-sqrt(3))/6; 25 | 26 | vec2 i = floor( p + (p.x+p.y)*K1 ); 27 | 28 | vec2 a = p - i + (i.x+i.y)*K2; 29 | vec2 o = (a.x>a.y) ? vec2(1.0,0.0) : vec2(0.0,1.0); 30 | vec2 b = a - o + K2; 31 | vec2 c = a - 1.0 + 2.0*K2; 32 | 33 | vec3 h = max( 0.5-vec3(dot(a,a), dot(b,b), dot(c,c) ), 0.0 ); 34 | 35 | vec3 n = h*h*h*h*vec3( dot(a,hash(i+0.0)), dot(b,hash(i+o)), dot(c,hash(i+1.0))); 36 | 37 | return dot( n, vec3(70.0) ); 38 | } 39 | 40 | float fbm(vec2 uv) 41 | { 42 | float f; 43 | mat2 m = mat2( 1.6, 1.2, -1.2, 1.6 ); 44 | f = 0.5000*noise( uv ); uv = m*uv; 45 | f += 0.2500*noise( uv ); uv = m*uv; 46 | f += 0.1250*noise( uv ); uv = m*uv; 47 | f += 0.0625*noise( uv ); uv = m*uv; 48 | f = 0.5 + 0.5*f; 49 | return f; 50 | } 51 | 52 | // no defines, standard redish flames 53 | //#define BLUE_FLAME 54 | //#define GREEN_FLAME 55 | 56 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 57 | { 58 | vec2 uv = fragCoord.xy / iResolution.xy; 59 | vec2 q = uv; 60 | q.x *= 5.; 61 | q.y *= 2.; 62 | float strength = floor(q.x+1.); 63 | float T3 = max(3.,1.25*strength)*iGlobalTime; 64 | q.x = mod(q.x,1.)-0.5; 65 | q.y -= 0.25; 66 | float n = fbm(strength*q - vec2(0,T3)); 67 | float c = 1. - 16. * pow( max( 0., length(q*vec2(1.8+q.y*1.5,.75) ) - n * max( 0., q.y+.25 ) ),1.2 ); 68 | // float c1 = n * c * (1.5-pow(1.25*uv.y,4.)); 69 | float c1 = n * c * (1.5-pow(2.50*uv.y,4.)); 70 | c1=clamp(c1,0.,1.); 71 | 72 | vec3 col = vec3(1.5*c1, 1.5*c1*c1*c1, c1*c1*c1*c1*c1*c1); 73 | 74 | #ifdef BLUE_FLAME 75 | col = col.zyx; 76 | #endif 77 | #ifdef GREEN_FLAME 78 | col = 0.85*col.yxz; 79 | #endif 80 | 81 | float a = c * (1.-pow(uv.y,3.)); 82 | fragColor = vec4( mix(vec3(0.),col,a), 1.0); 83 | } 84 | 85 | void main() 86 | { 87 | vec4 color = vec4(0.0,0.0,0.0,1.0); 88 | mainImage( color, gl_FragCoord.xy ); 89 | color.w = 1.0; 90 | gl_FragColor = color; 91 | } 92 | -------------------------------------------------------------------------------- /sample/glsl/assets/HypnoSwirl.glsl: -------------------------------------------------------------------------------- 1 | // 2 | uniform float time; 3 | uniform vec2 mouse; 4 | uniform vec2 resolution; 5 | 6 | float iGlobalTime = time; 7 | vec4 iMouse = vec4(mouse, 0.0, 0.0); 8 | vec2 iResolution = resolution; 9 | 10 | #define halfPhase 3.5 11 | #define speed_modifier 1.5 12 | 13 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) { 14 | 15 | float activeTime = iGlobalTime * speed_modifier; 16 | vec3 col; 17 | float timeMorph = 0.0; 18 | 19 | #ifdef IS_IOS 20 | vec2 p = -1.0 + 2.0 * fragCoord.xy; //iOS Dynamic AR App support 21 | #else 22 | vec2 p = -1.0 + 2.0 * fragCoord.xy / iResolution.xy; 23 | #endif 24 | 25 | p *= 7.0; 26 | 27 | float a = atan(p.y,p.x); 28 | float r = sqrt(dot(p,p)); 29 | 30 | if(mod(activeTime, 2.0 * halfPhase) < halfPhase) 31 | timeMorph = mod(activeTime, halfPhase); 32 | else 33 | timeMorph = (halfPhase - mod(activeTime, halfPhase)); 34 | 35 | timeMorph = 2.0*timeMorph + 1.0; 36 | 37 | float w = 0.25 + 3.0*(sin(activeTime + 1.0*r)+ 3.0*cos(activeTime + 5.0*a)/timeMorph); 38 | float x = 0.8 + 3.0*(sin(activeTime + 1.0*r)+ 3.0*cos(activeTime + 5.0*a)/timeMorph); 39 | 40 | col = vec3(0.1,0.2,0.82)*1.1; 41 | 42 | fragColor = vec4(col*w*x,1.0); 43 | } 44 | 45 | void main() 46 | { 47 | vec4 color = vec4(0.0,0.0,0.0,1.0); 48 | mainImage( color, gl_FragCoord.xy ); 49 | color.w = 1.0; 50 | gl_FragColor = color; 51 | } 52 | -------------------------------------------------------------------------------- /sample/glsl/assets/Simplicity.glsl: -------------------------------------------------------------------------------- 1 | uniform float time; 2 | uniform vec2 mouse; 3 | uniform vec2 resolution; 4 | 5 | float iGlobalTime = time; 6 | vec4 iMouse = vec4(mouse, 0.0, 0.0); 7 | vec2 iResolution = resolution; 8 | 9 | // http://www.fractalforums.com/new-theories-and-research/very-simple-formula-for-fractal-patterns/ 10 | float field(in vec3 p) { 11 | float strength = 7. + .03 * log(1.e-6 + fract(sin(iGlobalTime) * 4373.11)); 12 | float accum = 0.; 13 | float prev = 0.; 14 | float tw = 0.; 15 | for (int i = 0; i < 32; ++i) { 16 | float mag = dot(p, p); 17 | p = abs(p) / mag + vec3(-.5, -.4, -1.5); 18 | float w = exp(-float(i) / 7.); 19 | accum += w * exp(-strength * pow(abs(mag - prev), 2.3)); 20 | tw += w; 21 | prev = mag; 22 | } 23 | return max(0., 5. * accum / tw - .7); 24 | } 25 | 26 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) { 27 | vec2 uv = 2. * fragCoord.xy / iResolution.xy - 1.; 28 | vec2 uvs = uv * iResolution.xy / max(iResolution.x, iResolution.y); 29 | vec3 p = vec3(uvs / 4., 0) + vec3(1., -1.3, 0.); 30 | p += .2 * vec3(sin(iGlobalTime / 16.), sin(iGlobalTime / 12.), sin(iGlobalTime / 128.)); 31 | float t = field(p); 32 | float v = (1. - exp((abs(uv.x) - 1.) * 6.)) * (1. - exp((abs(uv.y) - 1.) * 6.)); 33 | fragColor = mix(.4, 1., v) * vec4(1.8 * t * t * t, 1.4 * t * t, t, 1.0); 34 | } 35 | 36 | void main() 37 | { 38 | vec4 color = vec4(0.0,0.0,0.0,1.0); 39 | mainImage( color, gl_FragCoord.xy ); 40 | color.w = 1.0; 41 | gl_FragColor = color; 42 | } 43 | -------------------------------------------------------------------------------- /sample/glsl/assets/TotalNoob.glsl: -------------------------------------------------------------------------------- 1 | uniform float time; 2 | uniform vec2 mouse; 3 | uniform vec2 resolution; 4 | 5 | float iGlobalTime = time; 6 | vec4 iMouse = vec4(mouse, 0.0, 0.0); 7 | vec2 iResolution = resolution; 8 | 9 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 10 | { 11 | vec2 p = (2.0*fragCoord.xy-iResolution.xy)/iResolution.y; 12 | float tau = 3.1415926535*2.0; 13 | float a = atan(p.x,p.y); 14 | float r = length(p)*0.75; 15 | vec2 uv = vec2(a/tau,r); 16 | 17 | //get the color 18 | float xCol = (uv.x - (iGlobalTime / 3.0)) * 3.0; 19 | xCol = mod(xCol, 3.0); 20 | vec3 horColour = vec3(0.25, 0.25, 0.25); 21 | 22 | if (xCol < 1.0) { 23 | 24 | horColour.r += 1.0 - xCol; 25 | horColour.g += xCol; 26 | } 27 | else if (xCol < 2.0) { 28 | 29 | xCol -= 1.0; 30 | horColour.g += 1.0 - xCol; 31 | horColour.b += xCol; 32 | } 33 | else { 34 | 35 | xCol -= 2.0; 36 | horColour.b += 1.0 - xCol; 37 | horColour.r += xCol; 38 | } 39 | 40 | // draw color beam 41 | uv = (2.0 * uv) - 1.0; 42 | float beamWidth = (0.7+0.5*cos(uv.x*10.0*tau*0.15*clamp(floor(5.0 + 10.0*cos(iGlobalTime)), 0.0, 10.0))) * abs(1.0 / (30.0 * uv.y)); 43 | vec3 horBeam = vec3(beamWidth); 44 | fragColor = vec4((( horBeam) * horColour), 1.0); 45 | } 46 | 47 | void main() 48 | { 49 | vec4 color = vec4(0.0,0.0,0.0,1.0); 50 | mainImage( color, gl_FragCoord.xy ); 51 | color.w = 1.0; 52 | gl_FragColor = color; 53 | } 54 | -------------------------------------------------------------------------------- /sample/glsl/assets/blue_pattern.glsl: -------------------------------------------------------------------------------- 1 | // @paulofalcao 2 | // 3 | // Blue Pattern 4 | // 5 | // A old shader i had lying around 6 | // Although it's really simple, I like the effect :) 7 | 8 | #ifdef GL_ES 9 | precision highp float; 10 | #endif 11 | 12 | uniform float time; 13 | uniform vec2 resolution; 14 | 15 | void main() 16 | { 17 | vec2 u=(gl_FragCoord.xy/resolution.x)*2.0-vec2(1.0,resolution.y/resolution.x); 18 | float t=time*0.5; 19 | 20 | float tt=sin(t/8.0)*64.0; 21 | float x=u.x*tt+sin(t*2.1)*4.0; 22 | float y=u.y*tt+cos(t*2.3)*4.0; 23 | float c=sin(x)+sin(y); 24 | float zoom=sin(t); 25 | x=x*zoom*2.0+sin(t*1.1); 26 | y=y*zoom*2.0+cos(t*1.3); 27 | float xx=cos(t*0.7)*x-sin(t*0.7)*y; 28 | float yy=sin(t*0.7)*x+cos(t*0.7)*y; 29 | c=(sin(c+sin(xx)+sin(yy))+1.0)*0.5; 30 | gl_FragColor=vec4((1.0-length(u)*2.0)*vec3(c*1.1,c*1.4,c*1.9),1.0); 31 | } 32 | -------------------------------------------------------------------------------- /sample/glsl/assets/circle01.glsl: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision mediump float; 3 | #endif 4 | uniform float time; 5 | uniform vec2 mouse; 6 | uniform vec2 resolution; 7 | void main() 8 | { 9 | vec2 p = (gl_FragCoord.xy-.5*resolution)/min(resolution.x,resolution.y); //-1~+1の座標系 10 | vec2 o = vec2(0,0); 11 | vec3 c = 0.01/(length(p-o))*vec3(1); 12 | gl_FragColor = vec4(c,1); 13 | } 14 | -------------------------------------------------------------------------------- /sample/glsl/assets/circle02.glsl: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision mediump float; 3 | #endif 4 | uniform float time; 5 | uniform vec2 mouse; 6 | uniform vec2 resolution; 7 | void main() 8 | { 9 | vec2 p = (gl_FragCoord.xy-.5*resolution)/min(resolution.x,resolution.y); //-1~+1の座標系 10 | vec3 c = vec3(0); 11 | for (int i=0; i<20; i++) { 12 | float x = .5*cos(2.*3.14*float(i)/20.); 13 | float y = .5*sin(2.*3.14*float(i)/20.); 14 | vec2 o = vec2(x,y); 15 | c += 0.01/(length(p-o))*vec3(1); 16 | } 17 | gl_FragColor = vec4(c,1); 18 | } 19 | -------------------------------------------------------------------------------- /sample/glsl/assets/circle03.glsl: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision mediump float; 3 | #endif 4 | uniform float time; 5 | uniform vec2 mouse; 6 | uniform vec2 resolution; 7 | void main() 8 | { 9 | vec2 p = (gl_FragCoord.xy-.5*resolution)/min(resolution.x,resolution.y); //-1~+1の座標系 10 | vec3 c = vec3(0); 11 | for (int i=0; i<20; i++) { 12 | float t = 2.*3.14*float(i)/20. * fract(time*0.5); 13 | float x = cos(t); 14 | float y = sin(t); 15 | vec2 o = .5*vec2(x,y); 16 | c += 0.01/(length(p-o))*vec3(1); 17 | } 18 | gl_FragColor = vec4(c,1); 19 | } 20 | -------------------------------------------------------------------------------- /sample/glsl/assets/circle04.glsl: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision mediump float; 3 | #endif 4 | uniform float time; 5 | uniform vec2 mouse; 6 | uniform vec2 resolution; 7 | void main() 8 | { 9 | vec2 p = (gl_FragCoord.xy-.5*resolution)/min(resolution.x,resolution.y); //-1~+1の座標系 10 | vec3 c = vec3(0); 11 | for (int i=0; i<20; i++) { 12 | float t = 2.*3.14*float(i)/20. * fract(time*0.5); 13 | float x = cos(t); 14 | float y = sin(2.*t); 15 | vec2 o = .5*vec2(x,y); 16 | c += 0.01/(length(p-o))*vec3(1); 17 | } 18 | gl_FragColor = vec4(c,1); 19 | } 20 | -------------------------------------------------------------------------------- /sample/glsl/assets/flower.glsl: -------------------------------------------------------------------------------- 1 | // first flower 2 | 3 | #ifdef GL_ES 4 | precision mediump float; 5 | #endif 6 | 7 | uniform float time; 8 | uniform vec2 mouse; 9 | uniform vec2 resolution; 10 | 11 | // My first circle deformation Mahmud Yuldashev mahmud9935@gmail.com 12 | 13 | const vec3 bgColor=vec3(0.9, 0.1, 0.05); 14 | 15 | void main( void ) 16 | { 17 | vec2 p = gl_FragCoord.xy/resolution.xy -0.5; 18 | p.x *= resolution.x/resolution.y; 19 | 20 | // deformation of radius 21 | float time = time+length(p*16.); 22 | float r=.2*(1.+sin(time))*pow(cos(time-atan(p.x,p.y)*2.), 2.); 23 | 24 | // p distance - radius 25 | float s = length(p) - r; 26 | 27 | // step 28 | vec3 col = bgColor / smoothstep(0.1, 1.0, pow(s,0.3)); 29 | col = col * 2.0 * mouse.x; 30 | gl_FragColor = vec4( col, 1.0 ); 31 | } 32 | -------------------------------------------------------------------------------- /sample/glsl/assets/fly.glsl: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision highp float; 3 | #endif 4 | #extension GL_OES_standard_derivatives : enable 5 | 6 | uniform float time; 7 | uniform vec2 mouse; 8 | uniform vec2 resolution; 9 | 10 | float iGlobalTime=time; 11 | //Somewhere in 1993 by nimitz (twitter: @stormoid) // Compiled for glslsanbox By Gigatron ; HUD removed ! 12 | 13 | #define PALETTE 6.8 14 | 15 | //3 to 5 works best 16 | #define TERRAIN_COMPLEXITY 4. 17 | #define ITR 60 18 | #define FAR 700. 19 | #define time mod(iGlobalTime,500.) 20 | 21 | mat2 mm2(in float a) 22 | { 23 | float c = cos(a), s = sin(a); 24 | return mat2(c,-s,s,c); 25 | } 26 | float smoothfloor(const in float x, const in float w) 27 | { 28 | return floor(x)+smoothstep(w, 1.-w,fract(x)); 29 | } 30 | 31 | vec3 enpos() 32 | { 33 | return vec3(sin(time)*100.+50.,sin(time)*30.+30.,300.+sin(time*.9+sin(time*0.88+0.2))*100.); 34 | } 35 | 36 | 37 | float tri(in float x) 38 | { 39 | return abs(fract(x)-0.5); 40 | } 41 | 42 | mat2 m2 = mat2( 0.80, 0.60, -0.60, 0.80 ); 43 | float tnoise(in vec2 p) 44 | { 45 | p*=.008; 46 | float z=2.; 47 | float rz = 0.; 48 | for (float i= 1.; i < TERRAIN_COMPLEXITY; i++ ) { 49 | rz+= tri(p.x+tri(p.y*1.))/z; 50 | z = z*2.; 51 | p = p*1.8; 52 | p*= m2; 53 | } 54 | return rz*9.; 55 | } 56 | 57 | float oct(in vec3 p) 58 | { 59 | return dot(vec3(0.5773),abs(p)); 60 | } 61 | vec2 ou( vec2 d1, vec2 d2 ) 62 | { 63 | return (d1.xFAR ) { 96 | break; 97 | } 98 | d += h; 99 | vec2 res = map(ro+rd*d); 100 | h = res.x*1.4; 101 | c = res.y; 102 | } 103 | return vec2(d,c); 104 | } 105 | 106 | vec3 normal(const in vec3 p) 107 | { 108 | vec2 e = vec2(-1., 1.)*.1; 109 | return normalize(e.yxx*map(p + e.yxx).x + 110 | e.xxy*map(p + e.xxy).x + 111 | e.xyx*map(p + e.xyx).x + 112 | e.yyy*map(p + e.yyy).x ); 113 | } 114 | 115 | void mainImage( out vec4 fragColor, in vec2 fragCoord ) 116 | { 117 | vec2 p = fragCoord.xy/resolution.xy-0.5; 118 | vec2 bp = p+0.5; 119 | p.x*=resolution.x/resolution.y; 120 | vec2 um = vec2(0); 121 | um.x = 0.5+(smoothstep(-2.,2.,sin(time*.7-0.1))-0.5)*.1; 122 | um.y = sin(time+1.)*0.02; 123 | 124 | //camera 125 | vec3 ro = vec3((smoothstep(-2., 2., sin(time*0.7+1.57))-0.5)*50., sin(time)*5.-1., time*50.); 126 | um.x *= 3.; 127 | vec3 eye = normalize(vec3(cos(um.x),um.y*5.,sin(um.x))); 128 | vec3 right = normalize(vec3(cos(um.x+1.5708),0.,sin(um.x+1.5708))); 129 | mat2 ori = mm2( smoothstep(-.5,.5,sin(time*0.7+0.78))-.5 + smoothfloor(time*0.04,.45)*6.28 ); 130 | right.xy *= ori; 131 | vec3 up = normalize(cross(right,eye)); 132 | vec3 rd=normalize((p.x*right+p.y*up)*.75+eye); 133 | 134 | vec3 bg = sin(vec3(0.35,0.4,0.48)*11.3*PALETTE)*0.5+.5; 135 | vec3 col = bg*floor(-rd.y*50.+6.)*0.06; 136 | 137 | //march 138 | vec2 rz = march(ro,rd); 139 | if ( rz.x < FAR ) { 140 | vec3 pos = ro+rz.x*rd; 141 | vec3 nor = normal( pos ); 142 | vec3 ligt = normalize(vec3(-.7,0.2, 0.1)); 143 | float dif = clamp(dot(nor, ligt), 0., 1.); 144 | float fre = pow(clamp(1. + dot(nor, rd), 0., 1.), 2.); 145 | if (rz.y == 1.) { 146 | float mx = abs(pos.x*.1)-10.; 147 | mx = smoothstep(-20.,10.,mx); 148 | col = mix(vec3(0.,0.37,0),vec3(0.2,.17,0.15),mx); 149 | } else { 150 | col = sin(vec3(0.35,0.4,0.48)*rz.y*PALETTE)*0.5+.55; 151 | } 152 | col = col*dif + col*0.4 + .3*fre*col; 153 | } 154 | 155 | fragColor = vec4( col, 1.0 ); 156 | } 157 | 158 | void main() 159 | { 160 | vec4 color = vec4(0.0,0.0,0.0,1.0); 161 | mainImage( color, gl_FragCoord.xy ); 162 | color.w = 1.0; 163 | gl_FragColor = color; 164 | } 165 | -------------------------------------------------------------------------------- /sample/glsl/assets/game.glsl: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision mediump float; 3 | #endif 4 | 5 | uniform float time; 6 | uniform vec2 mouse; 7 | uniform vec2 resolution; 8 | 9 | #define SCREEN_W 0.7 10 | #define SCROLL_SPEED 0.1 11 | 12 | vec2 p; 13 | vec2 myfighter_pos = mouse.xy - vec2(0.5, 0.5); 14 | 15 | 16 | float rand(vec2 co) 17 | { 18 | return fract(sin(dot(co.xy ,vec2(12.9898, 78.233))) * 43758.5453); 19 | } 20 | 21 | vec3 background() 22 | { 23 | float interval = 0.1; 24 | float thick = 0.005; 25 | 26 | if (mod(p.y + time * SCROLL_SPEED, interval) < thick || mod(p.x, interval) < thick) { 27 | return vec3(0, 0.2, 0.4); 28 | } 29 | return vec3(0, 0, 0); 30 | } 31 | 32 | vec2 get_boss_pos(float offset) 33 | { 34 | float x = sin(time - offset) * 0.2; 35 | 36 | return vec2(x, 0.35); 37 | } 38 | 39 | vec3 bullet(vec2 v, float t) 40 | { 41 | vec2 pos = get_boss_pos(t) + v * t; 42 | 43 | if (length(p - pos) < 0.008) { 44 | return vec3(1, 1, 1); 45 | } 46 | if (length(p - pos) < 0.01) { 47 | return vec3(1, 0.8, 0.3); 48 | } 49 | return vec3(0); 50 | } 51 | 52 | vec3 myfighter(vec2 pos) 53 | { 54 | float radius = 0.03; 55 | 56 | float dx = pos.x - p.x; 57 | float dy = pos.y - p.y; 58 | 59 | int px = int(floor(abs(dx) / 0.02)); 60 | int py = int(floor(dy / 0.02)); 61 | 62 | bool pixel = false; 63 | 64 | if (px == 0) { 65 | if (py >= -1 && py <= 1) { 66 | pixel = true; 67 | } 68 | } 69 | if (px == 1) { 70 | if (py >= 1 && py <= 2) { 71 | pixel = true; 72 | } 73 | } 74 | 75 | if (pixel) { 76 | return vec3(1, 1, 1); 77 | } 78 | return vec3(0); 79 | } 80 | 81 | vec3 laser(vec2 pos) 82 | { 83 | vec2 boss_pos = get_boss_pos(0.0); 84 | 85 | vec3 c = vec3(0); 86 | 87 | float a = 0.001 + rand( vec2(time) ) * 0.002; 88 | 89 | float d = abs(p.x - pos.x); 90 | float n = (a / d); 91 | 92 | if (p.y > pos.y) { 93 | c = vec3(n * 2.0, n * 2.0, n * 5.0); 94 | } 95 | 96 | if (abs(p.x - boss_pos.x) < 0.08) { 97 | if (p.y > 0.3) { 98 | c = vec3(0); 99 | } 100 | } 101 | return c; 102 | } 103 | 104 | vec3 boss() 105 | { 106 | vec2 pos = get_boss_pos(0.0); 107 | 108 | bool pixel = false; 109 | 110 | float dx = pos.x - p.x; 111 | float dy = pos.y - p.y; 112 | 113 | int px = int(floor(abs(dx) / 0.02)); 114 | int py = int(floor(dy / 0.02)); 115 | 116 | if (px >= -5 && px <= 5) { 117 | if (py >= -5 && py <= 3) { 118 | if (rand(vec2(px, py)) > 0.5) { 119 | pixel = true; 120 | } 121 | } 122 | } 123 | 124 | bool collision = false; 125 | if ( 126 | abs(pos.x - myfighter_pos.x) < .1 127 | && pos.y > myfighter_pos.y 128 | ) { 129 | collision = true; 130 | } 131 | 132 | vec3 hit_mark = collision ? 133 | vec3(rand(vec2(time)) * 0.05 / length(vec2(myfighter_pos.x, pos.y-0.05) - p)) 134 | : vec3(0); 135 | if (pixel) { 136 | return (collision? vec3(rand(vec2(time))) : vec3(0)) + vec3(1, 0.5, 0); 137 | } 138 | return vec3(0) + hit_mark; 139 | } 140 | 141 | void main() 142 | { 143 | p = (gl_FragCoord.xy - resolution * 0.5) / resolution.y; 144 | 145 | if (abs(p.x) > SCREEN_W / 2.0) { 146 | discard; 147 | } 148 | 149 | vec3 c = background(); 150 | 151 | c += boss(); 152 | 153 | for (int i = -4; i <= 2; i++) { 154 | float t = fract(time * 0.5 + float(i) * 0.03); 155 | vec2 v = normalize(vec2(float(i) * 0.1, -1.)); 156 | c += bullet(v, t); 157 | } 158 | 159 | for (int i = -2; i <= 4; i++) { 160 | float t = fract(time * 0.5 + 0.5 + float(i) * -0.03); 161 | vec2 v = normalize(vec2(float(i) * 0.1, -1.)); 162 | c += bullet(v, t); 163 | } 164 | 165 | c += myfighter(myfighter_pos); 166 | c += laser(myfighter_pos); 167 | 168 | gl_FragColor = vec4(c, 1); 169 | } 170 | -------------------------------------------------------------------------------- /sample/glsl/assets/gradient.glsl: -------------------------------------------------------------------------------- 1 | // グラディーション 2 | #version 120 3 | uniform vec2 resolution; 4 | uniform float time; 5 | void main() 6 | { 7 | vec2 pos = (gl_FragCoord.xy*2.0 -resolution) / resolution.y; 8 | gl_FragColor = vec4(pos, 0.0, 1.0); 9 | } 10 | -------------------------------------------------------------------------------- /sample/glsl/assets/invader.glsl: -------------------------------------------------------------------------------- 1 | // Created by sebastien durand - 2015 - License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License 2 | 3 | //precision mediump float; 4 | 5 | 6 | //// //// 7 | //// //// 8 | //// //// 9 | //// //// 10 | uniform float time; uniform 11 | vec2 resolution; void main(){ 12 | vec2 t = vec2(time,2),v =cos(t), 13 | d; float k=25.,w=length (d=///// 14 | gl_FragCoord.xy/resolution.y-.9-v);int y=int 15 | (mod(k/w+k*t,9.));gl_FragColor=exp(-k*abs(w+ 16 | v.x) )+cos(vec4(y,d,1))*w*w*floor (mod 17 | ((y> 3?35552534e8:56869384.)/exp2( vec4 18 | (y*7 +int (abs (mod 19 | (k*( atan (d.x ,d.y 20 | )+v),13. )-6.)))) 21 | ,2. ));} //////// 22 | 23 | -------------------------------------------------------------------------------- /sample/glsl/assets/orb01.glsl: -------------------------------------------------------------------------------- 1 | //precision mediump float; 2 | uniform float time; 3 | uniform vec2 resolution; 4 | 5 | void main() 6 | { 7 | vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); 8 | float l = 0.1 * abs(sin(time)) / length(p); 9 | gl_FragColor = vec4(vec3(l), 1.0); 10 | } 11 | -------------------------------------------------------------------------------- /sample/glsl/assets/orb02.glsl: -------------------------------------------------------------------------------- 1 | //precision mediump float; 2 | uniform float time; 3 | uniform vec2 resolution; 4 | 5 | void main() 6 | { 7 | vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); 8 | p += vec2(cos(time), sin(time)) * 0.5; 9 | float l = 0.1 / length(p); 10 | gl_FragColor = vec4(vec3(l), 1.0); 11 | } 12 | -------------------------------------------------------------------------------- /sample/glsl/assets/orb03.glsl: -------------------------------------------------------------------------------- 1 | //precision mediump float; 2 | uniform float time; 3 | uniform vec2 resolution; 4 | 5 | void main() 6 | { 7 | vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); 8 | p += vec2(cos(time * 5.0), sin(time)) * 0.5; 9 | float l = 0.1 / length(p); 10 | gl_FragColor = vec4(vec3(l), 1.0); 11 | } 12 | -------------------------------------------------------------------------------- /sample/glsl/assets/orb04.glsl: -------------------------------------------------------------------------------- 1 | //precision mediump float; 2 | uniform float time; 3 | uniform vec2 resolution; 4 | 5 | void main() 6 | { 7 | vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); 8 | vec3 destColor = vec3(0.0); 9 | for (float i = 0.0; i < 5.0; i++) { 10 | float j = i + 1.0; 11 | vec2 q = p + vec2(cos(time * j), sin(time * j)) * 0.5; 12 | destColor += 0.05 / length(q); 13 | } 14 | gl_FragColor = vec4(destColor, 1.0); 15 | } 16 | -------------------------------------------------------------------------------- /sample/glsl/assets/orb05.glsl: -------------------------------------------------------------------------------- 1 | //precision mediump float; 2 | uniform float time; 3 | uniform vec2 resolution; 4 | 5 | void main() 6 | { 7 | vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); 8 | float f = 0.01 / abs(length(p) - 0.5); 9 | gl_FragColor = vec4(vec3(f), 1.0); 10 | } 11 | -------------------------------------------------------------------------------- /sample/glsl/assets/orb06.glsl: -------------------------------------------------------------------------------- 1 | //precision mediump float; 2 | uniform float time; 3 | uniform vec2 resolution; 4 | 5 | void main() 6 | { 7 | vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); 8 | vec3 destColor = vec3(1.0, 0.3, 0.7); 9 | float f = 0.0; 10 | for (float i = 0.0; i < 10.0; i++) { 11 | float s = sin(time + i * 0.628318) * 0.5; // 3.14/5 -> 36 (360/10) 12 | float c = cos(time + i * 0.628318) * 0.5; 13 | f += 0.0025 / abs(length(p + vec2(c, s)) - 0.5); 14 | } 15 | gl_FragColor = vec4(vec3(destColor * f), 1.0); 16 | } 17 | -------------------------------------------------------------------------------- /sample/glsl/assets/orb07.glsl: -------------------------------------------------------------------------------- 1 | //precision mediump float; 2 | uniform float time; 3 | uniform vec2 resolution; 4 | 5 | void main() 6 | { 7 | vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); 8 | float f = p.x * p.y; 9 | gl_FragColor = vec4(vec3(f), 1.0); 10 | } 11 | -------------------------------------------------------------------------------- /sample/glsl/assets/orb08.glsl: -------------------------------------------------------------------------------- 1 | //precision mediump float; 2 | uniform float time; 3 | uniform vec2 resolution; 4 | 5 | void main() 6 | { 7 | vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); 8 | float f = abs(p.x) * abs(p.y); 9 | gl_FragColor = vec4(vec3(f), 1.0); 10 | } 11 | -------------------------------------------------------------------------------- /sample/glsl/assets/orb09.glsl: -------------------------------------------------------------------------------- 1 | //precision mediump float; 2 | uniform float time; 3 | uniform vec2 resolution; 4 | 5 | void main() 6 | { 7 | vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); 8 | float f = 0.001 / (abs(p.x) * abs(p.y)); 9 | gl_FragColor = vec4(vec3(f), 1.0); 10 | } 11 | -------------------------------------------------------------------------------- /sample/glsl/assets/orb10.glsl: -------------------------------------------------------------------------------- 1 | //precision mediump float; 2 | uniform float time; 3 | uniform vec2 resolution; 4 | 5 | void main() 6 | { 7 | vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); 8 | float f = 0.2 / abs(p.x) * abs(p.y); 9 | gl_FragColor = vec4(vec3(f), 1.0); 10 | } 11 | -------------------------------------------------------------------------------- /sample/glsl/assets/orb11.glsl: -------------------------------------------------------------------------------- 1 | //precision mediump float; 2 | uniform float time; 3 | uniform vec2 resolution; 4 | 5 | void main() 6 | { 7 | vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); 8 | vec2 q = mod(p, 0.2) - 0.1; 9 | float f = 0.2 / abs(q.x) * abs(q.y); 10 | gl_FragColor = vec4(vec3(f), 1.0); 11 | } 12 | -------------------------------------------------------------------------------- /sample/glsl/assets/orb12.glsl: -------------------------------------------------------------------------------- 1 | //precision mediump float; 2 | uniform float time; 3 | uniform vec2 resolution; 4 | 5 | void main() 6 | { 7 | vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); 8 | vec2 q = mod(p, 0.2) - 0.1; 9 | float s = sin(time); 10 | float c = cos(time); 11 | q *= mat2(c, s, -s, c); 12 | float v = 0.1 / abs(q.y) * abs(q.x); 13 | float r = v * abs(sin(time * 6.0) + 1.5); 14 | float g = v * abs(sin(time * 4.5) + 1.5); 15 | float b = v * abs(sin(time * 3.0) + 1.5); 16 | gl_FragColor = vec4(r, g, b, 1.0); 17 | } 18 | -------------------------------------------------------------------------------- /sample/glsl/assets/orb13.glsl: -------------------------------------------------------------------------------- 1 | //precision mediump float; 2 | uniform float time; 3 | uniform vec2 resolution; 4 | 5 | void main() 6 | { 7 | vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); 8 | 9 | float s = sin(time); // サインを求める 10 | float c = cos(time); // コサインを求める 11 | mat2 m = mat2(c, s, -s, c); // 行列に回転用の値をセット 12 | p *= m; // 行列をベクトルに掛け合わせる 13 | 14 | vec2 q = vec2(p.x - 1.0, p.y); 15 | float f = 0.1 / length(q); 16 | gl_FragColor = vec4(vec3(f), 1.0); 17 | } 18 | -------------------------------------------------------------------------------- /sample/glsl/assets/orb14.glsl: -------------------------------------------------------------------------------- 1 | //precision mediump float; 2 | uniform float time; 3 | uniform vec2 resolution; 4 | 5 | #define white vec3(1.0) 6 | const vec3 red = vec3(1.0, 0.0, 0.0); 7 | const vec3 green = vec3(0.0, 1.0, 0.0); 8 | const vec3 blue = vec3(0.0, 0.0, 1.0); 9 | 10 | void circle(vec2 p, vec2 offset, float size, vec3 color, inout vec3 i) 11 | { 12 | float l = length(p - offset); 13 | if (l < size) { 14 | i = color; 15 | } 16 | } 17 | 18 | void rect(vec2 p, vec2 offset, float size, vec3 color, inout vec3 i) 19 | { 20 | vec2 q = (p - offset) / size; 21 | if (abs(q.x) < 1.0 && abs(q.y) < 1.0) { 22 | i = color; 23 | } 24 | } 25 | 26 | void ellipse(vec2 p, vec2 offset, vec2 prop, float size, vec3 color, inout vec3 i) 27 | { 28 | vec2 q = (p - offset) / prop; 29 | if (length(q) < size) { 30 | i = color; 31 | } 32 | } 33 | 34 | void main() 35 | { 36 | vec3 destColor = white; 37 | vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); 38 | 39 | circle (p, vec2( 0.0, 0.5), 0.25, red, destColor); 40 | rect (p, vec2( 0.5, -0.5), 0.25, green, destColor); 41 | ellipse(p, vec2(-0.5, -0.5), vec2(0.5, 1.0), 0.25, blue, destColor); 42 | gl_FragColor = vec4(destColor, 1.0); 43 | } 44 | -------------------------------------------------------------------------------- /sample/glsl/assets/orb15.glsl: -------------------------------------------------------------------------------- 1 | //precision mediump float; 2 | uniform float time; 3 | uniform vec2 resolution; 4 | 5 | const float PI = 3.1415926; 6 | const vec3 lightColor = vec3(0.95, 0.95, 0.5); // 背景の後光の色 7 | const vec3 backColor = vec3(0.95, 0.25, 0.25); // 背景の下地の色 8 | 9 | // 背景の後光を描く 10 | void sunrise(vec2 p, inout vec3 i) 11 | { 12 | float f = atan(p.y, p.x) + time; 13 | float fs = sin(f * 10.0); 14 | i = mix(lightColor, backColor, fs); 15 | } 16 | 17 | void main() 18 | { 19 | // 座標を正規化する 20 | vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); 21 | 22 | // 最終的に出力される色 23 | vec3 destColor = vec3(1.0); 24 | 25 | // 背景の後光を描く 26 | sunrise(p, destColor); 27 | 28 | gl_FragColor = vec4(destColor, 1.0); 29 | } 30 | -------------------------------------------------------------------------------- /sample/glsl/assets/orb16.glsl: -------------------------------------------------------------------------------- 1 | // http://webgl.souhonzan.org/entry/?v=0002 2 | //precision mediump float; 3 | uniform float time; 4 | uniform vec2 resolution; 5 | 6 | const float PI = 3.1415926; 7 | const vec3 lightColor = vec3(0.95, 0.95, 0.5); // 背景の後光の色 8 | const vec3 backColor = vec3(0.95, 0.25, 0.25); // 背景の下地の色 9 | const vec3 faceColor = vec3(0.95, 0.75, 0.5); // 顔の色 10 | const vec3 noseColor = vec3(0.95, 0.25, 0.25); // 鼻の色 11 | const vec3 cheekColor = vec3(1.0, 0.55, 0.25); // 頬の色 12 | const vec3 eyesColor = vec3(0.15, 0.05, 0.05); // 目の色 13 | const vec3 highlight = vec3(0.95, 0.95, 0.95); // ハイライトの色 14 | const vec3 lineColor = vec3(0.3, 0.2, 0.2); // ラインの色 15 | 16 | // 円を描く 17 | void circle(vec2 p, vec2 offset, float size, vec3 color, inout vec3 i) 18 | { 19 | float l = length(p - offset); 20 | if (l < size) { 21 | i = color; 22 | } 23 | } 24 | 25 | // 楕円を描く 26 | void ellipse(vec2 p, vec2 offset, vec2 prop, float size, vec3 color, inout vec3 i) 27 | { 28 | vec2 q = (p - offset) / prop; 29 | if (length(q) < size) { 30 | i = color; 31 | } 32 | } 33 | 34 | // 円形にラインを引く 35 | void circleLine(vec2 p, vec2 offset, float iSize, float oSize, vec3 color, inout vec3 i) 36 | { 37 | vec2 q = p - offset; 38 | float l = length(q); 39 | if (l > iSize && l < oSize) { 40 | i = color; 41 | } 42 | } 43 | 44 | // 円形のラインを変形して半円のラインを引く 45 | void arcLine(vec2 p, vec2 offset, float iSize, float oSize, float rad, float height, vec3 color, inout vec3 i) 46 | { 47 | float s = sin(rad); 48 | float c = cos(rad); 49 | vec2 q = (p - offset) * mat2(c, -s, s, c); 50 | float l = length(q); 51 | if (l > iSize && l < oSize && q.y > height) { 52 | i = color; 53 | } 54 | } 55 | 56 | // 正方形を描く 57 | void rect(vec2 p, vec2 offset, float size, vec3 color, inout vec3 i) 58 | { 59 | vec2 q = (p - offset) / size; 60 | if (abs(q.x) < 1.0 && abs(q.y) < 1.0) { 61 | i = color; 62 | } 63 | } 64 | 65 | // 背景の後光を描く 66 | void sunrise(vec2 p, inout vec3 i) 67 | { 68 | float f = atan(p.y, p.x) + time; 69 | float fs = sin(f * 10.0); 70 | i = mix(lightColor, backColor, fs); 71 | } 72 | 73 | void main() 74 | { 75 | // 座標を正規化する 76 | vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); 77 | 78 | // 最終的に出力される色 79 | vec3 destColor = vec3(1.0); 80 | 81 | // 背景の後光を描く 82 | sunrise(p, destColor); 83 | 84 | // おおもとの座標を回転させる 85 | float s = sin(sin(time * 2.0) * 0.75); 86 | float c = cos(sin(time * 2.0)); 87 | vec2 q = p * mat2(c, -s, s, c); 88 | 89 | // 顔のパーツを順番に描いていく 90 | circle(q, vec2(0.0), 0.5, faceColor, destColor); 91 | circle(q, vec2(0.0, -0.05), 0.15, noseColor, destColor); 92 | circle(q, vec2(0.325, -0.05), 0.15, cheekColor, destColor); 93 | circle(q, vec2(-0.325, -0.05), 0.15, cheekColor, destColor); 94 | ellipse(q, vec2(0.15, 0.135), vec2(0.75, 1.0), 0.075, eyesColor, destColor); 95 | ellipse(q, vec2(-0.15, 0.135), vec2(0.75, 1.0), 0.075, eyesColor, destColor); 96 | circleLine(q, vec2(0.0), 0.5, 0.525, lineColor, destColor); 97 | circleLine(q, vec2(0.0, -0.05), 0.15, 0.17, lineColor, destColor); 98 | arcLine(q, vec2(0.325, -0.05), 0.15, 0.17, PI * 1.5, 0.0, lineColor, destColor); 99 | arcLine(q, vec2(-0.325, -0.05), 0.15, 0.17, PI * 0.5, 0.0, lineColor, destColor); 100 | arcLine(q * vec2(1.2, 1.0), vec2(0.19, 0.2), 0.125, 0.145, 0.0, 0.02, lineColor, destColor); 101 | arcLine(q * vec2(1.2, 1.0), vec2(-0.19, 0.2), 0.125, 0.145, 0.0, 0.02, lineColor, destColor); 102 | arcLine(q * vec2(0.9, 1.0), vec2(0.0, -0.15), 0.2, 0.22, PI, 0.055, lineColor, destColor); 103 | rect(q, vec2(-0.025, 0.0), 0.035, highlight, destColor); 104 | rect(q, vec2(-0.35, 0.0), 0.035, highlight, destColor); 105 | rect(q, vec2(0.3, 0.0), 0.035, highlight, destColor); 106 | gl_FragColor = vec4(destColor, 1.0); 107 | } 108 | -------------------------------------------------------------------------------- /sample/glsl/assets/plasma.glsl: -------------------------------------------------------------------------------- 1 | // プラズマ 2 | #version 120 3 | uniform vec2 resolution; 4 | uniform float time; 5 | float plasma(vec2 p) 6 | { 7 | p*=10.0; 8 | return (sin(p.x)*0.25+0.25)+(sin(p.y)*0.25+0.25); 9 | } 10 | void main() 11 | { 12 | vec2 pos = (gl_FragCoord.xy*2.0 -resolution) / resolution.y; 13 | gl_FragColor = vec4(plasma(pos)); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /sample/glsl/assets/plasma2.glsl: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision mediump float; 3 | #endif 4 | 5 | uniform float time; 6 | uniform vec2 mouse; 7 | uniform vec2 resolution; 8 | 9 | void main() 10 | { 11 | vec2 position = ( gl_FragCoord.xy / resolution.xy ) + mouse / 4.0; 12 | 13 | float color = 0.0; 14 | color += sin( position.x * cos( time / 15.0 ) * 80.0 ) + cos( position.y * cos( time / 15.0 ) * 10.0 ); 15 | color += sin( position.y * sin( time / 10.0 ) * 40.0 ) + cos( position.x * sin( time / 25.0 ) * 40.0 ); 16 | color += sin( position.x * sin( time / 5.0 ) * 10.0 ) + sin( position.y * sin( time / 35.0 ) * 80.0 ); 17 | color *= sin( time / 10.0 ) * 0.5; 18 | 19 | gl_FragColor = vec4( vec3( color, color * 0.5, sin( color + time / 3.0 ) * 0.75 ), 1.0 ); 20 | } 21 | -------------------------------------------------------------------------------- /sample/glsl/assets/race.glsl: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision mediump float; 3 | #endif 4 | 5 | uniform float time; 6 | uniform vec2 mouse; 7 | uniform vec2 resolution; 8 | 9 | // unfinished by gigatron ; road sin code from shader toyyy from mr matz; 10 | vec3 road(vec3 pos) 11 | { 12 | vec3 c1 = vec3(0.1,0.9,0.1); 13 | vec3 c2 = vec3(0.1,0.6,0.1); 14 | float a=time; 15 | float k=sin(.2*a); 16 | //pos.x *= 17 | pos.x-=.05*k*k*k*pos.y*pos.y; 18 | 19 | 20 | if (abs(pos.x) < 1.0) { 21 | c1 = vec3(0.9,0.1,0.1); 22 | c2 = vec3(0.9,0.9,0.9); 23 | } 24 | if (abs(pos.x) < .8) { //left and right line 25 | c1 = vec3(0.5,0.5,0.5); 26 | c2 = vec3(0.5,0.5,0.5); 27 | } 28 | if (abs(pos.x) < 0.002) { //middle lines 29 | c1 = vec3(0.5,0.5,0.5); 30 | c2 = vec3(0.9,0.9,0.9); 31 | } 32 | 33 | float t = time * 15.0; //speed of the tesla car*10 34 | 35 | 36 | float v = pow(sin(0.),20.0); 37 | 38 | float rep = fract(pos.y+t); 39 | float blur = dot(pos,pos)*0.005; 40 | vec3 ground = mix(c1,c2,smoothstep(0.25-blur*0.25,0.25+blur*0.25,rep)*smoothstep(0.75+blur*0.25,0.75-blur*0.25,rep)); 41 | 42 | return ground; 43 | } 44 | 45 | vec3 sky(vec2 uv) 46 | { 47 | return mix(vec3(1.0,1.0,1.0),vec3(0.1,0.7,1.0),uv.y); 48 | } 49 | 50 | vec3 car(vec2 uv) 51 | { 52 | if (uv.y > -0.3) { 53 | return vec3(0.); 54 | } 55 | float carpos = (mouse.x * 2.0) - 1.0; 56 | if (abs(uv.x-carpos) < 0.15) { 57 | if (abs(carpos) > 0.4) { 58 | return (vec3(1.,0.,0.)); 59 | } 60 | return vec3(1.); 61 | } 62 | return vec3(0.); 63 | } 64 | 65 | float insidecar(vec3 col) 66 | { 67 | if (length(col) == .0) { 68 | return .0; 69 | } 70 | return 1.; 71 | } 72 | 73 | void main() 74 | { 75 | vec2 res = resolution.xy/resolution.y; 76 | vec2 uv = gl_FragCoord.xy / resolution.y; 77 | uv -= res/2.0; 78 | 79 | vec3 pos = vec3(uv.x/abs(uv.y),1.0/abs(uv.y),step(0.0,uv.y)*2.0-1.0); 80 | 81 | vec3 color = vec3(0.0); 82 | 83 | color = mix(road(pos),sky(uv),step(.0,pos.z)); 84 | 85 | vec3 carcolor = car(uv); 86 | 87 | color = mix(color, carcolor, insidecar(carcolor)); 88 | // color = carcolor; 89 | 90 | gl_FragColor = vec4(color, 1.0 ); 91 | } 92 | -------------------------------------------------------------------------------- /sample/glsl/assets/ray_demo.glsl: -------------------------------------------------------------------------------- 1 | uniform float time; 2 | uniform vec2 mouse; 3 | uniform vec2 resolution; 4 | 5 | float sphere(vec3 ray, vec3 dir, vec3 center, float radius) 6 | { 7 | vec3 rc = ray-center; 8 | float c = dot(rc, rc) - (radius*radius); 9 | float b = dot(dir, rc); 10 | float d = b*b - c; 11 | float t = -b - sqrt(abs(d)); 12 | float st = step(0.0, min(t,d)); 13 | return mix(-1.0, t, st); 14 | } 15 | 16 | vec3 background(float t, vec3 rd) 17 | { 18 | vec3 light = normalize(vec3(sin(t), 0.6, cos(t))); 19 | float sun = max(0.0, dot(rd, light)); 20 | float sky = max(0.0, dot(rd, vec3(0.0, 1.0, 0.0))); 21 | float ground = max(0.0, -dot(rd, vec3(0.0, 1.0, 0.0))); 22 | return 23 | (pow(sun, 256.0)+0.2*pow(sun, 2.0))*vec3(2.0, 1.6, 1.0) + 24 | pow(ground, 0.5)*vec3(0.4, 0.3, 0.2) + 25 | pow(sky, 1.0)*vec3(0.5, 0.6, 0.7); 26 | } 27 | 28 | void main() 29 | { 30 | vec2 uv = (-1.0 + 2.0*gl_FragCoord.xy / resolution.xy) * vec2(resolution.x/resolution.y, 1.0); 31 | vec3 ro = vec3(0.0, 0.0, -3.0); 32 | vec3 rd = normalize(vec3(uv, 1.0)); 33 | vec3 p = vec3(0.0, 0.0, 0.0); 34 | float t = sphere(ro, rd, p, 1.0); 35 | vec3 nml = normalize(p - (ro+rd*t)); 36 | vec3 bgCol = background(time, rd); 37 | rd = reflect(rd, nml); 38 | vec3 col = background(time, rd) * vec3(0.9, 0.8, 1.0); 39 | gl_FragColor = vec4( mix(bgCol, col, step(0.0, t)), 1.0 ); 40 | } 41 | -------------------------------------------------------------------------------- /sample/glsl/assets/rayt01.glsl: -------------------------------------------------------------------------------- 1 | //precision mediump float; 2 | uniform float time; 3 | uniform vec2 resolution; 4 | 5 | struct Ray { 6 | vec3 origin; 7 | vec3 direction; 8 | }; 9 | 10 | struct Sphere { 11 | float radius; 12 | vec3 position; 13 | vec3 color; 14 | }; 15 | 16 | bool intersectSphere(Ray R, Sphere S) 17 | { 18 | vec3 a = R.origin - S.position; 19 | float b = dot(a, R.direction); 20 | float c = dot(a, a) - (S.radius * S.radius); 21 | float d = b * b - c; 22 | if (d > 0.0) { 23 | float t = -b - sqrt(d); 24 | return (t > 0.0); 25 | } 26 | return false; 27 | } 28 | 29 | void main() 30 | { 31 | // fragment position 32 | vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); 33 | 34 | // ray init 35 | Ray ray; 36 | ray.origin = vec3(0.0, 0.0, 5.0); 37 | ray.direction = normalize(vec3(p.x, p.y, -1.0)); 38 | 39 | // sphere init 40 | Sphere sphere; 41 | sphere.radius = 1.0; 42 | sphere.position = vec3(0.0); 43 | sphere.color = vec3(1.0); 44 | 45 | // hit check 46 | vec3 destColor = vec3(0.0); 47 | if (intersectSphere(ray, sphere)) { 48 | destColor = sphere.color; 49 | } 50 | 51 | gl_FragColor = vec4(destColor, 1.0); 52 | } 53 | -------------------------------------------------------------------------------- /sample/glsl/assets/rayt02.glsl: -------------------------------------------------------------------------------- 1 | //precision mediump float; 2 | uniform float time; 3 | uniform vec2 resolution; 4 | 5 | struct Ray { 6 | vec3 origin; 7 | vec3 direction; 8 | }; 9 | 10 | struct Sphere { 11 | float radius; 12 | vec3 position; 13 | vec3 color; 14 | }; 15 | 16 | struct Intersection { 17 | bool hit; 18 | vec3 hitPoint; 19 | vec3 normal; 20 | vec3 color; 21 | }; 22 | 23 | Intersection intersectSphere(Ray R, Sphere S) 24 | { 25 | Intersection i; 26 | vec3 a = R.origin - S.position; 27 | float b = dot(a, R.direction); 28 | float c = dot(a, a) - (S.radius * S.radius); 29 | float d = b * b - c; 30 | if (d > 0.0) { 31 | float t = -b - sqrt(d); 32 | if (t > 0.0) { 33 | i.hit = true; 34 | i.hitPoint = R.origin + R.direction * t; 35 | i.normal = normalize(i.hitPoint - S.position); 36 | float d = clamp(dot(normalize(vec3(1.0)), i.normal), 0.1, 1.0); 37 | i.color = S.color * d; 38 | return i; 39 | } 40 | } 41 | i.hit = false; 42 | i.hitPoint = vec3(0.0); 43 | i.normal = vec3(0.0); 44 | i.color = vec3(0.0); 45 | return i; 46 | } 47 | 48 | void main() 49 | { 50 | // fragment position 51 | vec2 p = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y); 52 | 53 | // ray init 54 | Ray ray; 55 | ray.origin = vec3(0.0, 0.0, 5.0); 56 | ray.direction = normalize(vec3(p.x, p.y, -1.0)); 57 | 58 | // sphere init 59 | Sphere sphere; 60 | sphere.radius = 1.0; 61 | sphere.position = vec3(cos(time), sin(time), cos(time * 3.0)); 62 | sphere.color = vec3(1.0); 63 | 64 | // hit check 65 | Intersection i = intersectSphere(ray, sphere); 66 | gl_FragColor = vec4(i.color, 1.0); 67 | } 68 | -------------------------------------------------------------------------------- /sample/glsl/assets/sample1.glsl: -------------------------------------------------------------------------------- 1 | //precision highp float; 2 | 3 | uniform float time; 4 | uniform vec2 resolution; 5 | 6 | #define TWO_PI 6.283185 7 | #define NUMBALLS 50.0 8 | 9 | float d = -TWO_PI/36.0; 10 | 11 | void main() 12 | { 13 | vec2 p = (2.0*gl_FragCoord.xy - resolution)/min(resolution.x, resolution.y); 14 | //p *= mat2(cos(time), -sin(time), sin(time), cos(time)); 15 | 16 | vec3 c = vec3(0); //ftfy 17 | for (float i = 0.0; i < NUMBALLS; i++) { 18 | float t = TWO_PI * i/NUMBALLS + time; 19 | float x = cos(t); 20 | float y = sin(2.0 * t + d); 21 | vec2 q = 0.8*vec2(x, y); 22 | c += 0.01/distance(p, q) * vec3(0.5 * abs(x), 0, abs(y)); 23 | } 24 | gl_FragColor = vec4(c, 2.0); 25 | } 26 | -------------------------------------------------------------------------------- /sample/glsl/assets/sample10.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | Daily an hour GLSL sketch by @chimanaco 1/30 3 | 4 | References: 5 | http://pixelshaders.com/examples/quasicrystal.html 6 | http://www.atmarkit.co.jp/ait/articles/1211/26/news012_3.html 7 | */ 8 | 9 | #ifdef GL_ES 10 | precision mediump float; 11 | #endif 12 | 13 | uniform float time; 14 | uniform vec2 mouse; 15 | uniform vec2 resolution; 16 | 17 | void main() 18 | { 19 | vec2 position = (gl_FragCoord.xy * 2. -resolution) / resolution.y; 20 | vec2 p = (position - 0.5) * 5.; 21 | float angle = time; 22 | vec2 direction = vec2(cos(angle), sin(angle)); 23 | 24 | float brightness = cos(dot(p * sin(angle * 0.25), direction) + sin(distance(direction, tan(p)))); 25 | gl_FragColor.rgb = vec3(.2, brightness, cos(brightness)); 26 | gl_FragColor.a = 1.; 27 | } 28 | -------------------------------------------------------------------------------- /sample/glsl/assets/sample11.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | Daily an hour GLSL sketch by @chimanaco 3/30 3 | 4 | References: 5 | http://tokyodemofest.jp/2014/7lines/index.html 6 | */ 7 | 8 | #ifdef GL_ES 9 | precision mediump float; 10 | #endif 11 | 12 | uniform vec2 resolution; 13 | uniform float time; 14 | uniform vec2 mouse; 15 | 16 | float PI = 3.1415926535; 17 | 18 | void main() 19 | { 20 | vec2 p=(gl_FragCoord.xy -.5 * resolution)/ min(resolution.x,resolution.y); 21 | vec3 c = vec3(0); 22 | 23 | for (int i = 0; i < 20; i++) { 24 | float t = 2.* PI * float(i) / 20. * fract(time*0.5); 25 | float x = cos(t) * sin(t); 26 | float y = sin(t); 27 | vec2 o = 0.45 * vec2(x,y); 28 | float r = fract(t); 29 | float g = 1.-r; 30 | //float b = 1.-r; 31 | c += 0.005/(length(p-o))*vec3(r,g,1); 32 | } 33 | gl_FragColor = vec4(c,1); 34 | } 35 | -------------------------------------------------------------------------------- /sample/glsl/assets/sample12.glsl: -------------------------------------------------------------------------------- 1 | /* 2 | Daily an hour GLSL sketch by @chimanaco 11/30 3 | */ 4 | 5 | #ifdef GL_ES 6 | precision mediump float; 7 | #endif 8 | 9 | uniform float time; 10 | uniform vec2 resolution; 11 | 12 | vec3 hsv2rgb(vec3 c) 13 | { 14 | vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); 15 | vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); 16 | return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); 17 | } 18 | 19 | void main() 20 | { 21 | vec2 p = ( gl_FragCoord.xy / resolution.xy ) - 0.5; 22 | vec2 direction = vec2(cos(time), sin(time)); 23 | 24 | float sx = 0.15 * sin( 5.0 * p.x - time - length(p)); 25 | float dy = 1.0 / ( 10.0 * abs(p.y - sx )); 26 | vec3 c = hsv2rgb(vec3( ( (p.x + 0.1) * dy) * 0.5 + cos(dot(p, direction)) * 5.0, 0.4, dy)); 27 | gl_FragColor = vec4( c, 1.0 ); 28 | } 29 | -------------------------------------------------------------------------------- /sample/glsl/assets/sample2.glsl: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision mediump float; 3 | #endif 4 | 5 | uniform float time; 6 | uniform vec2 mouse; 7 | uniform vec2 resolution; 8 | 9 | void main() 10 | { 11 | vec2 p = ( gl_FragCoord.xy / resolution.xy ) - 0.5; 12 | p.x = (resolution.x * p.x) / resolution.y; 13 | 14 | vec2 p1 = p * 8.; 15 | vec2 p2 = p1 + vec2( cos(time * 5.), sin(time * 12.) ); 16 | float c = 1. - dot(p1,p2 * sin(time * .25)); 17 | float a = atan( p.x, p.y); 18 | float w = .75 * sin(a * 10.) + .25 * sin(time * 13.); 19 | c += w * (.5 + .5 * sin(time* 6.)); 20 | 21 | gl_FragColor = vec4( c, c * .5 , c * .25, 1. ); 22 | } 23 | -------------------------------------------------------------------------------- /sample/glsl/assets/sample3.glsl: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision mediump float; 3 | #endif 4 | 5 | uniform float time; 6 | uniform vec2 mouse; 7 | uniform vec2 resolution; 8 | 9 | #define PI 3.14159265359 10 | 11 | void main() 12 | { 13 | vec2 position = ( gl_FragCoord.xy / resolution.xy ); 14 | position.x = (position.x - 0.5) * (resolution.x / resolution.y) + 0.5; 15 | position.x = (position.x - 0.5) / (1.1 - 0.2 * position.y) + 0.5; 16 | 17 | position.y -= 0.05 * abs(sin(time*2.0*PI)); 18 | float topleft = step(fract(position.x*4.0), 0.5) * step(fract(position.y*4.0), 0.5); 19 | float bottomright = step(0.5, fract(position.x*4.0)) * step(0.5, fract(position.y*4.0)); 20 | float diamond = 1.0 - mod(floor((position.x+position.y)*4.0) + floor((position.x-position.y)*4.0), 2.0); 21 | 22 | float color = 0.75 + (0.5 + 0.4 * topleft - 0.4 * bottomright) * diamond; 23 | float flash = step(2.5, mod(time, 4.0)) * max(0.0, (1.0 - mod(time*2.0, 1.0)))*diamond; 24 | vec4 finalcolor = mix(vec4(1.0, 0.25, 0.25, 1.0), vec4(0.25, 0.25, 1.0, 1.0), step(4.0, mod(time, 8.0))); 25 | float whiteflash = max(0.0, 1.0 - mod(time, 4.0)*2.0) * step(1.0, time); 26 | 27 | gl_FragColor = mix((finalcolor * color) - vec4(0.25, 0.25, 0.25, 1.0) * flash*0.25, vec4(1.0, 1.0, 1.0, 1.0), whiteflash); 28 | } 29 | -------------------------------------------------------------------------------- /sample/glsl/assets/sample4.glsl: -------------------------------------------------------------------------------- 1 | // By @paulofalcao 2 | // 3 | // Blobs 4 | 5 | #ifdef GL_ES 6 | precision highp float; 7 | #endif 8 | 9 | uniform float time; 10 | uniform vec2 resolution; 11 | 12 | float makePoint(float x,float y,float fx,float fy,float sx,float sy,float t) 13 | { 14 | float xx=x+cos(t*fx*1.1)*sx; 15 | float yy=y+tan(t*fy*0.1)*sy; 16 | return 1.0/sqrt(xx*xx+yy*yy); 17 | } 18 | 19 | void main() 20 | { 21 | vec2 p=(gl_FragCoord.xy/resolution.y)/1.0-vec2(1,sin(resolution.y*resolution.y)/20.0); 22 | 23 | //p=p*1.0; 24 | 25 | float x=p.x; 26 | float y=p.y; 27 | 28 | float a= 29 | makePoint(x ,y,.5,.5,.5,.5,time); 30 | a=a+makePoint(x,y,1.9,2.0,0.4,0.4,time); 31 | a=a+makePoint(x,y,0.8,0.7/time,0.4,0.5,time); 32 | a=a+makePoint(x,y,2.3,0.1,0.6,0.3,time); 33 | a=a+makePoint(x,y,0.8,1.7,0.5,0.4,time); 34 | a=a+makePoint(x,y,0.3,1.0,0.4,0.4,time); 35 | a=a+makePoint(x,y,1.4,1.7,0.4,0.5,time); 36 | a=a+makePoint(x,y,1.3,2.1,0.6,0.3,time); 37 | a=a+makePoint(x,y,1.8,1.7,0.5,0.4,time); 38 | 39 | float b= 40 | makePoint(x,y,1.2,1.9,0.1,0.2,time); 41 | b=b+makePoint(x,y,0.7,2.7,0.4,0.4,time); 42 | b=b+makePoint(x,y,1.4,0.6,0.4,0.5,time); 43 | b=b+makePoint(x,y,2.6,0.4,0.6,0.3,time); 44 | b=b+makePoint(x,y,0.7,1.4,0.5,0.4,time); 45 | b=b+makePoint(x,y,0.7,1.7,0.4,0.4,time); 46 | b=b+makePoint(x,y,0.8,0.5,0.4,0.5,time); 47 | b=b+makePoint(x,y,1.4,0.9,0.6,0.3,time); 48 | b=b+makePoint(x,y,0.7,1.3,0.5,0.4,time); 49 | 50 | float c= 51 | makePoint(x,y,3.7,0.3,0.3,0.3,time); 52 | c=c+makePoint(x,y,1.9,1.3,0.4,0.4,time); 53 | c=c+makePoint(x,y,0.8,0.9,0.4,0.5,time); 54 | c=c+makePoint(x,y,1.2,1.7,0.6,0.3,time); 55 | c=c+makePoint(x,y,0.3,0.6,0.5,0.4,time); 56 | c=c+makePoint(x,y,0.3,0.3,0.4,0.4,time); 57 | c=c+makePoint(x,y,1.4,0.8,0.4,0.5,time); 58 | c=c+makePoint(x,y,0.2,0.6,0.6,0.3,time); 59 | c=c+makePoint(x,y,1.3,0.5,0.5,0.4,time); 60 | 61 | 62 | vec3 d = vec3(cos(a),sin(b),sin(c))/sin(2.0); 63 | 64 | gl_FragColor = vec4(d.y,d.y,d.y,0.2); 65 | 66 | } 67 | -------------------------------------------------------------------------------- /sample/glsl/assets/sample5.glsl: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision mediump float; 3 | #endif 4 | 5 | uniform float time; 6 | uniform vec2 mouse; 7 | uniform vec2 resolution; 8 | 9 | // An attempt at Quilez's warping (domain distortions): 10 | // http://iquilezles.org/www/articles/warp/warp.htm 11 | // 12 | // Not as good as his, but still interesting. 13 | // @SyntopiaDK, 2012 14 | 15 | 16 | 17 | float rand(vec2 co) 18 | { 19 | // implementation found at: lumina.sourceforge.net/Tutorials/Noise.html 20 | return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); 21 | } 22 | 23 | float noise2f( in vec2 p ) 24 | { 25 | vec2 ip = vec2(floor(p)); 26 | vec2 u = fract(p); 27 | // http://www.iquilezles.org/www/articles/morenoise/morenoise.htm 28 | u = u*u*(3.0-2.0*u); 29 | //u = u*u*u*((6.0*u-15.0)*u+10.0); 30 | 31 | float res = mix( 32 | mix(rand(ip), rand(ip+vec2(1.0,0.0)),u.x), 33 | mix(rand(ip+vec2(0.0,1.0)), rand(ip+vec2(1.0,1.0)),u.x), 34 | u.y) 35 | ; 36 | return res*res; 37 | //return 2.0* (res-0.5); 38 | } 39 | 40 | float fbm(vec2 c) 41 | { 42 | float f = 0.0; 43 | float w = 1.0; 44 | for (int i = 0; i < 8; i++) { 45 | f+= w*noise2f(c); 46 | c*=2.0; 47 | w*=0.5; 48 | } 49 | return f; 50 | } 51 | 52 | 53 | 54 | vec2 cMul(vec2 a, vec2 b) 55 | { 56 | return vec2( a.x*b.x - a.y*b.y,a.x*b.y + a.y * b.x); 57 | } 58 | 59 | float pattern( vec2 p, out vec2 q, out vec2 r ) 60 | { 61 | q.x = fbm( p +0.00*time); 62 | q.y = fbm( p + vec2(1.0)); 63 | 64 | r.x = fbm( p +1.0*q + vec2(1.7,9.2)+0.15*time ); 65 | r.y = fbm( p+ 1.0*q + vec2(8.3,2.8)+0.126*time); 66 | //r = cMul(q,q+0.1*time); 67 | return fbm(p +1.0*r + 0.0* time); 68 | } 69 | 70 | const vec3 color1 = vec3(0.101961,0.619608,0.666667); 71 | const vec3 color2 = vec3(0.666667,0.666667,0.498039); 72 | const vec3 color3 = vec3(0,0,0.164706); 73 | const vec3 color4 = vec3(0.666667,1,1); 74 | void main() 75 | { 76 | vec2 q; 77 | vec2 r; 78 | vec2 c = 1000.0*gl_FragCoord.xy/ resolution.xy; 79 | float f = pattern(c*0.01,q,r); 80 | vec3 col = mix(color1,color2,clamp((f*f)*4.0,0.0,1.0)); 81 | col = color2; 82 | col = mix(col,color3,clamp(length(q),0.0,1.0)); 83 | col = mix(col,color4,clamp(length(r.x),0.0,1.0)); 84 | gl_FragColor = vec4((0.2*f*f*f+0.6*f*f+0.5*f)*col,1.0); 85 | } 86 | -------------------------------------------------------------------------------- /sample/glsl/assets/sky.glsl: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision mediump float; 3 | #endif 4 | 5 | uniform float time; 6 | uniform vec2 mouse; 7 | uniform vec2 resolution; 8 | 9 | mat2 m = mat2( 0.90, 0.110, -0.70, 1.00 ); 10 | 11 | float hash( float n ) 12 | { 13 | return fract(sin(n)*758.5453); 14 | } 15 | 16 | float noise( in vec3 x ) 17 | { 18 | vec3 p = floor(x); 19 | vec3 f = fract(x); 20 | //f = f*f*(3.0-2.0*f); 21 | float n = p.x + p.y*57.0 + p.z*800.0; 22 | float res = mix(mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x), mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y), 23 | mix(mix( hash(n+800.0), hash(n+801.0),f.x), mix( hash(n+857.0), hash(n+858.0),f.x),f.y),f.z); 24 | return res; 25 | } 26 | 27 | float fbm( vec3 p ) 28 | { 29 | float f = 0.0; 30 | f += 0.50000*noise( p ); 31 | p = p*2.02; 32 | f -= 0.25000*noise( p ); 33 | p = p*2.03; 34 | f += 0.12500*noise( p ); 35 | p = p*2.01; 36 | f += 0.06250*noise( p ); 37 | p = p*2.04; 38 | f -= 0.03125*noise( p ); 39 | return f/0.984375; 40 | } 41 | 42 | float cloud(vec3 p) 43 | { 44 | p-=fbm(vec3(p.x,p.y,0.0)*0.5)*2.25; 45 | 46 | float a =0.0; 47 | a-=fbm(p*3.0)*2.2-1.1; 48 | if (a<0.0) { 49 | a=0.0; 50 | } 51 | a=a*a; 52 | return a; 53 | } 54 | 55 | vec3 f2(vec3 c) 56 | { 57 | c+=hash(gl_FragCoord.x+gl_FragCoord.y*9.9)*0.01; 58 | 59 | 60 | c*=0.7-length(gl_FragCoord.xy / resolution.xy -0.5)*0.7; 61 | float w=length(c); 62 | c=mix(c*vec3(1.0,1.0,1.6),vec3(w,w,w)*vec3(1.4,1.2,1.0),w*1.1-0.2); 63 | return c; 64 | } 65 | 66 | void main() 67 | { 68 | vec2 position = ( gl_FragCoord.xy / resolution.xy ) ; 69 | position.y+=0.2; 70 | 71 | vec2 coord= vec2((position.x-0.5)/position.y,1.0/(position.y+0.2)); 72 | 73 | //coord+=fbm(vec3(coord*18.0,time*0.001))*0.07; 74 | coord+=time*0.01; 75 | 76 | float q = cloud(vec3(coord*1.0,0.222)); 77 | 78 | vec3 col =vec3(0.2,0.7,0.8) + vec3(q*vec3(0.2,0.4,0.1)); 79 | gl_FragColor = vec4( f2(col), 1.0 ); 80 | } 81 | -------------------------------------------------------------------------------- /sample/glsl/assets/star_mark.glsl: -------------------------------------------------------------------------------- 1 | 2 | //Procedural Ordering by nimitz (twitter: @stormoid) 3 | // Gigatron for glslsandbox 4 | /* 5 | Demonstration of a simple way to have multiple objects ordered 6 | by an arbitrary function, in this case depth. The nice thing about 7 | this algorithm is that the "sorting" is completely parametric 8 | so the complexity doesn't increase with the number of objects at all. 9 | 10 | There might be some way to make the algorithm more general? 11 | */ 12 | #ifdef GL_ES 13 | precision mediump float; 14 | #endif 15 | 16 | uniform float time; 17 | uniform vec2 mouse; 18 | uniform vec2 resolution; 19 | 20 | 21 | //Number of objects to order 22 | #define NUM_OBJ 11. 23 | 24 | //If defined, the darkest layer is the one on top 25 | //and so on, with the bottom being lightest. 26 | //#define COLOR_BY_LAYER 27 | 28 | //Fixed alpha value (otherwise modulated by time) 29 | //#define ALPHA 0.5 30 | 31 | 32 | 33 | 34 | mat2 mm2(in float theta) 35 | { 36 | float c = cos(theta); 37 | float s = sin(theta); 38 | return mat2(c,-s,s,c); 39 | } 40 | 41 | //the function which defines the ordering 42 | float f (const in float x) 43 | { 44 | return mod(time-x,NUM_OBJ); 45 | } 46 | 47 | vec4 star(in vec2 p, const in float x, const in float num) 48 | { 49 | p.x+=sin(num*1.)*.25+sin(time*0.4+num*3.)*0.3; 50 | p.y+=sin(num*2.)*0.1+cos(time*0.5)*0.09; 51 | p = p/exp(x*.4-3.); 52 | 53 | p *= mm2(time*0.6+num*2.); 54 | 55 | //I knew i would find a use for my pentagon function at some point :) 56 | //two subtracted inverted pentagons -> 5 pointed star 57 | vec2 q = abs(p); 58 | float pen1 = max(max(q.x*1.176-p.y*0.385, q.x*0.727+p.y), -p.y*1.237); 59 | float pen2 = max(max(q.x*1.176+p.y*0.385, q.x*0.727-p.y), p.y*1.237)*0.619; 60 | float a = (pen1-pen2)*4.; 61 | 62 | //animation of the "send to back" 63 | float mx = clamp(0.1+1./x*0.05,0.,10.); 64 | a = 1.-smoothstep(0.1,mx,a); 65 | 66 | vec3 col = a*(sin((vec3(.19,5.,2.)*(num+1.04)*8.01))*0.5+0.6); 67 | return vec4(col,a); 68 | } 69 | 70 | void main() 71 | { 72 | //setup coordinates 73 | vec2 p = gl_FragCoord.xy / resolution.xy-0.5; 74 | p.x *= resolution.x/resolution.y; 75 | vec3 col = vec3(0); 76 | float r = length(p); 77 | 78 | for (float i = 0.; i min(a,b) && x < max(a,b); 20 | } 21 | 22 | bool inVectorRange(vec2 p, vec2 center, vec2 halfsize) 23 | { 24 | return inRange(p.x, center.x - halfsize.x, center.x + halfsize.x) && 25 | inRange(p.y, center.y - halfsize.y, center.y + halfsize.y); 26 | } 27 | 28 | void main() 29 | { 30 | float ballSize = 0.025; 31 | float ballRange = 0.8; 32 | vec2 paddleSize = vec2(0.0125, 0.1); 33 | 34 | vec2 position = ( gl_FragCoord.xy / resolution.xy ) - vec2(0.5, 0.5); 35 | position.x *= resolution.x / resolution.y; 36 | 37 | vec2 ballPos = vec2(triWave(time)*ballRange, triWave(time*0.725)*(1.0 - ballSize)); 38 | 39 | float inter1 = 1.0 - (ballPos.x/ballRange + 0.5); 40 | vec2 paddle1 = vec2(-0.45 + ballSize, clamp(mix(0.0, ballPos.y, 0.25 + 0.75 * inter1), -0.5 + paddleSize.y, 0.5 - paddleSize.y)); 41 | 42 | float inter2 = ballPos.x/ballRange + 0.5; 43 | vec2 paddle2 = vec2(0.45 - ballSize, clamp(mix(0.0, ballPos.y, 0.25 + 0.75 * inter2), -0.5 + paddleSize.y, 0.5 - paddleSize.y)); 44 | 45 | float color = 0.0; 46 | color = ( 47 | length(position - ballPos) < ballSize || // ball 48 | inVectorRange(position, paddle1, paddleSize) || // paddle left 49 | inVectorRange(position, paddle2, paddleSize)) // paddle right 50 | ? 1.0 : 0.0; 51 | 52 | gl_FragColor = vec4( color, color, color, 1.0 ); 53 | } 54 | -------------------------------------------------------------------------------- /sample/glsl/assets/tex.glsl: -------------------------------------------------------------------------------- 1 | // 2 | uniform float time; 3 | uniform vec2 mouse; 4 | uniform vec2 resolution; 5 | uniform sampler2D texture; 6 | //uniform sampler2D iChannel0; 7 | #define iChannel0 texture 8 | uniform sampler2D iChannel1; 9 | uniform sampler2D iChannel2; 10 | 11 | float iGlobalTime = time; 12 | vec4 iMouse = vec4(mouse*resolution.xy, 0.0, 0.0); 13 | vec2 iResolution = resolution; 14 | 15 | float Sign(vec2 p1, vec2 p2, vec2 p3) 16 | { 17 | return (p1.x - p3.x) * (p2.y - p3.y) - (p2.x - p3.x) * (p1.y - p3.y); 18 | } 19 | 20 | bool IsPointInTri(vec2 pt, vec2 v1, vec2 v2, vec2 v3) 21 | { 22 | bool b1, b2, b3; 23 | 24 | b1 = Sign(pt, v1, v2) < 0.0; 25 | b2 = Sign(pt, v2, v3) < 0.0; 26 | b3 = Sign(pt, v3, v1) < 0.0; 27 | 28 | return ((b1 == b2) && (b2 == b3)); 29 | } 30 | 31 | void mainImage(out vec4 fragColor, in vec2 fragCoord) 32 | { 33 | vec2 r = 2.0*vec2(fragCoord.xy - 0.5*iResolution.xy) / iResolution.y; 34 | vec2 uv = fragCoord.xy/iResolution.xy; 35 | uv.y = 1.-uv.y; 36 | 37 | if (IsPointInTri(uv, vec2(0.5, 0.7), vec2(1.0, 0.3), vec2(0.5, 0.3))) { 38 | float prog = (0.5-uv.x)*2.; 39 | 40 | float hyp = sqrt(pow(0.5,2.)+pow(0.5,2.)); 41 | 42 | float r = 0.5; 43 | 44 | float x = 0.0+uv.x + r * cos(60. * iGlobalTime*0.01); 45 | float y = 0.5+uv.y + r * sin(60. * iGlobalTime*0.01); 46 | 47 | uv.x = x; 48 | uv.y = y; 49 | } 50 | 51 | vec4 tex = texture2D(iChannel0, uv); 52 | vec3 pixel = tex.rgb; 53 | 54 | fragColor = vec4(pixel, 1.0); 55 | } 56 | 57 | void main() 58 | { 59 | vec4 color; 60 | mainImage(color, gl_FragCoord.xy); 61 | gl_FragColor = color; 62 | } 63 | -------------------------------------------------------------------------------- /sample/glsl/assets/tex.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/glsl/assets/tex.jpg -------------------------------------------------------------------------------- /sample/glsl/assets/tunnel.glsl: -------------------------------------------------------------------------------- 1 | //precision highp float; 2 | 3 | uniform float time; 4 | uniform vec2 mouse; 5 | uniform vec2 resolution; 6 | 7 | float gc=fract(time*3.2/90.), 8 | gb=fract(gc*2.), 9 | PI=3.14159; 10 | vec3 ff(vec2 p) 11 | { 12 | vec2 q=vec2(sin(.08*p.x),4.*p.y); 13 | vec3 c=vec3(0); 14 | for (float i=0.; i<9.; i++) { 15 | c+=(1.+sin(i*sin(time)+vec3(0.,1.3,2.2)))*.2/length(q-vec2(sin(i),12.*sin(.3*time+i))); 16 | } 17 | return c+vec3(mix(mod(floor(p.x*.2)+floor(p.y*2.2),2.),.2,gc)); 18 | } 19 | vec3 ft(vec3 o,vec3 d) 20 | { 21 | d.y*=.65+.1*sin(.5*time); 22 | float D=1./(d.y*d.y+d.z*d.z), 23 | a=(o.y*d.y+o.z*d.z)*D, 24 | b=(o.y*o.y+o.z*o.z-36.)*D, 25 | t=-a-sqrt(a*a-b); 26 | o+=t*d; 27 | return ff(vec2(o.x,atan(o.y,o.z)))*(1.+.01*t); 28 | } 29 | void main() 30 | { 31 | vec2 p=(2.*gl_FragCoord.xy-resolution)/resolution.y, 32 | q=1.*gl_FragCoord.xy/resolution-1.; 33 | vec3 cp=vec3(-time*20.+1.,1.6*sin(time*1.2),2.+2.*cos(time*.3)), 34 | ct=cp+vec3(1.,.3*cos(time),-.2), 35 | cd=normalize(ct-cp), 36 | cr=normalize(cross(cd,vec3(.111*cos(.3*time),0.,1.))), 37 | cu=cross(cr,cd), 38 | rd=normalize(2.*cd+cr*p.x+cu*p.y), 39 | c=ft(cp,rd)* 40 | min(1.,1.8-dot(q,q)); 41 | gl_FragColor=vec4(c,1); 42 | } 43 | -------------------------------------------------------------------------------- /sample/glsl/assets/wait.glsl: -------------------------------------------------------------------------------- 1 | #ifdef GL_ES 2 | precision mediump float; 3 | #endif 4 | 5 | uniform float time; 6 | uniform vec2 mouse; 7 | uniform vec2 resolution; 8 | 9 | #define pi 3.1415926536 10 | #define N 12 11 | 12 | void main() 13 | { 14 | vec2 position = ( gl_FragCoord.xy / resolution.xy ); 15 | vec2 center=position*2.-1.; 16 | center.x*=resolution.x/resolution.y; 17 | float c=0.; 18 | float r=0.3; 19 | float o; 20 | for (int i=0; iwidth ? 0: x; 66 | nvgBeginFrame(vg, width, height, pixelRatio); 67 | s.x = x; 68 | s.y = sin_fast(x/10.)*height/2+height/2; 69 | caSpriteRender(&s); 70 | nvgEndFrame(vg); 71 | } 72 | 73 | void caEnd() 74 | { 75 | caSpriteDelete(&s); 76 | nvgDelete(vg); 77 | } 78 | -------------------------------------------------------------------------------- /sample/teapot_GL1/Makefile: -------------------------------------------------------------------------------- 1 | #SRC = ../glfw/glfw.c 2 | INCLUDE = -I../../ -I../../nanovg 3 | LIBS = -lglfw -lGL -lGLU -lm 4 | 5 | include ../Makefile.in 6 | -------------------------------------------------------------------------------- /sample/teapot_GL1/assets/teapot.obj.dat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/teapot_GL1/assets/teapot.obj.dat -------------------------------------------------------------------------------- /sample/teapot_GL1/main.c: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------- 2 | // catgl 3 | // 4 | // ©2015 Yuichiro Nakada 5 | //--------------------------------------------------------- 6 | 7 | #include 8 | 9 | #define CATGL_GLES_IMPLEMENTATION // Use OpenGL ES1 10 | #include "catgl.h" 11 | #include "models.h" 12 | 13 | MODEL_T m; 14 | 15 | static float angle = 0; 16 | 17 | // 透視投影の設定 18 | void gluPerspective(double fovy, double aspect, double zNear, double zFar) 19 | { 20 | GLfloat xmin, xmax, ymin, ymax; 21 | ymax = zNear * tan(fovy * CATGL_PI / 360.0); 22 | ymin = -ymax; 23 | xmin = ymin * aspect; 24 | xmax = ymax * aspect; 25 | // glFrustumf(xmin, xmax, ymin, ymax, zNear, zFar); 26 | glFrustum(xmin, xmax, ymin, ymax, zNear, zFar); 27 | } 28 | 29 | void caInit(int width, int height) 30 | { 31 | // Set background color and clear buffers 32 | glClearColor((0.3922f+7*0.5f)/8, (0.1176f+7*0.5f)/8, (0.5882f+7*0.5f)/8, 1.0f); 33 | 34 | // Enable back face culling. 35 | glEnable(GL_CULL_FACE); 36 | 37 | glEnable(GL_DEPTH_TEST); 38 | glClearDepthf(1.0); 39 | glDepthFunc(GL_LEQUAL); 40 | 41 | float noAmbient[] = {1.0f, 1.0f, 1.0f, 1.0f}; 42 | glLightfv(GL_LIGHT0, GL_AMBIENT, noAmbient); 43 | glEnable(GL_LIGHT0); 44 | glEnable(GL_LIGHTING); 45 | 46 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); 47 | glEnableClientState(GL_VERTEX_ARRAY); 48 | 49 | // 縦横比の設定 50 | float ratio = (float)width / (float)height; 51 | glViewport(0, 0, (int)width, (int)height); 52 | 53 | // 行列演算のモード設定 54 | glMatrixMode(GL_PROJECTION); 55 | // 単位行列のロード 56 | glLoadIdentity(); 57 | // 透視投影の設定 58 | gluPerspective(40.0, ratio, 0.1, 100); 59 | 60 | // m = cube_wavefront(); 61 | m = caLoadWavefront("teapot.obj.dat", NULL); 62 | //m = caLoadWavefront("airboat.obj", NULL); 63 | //m = caLoadWavefront("al.obj", NULL); 64 | //m = caLoadWavefront("cube.obj", NULL); 65 | //m = caLoadWavefront("sample.obj", NULL); 66 | //m = caLoadWavefront("cornell_box.obj", NULL); 67 | } 68 | 69 | void caRender() 70 | { 71 | // 行列演算のモード設定 72 | glMatrixMode(GL_MODELVIEW); 73 | // 単位行列のロード 74 | glLoadIdentity(); 75 | // 平行移動 76 | glTranslatef(0.0, 0.0, -2.0); 77 | // 角度を演算 78 | angle = (angle + 2); 79 | if (angle >= 360) { 80 | angle = 0; 81 | } 82 | // 角度を設定 83 | glRotatef(angle, angle, angle, 1.0f); 84 | 85 | // バッファをクリアー 86 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 87 | 88 | caDrawWavefront(m, 0); 89 | } 90 | 91 | void caEnd() 92 | { 93 | caUnloadWavefront(m); 94 | } 95 | -------------------------------------------------------------------------------- /sample/teapot_GL1/models.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012, Broadcom Europe Ltd 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | * Neither the name of the copyright holder nor the 13 | names of its contributors may be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef MODELS_T 29 | #define MODELS_T 30 | typedef struct opqaue_model_s * MODEL_T; 31 | 32 | MODEL_T caLoadWavefront(const char *modelname, const char *texturename); 33 | void caUnloadWavefront(MODEL_T m); 34 | int caDrawWavefront(MODEL_T m, GLuint texture); 35 | 36 | MODEL_T cube_wavefront(); 37 | #endif 38 | -------------------------------------------------------------------------------- /sample/teapot_GL1/teapot_GL1-debug.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/teapot_GL1/teapot_GL1-debug.apk -------------------------------------------------------------------------------- /sample/texture_basic/Makefile: -------------------------------------------------------------------------------- 1 | #SRC = ../glfw/glfw.c 2 | INCLUDE = -I../../ -I../../nanovg 3 | LIBS = -lglfw -lGL -lGLU -lm 4 | 5 | include ../Makefile.in 6 | -------------------------------------------------------------------------------- /sample/texture_basic/main.c: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------- 2 | // catgl 3 | // 4 | // ©2015 Yuichiro Nakada 5 | //--------------------------------------------------------- 6 | 7 | #define CATGL_IMPLEMENTATION 8 | #include "catgl.h" 9 | 10 | const char* vertex_shader = 11 | "attribute vec4 position;\n" 12 | "attribute vec2 texcoord;\n" 13 | "varying vec2 texcoordVarying;\n" 14 | "void main() {\n" 15 | "gl_Position = position;\n" 16 | "texcoordVarying = texcoord;\n" 17 | "}\n"; 18 | 19 | const char* fragment_shader = 20 | // "precision mediump float;\n" 21 | "varying vec2 texcoordVarying;\n" 22 | "uniform sampler2D texture;\n" 23 | "void main() {\n" 24 | "gl_FragColor = texture2D(texture, texcoordVarying);\n" 25 | "}\n"; 26 | 27 | const float vertices[] = { 28 | -1.0f, 1.0f, 0.0f, 29 | -1.0f, -1.0f, 0.0f, 30 | 1.0f, 1.0f, 0.0f, 31 | 1.0f, -1.0f, 0.0f 32 | }; 33 | 34 | const float texcoords[] = { 35 | 0.0f, 0.0f, 36 | 0.0f, 1.0f, 37 | 1.0f, 0.0f, 38 | 1.0f, 1.0f 39 | }; 40 | 41 | GLuint program, position, texcoord; 42 | GLuint textures[1]; 43 | 44 | // ダミーテクスチャ 45 | static unsigned char tex[] = { 46 | 255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 255 ,255, 0, 0, 0, 255, 47 | 255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255 ,255, 255, 255, 255, 255, 48 | 128, 0, 0, 255, 0, 128, 0, 255, 0, 0, 128 ,255, 128, 128, 128, 255, 49 | 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, 255 ,255, 255, 255, 255, 255, 50 | }; 51 | 52 | void caInit(int width, int height) 53 | { 54 | glViewport(0, 0, width, height); 55 | 56 | program = caCreateProgram(vertex_shader, "position", fragment_shader, "gl_FragColor"); 57 | if (program == 0) { 58 | return; 59 | } 60 | glUseProgram(program); 61 | 62 | position = glGetAttribLocation(program, "position"); 63 | glEnableVertexAttribArray(position); 64 | 65 | texcoord = glGetAttribLocation(program, "texcoord"); 66 | glEnableVertexAttribArray(texcoord); 67 | 68 | textures[0] = caCreateTexture(tex, 4, 4); 69 | } 70 | 71 | void caRender() 72 | { 73 | glClearColor(0.3f, 0.3f, 0.3f, 1.0f); 74 | glClear(GL_COLOR_BUFFER_BIT); 75 | 76 | glBindTexture(GL_TEXTURE_2D, textures[0]); 77 | glVertexAttribPointer(texcoord, 2, GL_FLOAT, GL_FALSE, 0, texcoords); 78 | glVertexAttribPointer(position, 3, GL_FLOAT, GL_FALSE, 0, vertices); 79 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 80 | } 81 | 82 | void caEnd() 83 | { 84 | glDeleteTextures(1, textures); 85 | glDeleteProgram(program); 86 | } 87 | -------------------------------------------------------------------------------- /sample/texture_pbo/Makefile: -------------------------------------------------------------------------------- 1 | #SRC = ../glfw/glfw.c 2 | INCLUDE = -I../../ -I../../nanovg 3 | LIBS = -lglfw -lGL -lGLU -lm 4 | 5 | include ../Makefile.in 6 | -------------------------------------------------------------------------------- /sample/texture_pbo/main.c: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------- 2 | // catgl 3 | // 4 | // ©2015 Yuichiro Nakada 5 | //--------------------------------------------------------- 6 | 7 | #define CATGL_IMPLEMENTATION 8 | #include "catgl.h" 9 | 10 | const char* vertex_shader = 11 | "attribute vec4 position;\n" 12 | "attribute vec2 texcoord;\n" 13 | "varying vec2 texcoordVarying;\n" 14 | "void main() {\n" 15 | "gl_Position = position;\n" 16 | "texcoordVarying = texcoord;\n" 17 | "}\n"; 18 | 19 | const char* fragment_shader = 20 | // "precision mediump float;\n" 21 | "varying vec2 texcoordVarying;\n" 22 | "uniform sampler2D texture;\n" 23 | "void main() {\n" 24 | "gl_FragColor = texture2D(texture, texcoordVarying);\n" 25 | "}\n"; 26 | 27 | /*const float vertices[] = { 28 | -1.0f, 1.0f, 0.0f, 29 | -1.0f, -1.0f, 0.0f, 30 | 1.0f, 1.0f, 0.0f, 31 | 1.0f, -1.0f, 0.0f 32 | }; 33 | 34 | const float texcoords[] = { 35 | 0.0f, 0.0f, 36 | 0.0f, 1.0f, 37 | 1.0f, 0.0f, 38 | 1.0f, 1.0f 39 | };*/ 40 | 41 | const float vertices[] = { 42 | -1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 43 | -1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 44 | 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 45 | 1.0f, -1.0f, 0.0f, 1.0f, 1.0f 46 | }; 47 | 48 | GLuint vbo[2]; 49 | GLuint program, position, texcoord; 50 | GLuint textures[1]; 51 | 52 | // ダミーテクスチャ 53 | static unsigned char tex[] = { 54 | 255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 255 ,255, 0, 0, 0, 255, 55 | 255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255 ,255, 255, 255, 255, 255, 56 | 128, 0, 0, 255, 0, 128, 0, 255, 0, 0, 128 ,255, 128, 128, 128, 255, 57 | 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, 255 ,255, 255, 255, 255, 255, 58 | }; 59 | 60 | void caInit(int width, int height) 61 | { 62 | glViewport(0, 0, width, height); 63 | 64 | program = caCreateProgram(vertex_shader, "position", fragment_shader, "gl_FragColor"); 65 | if (program == 0) { 66 | return; 67 | } 68 | glUseProgram(program); 69 | 70 | glGenBuffers(2, vbo); 71 | glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); 72 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); 73 | // glBindBuffer(GL_ARRAY_BUFFER, vbo[1]); 74 | // glBufferData(GL_ARRAY_BUFFER, sizeof(texcoords), texcoords, GL_STATIC_DRAW); 75 | 76 | glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); 77 | glEnableVertexAttribArray(CATGL_ATT_VERTEX); 78 | // glVertexAttribPointer(CATGL_ATT_VERTEX, 3, GL_FLOAT, GL_FALSE, 0, 0); 79 | glVertexAttribPointer(CATGL_ATT_VERTEX, 3, GL_FLOAT, GL_FALSE, sizeof(float)*5, 0); 80 | 81 | // glBindBuffer(GL_ARRAY_BUFFER, vbo[1]); 82 | glEnableVertexAttribArray(CATGL_ATT_TEXTURE); 83 | // glVertexAttribPointer(CATGL_ATT_TEXTURE, 2, GL_FLOAT, GL_FALSE, 0, 0); 84 | glVertexAttribPointer(CATGL_ATT_TEXTURE, 2, GL_FLOAT, GL_FALSE, sizeof(float)*5, sizeof(float)*3); 85 | 86 | textures[0] = caCreateTexture(tex, 4, 4); 87 | } 88 | 89 | void caRender() 90 | { 91 | glClearColor(0.3f, 0.3f, 0.3f, 1.0f); 92 | glClear(GL_COLOR_BUFFER_BIT); 93 | 94 | glBindTexture(GL_TEXTURE_2D, textures[0]); 95 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 96 | } 97 | 98 | void caEnd() 99 | { 100 | glDeleteTextures(1, textures); 101 | glDeleteProgram(program); 102 | } 103 | -------------------------------------------------------------------------------- /sample/texture_pic/Makefile: -------------------------------------------------------------------------------- 1 | #SRC = ../glfw/glfw.c 2 | INCLUDE = -I../../ -I../../nanovg 3 | LIBS = -lglfw -lGL -lGLU -lm 4 | 5 | include ../Makefile.in 6 | -------------------------------------------------------------------------------- /sample/texture_pic/assets/cat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/texture_pic/assets/cat.jpg -------------------------------------------------------------------------------- /sample/texture_pic/main.c: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------- 2 | // catgl 3 | // 4 | // ©2015 Yuichiro Nakada 5 | //--------------------------------------------------------- 6 | 7 | #define CATGL_IMPLEMENTATION 8 | #include "catgl.h" 9 | 10 | const char* vertex_shader = 11 | "attribute vec4 position;\n" 12 | "attribute vec2 texcoord;\n" 13 | "varying vec2 texcoordVarying;\n" 14 | "void main() {\n" 15 | "gl_Position = position;\n" 16 | "texcoordVarying = texcoord;\n" 17 | "}\n"; 18 | 19 | const char* fragment_shader = 20 | // "precision mediump float;\n" 21 | "varying vec2 texcoordVarying;\n" 22 | "uniform sampler2D texture;\n" 23 | "void main() {\n" 24 | "gl_FragColor = texture2D(texture, texcoordVarying);\n" 25 | "}\n"; 26 | 27 | const float vertices[] = { 28 | -1.0f, 1.0f, 0.0f, 29 | -1.0f, -1.0f, 0.0f, 30 | 1.0f, 1.0f, 0.0f, 31 | 1.0f, -1.0f, 0.0f 32 | }; 33 | 34 | const float texcoords[] = { 35 | 0.0f, 0.0f, 36 | 0.0f, 1.0f, 37 | 1.0f, 0.0f, 38 | 1.0f, 1.0f 39 | }; 40 | 41 | GLuint vbo[2]; 42 | GLuint program, position, texcoord; 43 | GLuint textures[1]; 44 | 45 | // ダミーテクスチャ 46 | /*static unsigned char tex[] = { 47 | 255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 255 ,255, 0, 0, 0, 255, 48 | 255, 0, 0, 255, 0, 255, 0, 255, 0, 0, 255 ,255, 255, 255, 255, 255, 49 | 128, 0, 0, 255, 0, 128, 0, 255, 0, 0, 128 ,255, 128, 128, 128, 255, 50 | 255, 255, 0, 255, 255, 0, 255, 255, 0, 255, 255 ,255, 255, 255, 255, 255, 51 | };*/ 52 | 53 | void caInit(int width, int height) 54 | { 55 | glViewport(0, 0, width, height); 56 | 57 | program = caCreateProgram(vertex_shader, "position", fragment_shader, "gl_FragColor"); 58 | if (program == 0) { 59 | return; 60 | } 61 | glUseProgram(program); 62 | 63 | glGenBuffers(2, vbo); 64 | glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); 65 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); 66 | glBindBuffer(GL_ARRAY_BUFFER, vbo[1]); 67 | glBufferData(GL_ARRAY_BUFFER, sizeof(texcoords), texcoords, GL_STATIC_DRAW); 68 | 69 | position = glGetAttribLocation(program, "position"); 70 | glEnableVertexAttribArray(position); 71 | glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); 72 | glVertexAttribPointer(position, 3, GL_FLOAT, GL_FALSE, 0, 0); 73 | 74 | texcoord = glGetAttribLocation(program, "texcoord"); 75 | glEnableVertexAttribArray(texcoord); 76 | glBindBuffer(GL_ARRAY_BUFFER, vbo[1]); 77 | glVertexAttribPointer(texcoord, 2, GL_FLOAT, GL_FALSE, 0, 0); 78 | 79 | //textures[0] = caCreateTexture(tex, 4, 4); 80 | textures[0] = caLoadTexture("cat.jpg"); 81 | } 82 | 83 | void caRender() 84 | { 85 | glClearColor(0.3f, 0.3f, 0.3f, 1.0f); 86 | glClear(GL_COLOR_BUFFER_BIT); 87 | 88 | glBindTexture(GL_TEXTURE_2D, textures[0]); 89 | // glVertexAttribPointer(texcoord, 2, GL_FLOAT, GL_FALSE, 0, texcoords); 90 | // glVertexAttribPointer(position, 3, GL_FLOAT, GL_FALSE, 0, vertices); 91 | glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 92 | } 93 | 94 | void caEnd() 95 | { 96 | glDeleteTextures(1, textures); 97 | glDeleteProgram(program); 98 | } 99 | -------------------------------------------------------------------------------- /sample/triangle/Makefile: -------------------------------------------------------------------------------- 1 | #SRC = ../glfw/glfw.c 2 | INCLUDE = -I../../ -I../../nanovg 3 | LIBS = -lglfw -lGL -lGLU -lm 4 | 5 | include ../Makefile.in 6 | -------------------------------------------------------------------------------- /sample/triangle/triangle.c: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------- 2 | // catgl 3 | // 4 | // ©2015 Yuichiro Nakada 5 | //--------------------------------------------------------- 6 | 7 | #define CATGL_IMPLEMENTATION 8 | #include "catgl.h" 9 | 10 | // Shader sources 11 | static const GLchar vsrc[] = 12 | "#version 120\n" 13 | "uniform mat4 projectionMatrix;" 14 | "uniform mat4 modelviewMatrix;" 15 | "attribute vec3 position;" // in 16 | "attribute vec3 v_color;" // in 17 | "varying vec3 f_color;" // out 18 | // "attribute vec2 texcoord;" // in 19 | // "varying vec2 texcoordVarying;" // out 20 | "void main() {" 21 | " gl_Position = projectionMatrix * modelviewMatrix * vec4(position, 1.0);" 22 | //ok " gl_Position = gl_ModelViewMatrix * vec4(position, 1.0);" 23 | //x " gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;" 24 | " f_color = v_color;" 25 | // " texcoordVarying = texcoord;" 26 | "}"; 27 | static const GLchar fsrc[] = 28 | "#version 120\n" 29 | "varying vec3 f_color;" 30 | "void main(void) {" 31 | " gl_FragColor = vec4(f_color.x, f_color.y, f_color.z, 1.0);" 32 | "}"; 33 | 34 | CATGL_VERTEX obj[] = 35 | { 36 | { 0.0f, 0.8f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f }, 37 | { -0.8f, -0.8f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f }, 38 | { 0.8f, -0.8f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f }, 39 | }; 40 | 41 | GLuint program; 42 | GLuint vbo; 43 | 44 | // 表示の初期化 45 | void caInit(int width, int height) 46 | { 47 | glViewport(0, 0, width, height); 48 | 49 | program = caCreateProgram(vsrc, "position", fsrc, "gl_FragColor"); 50 | 51 | GLuint att[3]; 52 | att[0] = glGetAttribLocation(program, "position"); 53 | att[1] = glGetAttribLocation(program, "v_color"); 54 | att[2] = 65535; 55 | vbo = caCreateObject(obj, sizeof(obj)/sizeof(obj[0]), att); 56 | 57 | glUseProgram(program); 58 | } 59 | 60 | // 描画 61 | void caRender() 62 | { 63 | // glMatrixMode(GL_MODELVIEW); 64 | // glLoadIdentity(); 65 | //glTranslatef(0.0, 0.0, -50.0); 66 | static float angle; 67 | angle += 2; 68 | if (angle > 360) { 69 | angle = 0; 70 | } 71 | // glRotatef(angle, 0, 0, 1.0f); 72 | 73 | /* GLfloat m[16]; 74 | glGetFloatv(GL_MODELVIEW_MATRIX, m); 75 | caPrintMatrix(m); 76 | glUniformMatrix4fv(glGetUniformLocation(program, "modelviewMatrix"), 1, GL_FALSE, m); 77 | glGetFloatv(GL_PROJECTION_MATRIX, m); 78 | glUniformMatrix4fv(glGetUniformLocation(program, "projectionMatrix"), 1, GL_FALSE, m);*/ 79 | 80 | float m[16]; 81 | caMakeUnit(m); 82 | glUniformMatrix4fv(glGetUniformLocation(program, "projectionMatrix"), 1, GL_FALSE, m); 83 | caRotationZ(m, angle); 84 | glUniformMatrix4fv(glGetUniformLocation(program, "modelviewMatrix"), 1, GL_FALSE, m); 85 | 86 | // Clear the screen to black 87 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 88 | glClear(GL_COLOR_BUFFER_BIT); 89 | 90 | // Draw a triangle from the 3 vertices 91 | glDrawArrays(GL_TRIANGLES, 0, 3); 92 | } 93 | 94 | void caEnd() 95 | { 96 | glDeleteBuffers(1, &vbo); 97 | glDeleteProgram(program); 98 | } 99 | -------------------------------------------------------------------------------- /sample/viewer/Makefile: -------------------------------------------------------------------------------- 1 | #SRC = ../glfw/glfw.c 2 | INCLUDE = -I../../ -I../../nanovg 3 | LIBS = -lglfw -lGL -lGLU -lm 4 | 5 | include ../Makefile.in 6 | -------------------------------------------------------------------------------- /sample/viewer/assets/eyeM2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/viewer/assets/eyeM2.bmp -------------------------------------------------------------------------------- /sample/viewer/assets/miku.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'None' 2 | # Material Count: 17 3 | 4 | newmtl mat00.002 5 | Ns 7.843137 6 | Ka 0.000000 0.000000 0.000000 7 | Kd 0.106400 0.492800 0.568000 8 | Ks 0.000000 0.000000 0.000000 9 | Ni 1.000000 10 | d 1.000000 11 | illum 2 12 | 13 | newmtl mat01.002 14 | Ns 17.647059 15 | Ka 0.000000 0.000000 0.000000 16 | Kd 0.000000 0.454400 0.454400 17 | Ks 0.125000 0.125000 0.125000 18 | Ni 1.000000 19 | d 1.000000 20 | illum 2 21 | 22 | newmtl mat02.002 23 | Ns 9.803922 24 | Ka 0.000000 0.000000 0.000000 25 | Kd 0.640000 0.569600 0.499200 26 | Ks 0.075000 0.075000 0.075000 27 | Ni 1.000000 28 | d 1.000000 29 | illum 2 30 | 31 | newmtl mat03.002 32 | Ns 27.450980 33 | Ka 0.000000 0.000000 0.000000 34 | Kd 0.128000 0.128000 0.128000 35 | Ks 0.200000 0.200000 0.200000 36 | Ni 1.000000 37 | d 1.000000 38 | illum 2 39 | 40 | newmtl mat04.002 41 | Ns 7.843137 42 | Ka 0.000000 0.000000 0.000000 43 | Kd 0.451840 0.451840 0.451840 44 | Ks 0.075000 0.075000 0.075000 45 | Ni 1.000000 46 | d 1.000000 47 | illum 2 48 | 49 | newmtl mat05.002 50 | Ns 7.843137 51 | Ka 0.000000 0.000000 0.000000 52 | Kd 0.376320 0.640000 0.522240 53 | Ks 0.000000 0.000000 0.000000 54 | Ni 1.000000 55 | d 1.000000 56 | illum 2 57 | 58 | newmtl mat06.002 59 | Ns 7.843137 60 | Ka 0.000000 0.000000 0.000000 61 | Kd 0.523200 0.523200 0.523200 62 | Ks 0.000000 0.000000 0.000000 63 | Ni 1.000000 64 | d 1.000000 65 | illum 2 66 | map_Kd eyeM2.bmp 67 | map_d eyeM2.bmp 68 | 69 | newmtl mat07.002 70 | Ns 7.843137 71 | Ka 0.000000 0.000000 0.000000 72 | Kd 0.092800 0.092800 0.092800 73 | Ks 0.190000 0.190000 0.190000 74 | Ni 1.000000 75 | d 1.000000 76 | illum 2 77 | 78 | newmtl mat08.002 79 | Ns 7.843137 80 | Ka 0.000000 0.000000 0.000000 81 | Kd 0.634880 0.147840 0.206080 82 | Ks 0.000000 0.000000 0.000000 83 | Ni 1.000000 84 | d 1.000000 85 | illum 2 86 | 87 | newmtl mat09.002 88 | Ns 7.843137 89 | Ka 0.000000 0.000000 0.000000 90 | Kd 0.462080 0.504320 0.130560 91 | Ks 0.000000 0.000000 0.000000 92 | Ni 1.000000 93 | d 1.000000 94 | illum 2 95 | 96 | newmtl mat10.002 97 | Ns 7.843137 98 | Ka 0.000000 0.000000 0.000000 99 | Kd 0.474240 0.544640 0.640000 100 | Ks 0.000000 0.000000 0.000000 101 | Ni 1.000000 102 | d 1.000000 103 | illum 2 104 | 105 | newmtl mat11.002 106 | Ns 7.843137 107 | Ka 0.000000 0.000000 0.000000 108 | Kd 0.000000 0.000000 0.000000 109 | Ks 0.000000 0.000000 0.000000 110 | Ni 1.000000 111 | d 1.000000 112 | illum 2 113 | 114 | newmtl mat12.002 115 | Ns 7.843137 116 | Ka 0.000000 0.000000 0.000000 117 | Kd 0.561920 0.080000 0.097920 118 | Ks 0.000000 0.000000 0.000000 119 | Ni 1.000000 120 | d 1.000000 121 | illum 2 122 | 123 | newmtl mat13.002 124 | Ns 7.843137 125 | Ka 0.000000 0.000000 0.000000 126 | Kd 0.165760 0.110720 0.065280 127 | Ks 0.000000 0.000000 0.000000 128 | Ni 1.000000 129 | d 1.000000 130 | illum 2 131 | 132 | newmtl mat14.002 133 | Ns 7.843137 134 | Ka 0.000000 0.000000 0.000000 135 | Kd 0.640000 0.304000 0.331520 136 | Ks 0.000000 0.000000 0.000000 137 | Ni 1.000000 138 | d 1.000000 139 | illum 2 140 | 141 | newmtl mat15.002 142 | Ns 7.843137 143 | Ka 0.000000 0.000000 0.000000 144 | Kd 0.640000 0.640000 0.640000 145 | Ks 0.090000 0.090000 0.090000 146 | Ni 1.000000 147 | d 1.000000 148 | illum 2 149 | 150 | newmtl mat16.002 151 | Ns 7.843137 152 | Ka 0.000000 0.000000 0.000000 153 | Kd 0.065600 0.307200 0.354400 154 | Ks 0.000000 0.000000 0.000000 155 | Ni 1.000000 156 | d 1.000000 157 | illum 2 158 | -------------------------------------------------------------------------------- /sample/viewer/viewer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/viewer/viewer.png -------------------------------------------------------------------------------- /sample/viewer_GL1/Makefile: -------------------------------------------------------------------------------- 1 | #SRC = ../glfw/glfw.c 2 | INCLUDE = -I../../ -I../../nanovg 3 | LIBS = -lglfw -lGL -lGLU -lm 4 | 5 | include ../Makefile.in 6 | -------------------------------------------------------------------------------- /sample/viewer_GL1/main.c: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------- 2 | // catgl 3 | // 4 | // ©2015 Yuichiro Nakada 5 | //--------------------------------------------------------- 6 | 7 | #include 8 | 9 | #define CATGL_GLES_IMPLEMENTATION // Use OpenGL ES1 10 | #include "catgl.h" 11 | #include "catgl_obj.h" 12 | 13 | CATGL_MODEL m; 14 | GLuint vbo[2]; 15 | 16 | static float angle = 0; 17 | 18 | #include 19 | char *getObjFile(/*char *path, char *ext, */int c) 20 | { 21 | char *path = "./"; 22 | char *ext = ".obj"; 23 | 24 | static char s[BUFSIZ]; 25 | int n = -1, e = strlen(ext); 26 | 27 | //printf("+%s\n", path); 28 | DIR *dir = opendir(CATGL_ASSETS(path)); 29 | struct dirent *d; 30 | while ((d = readdir(dir)) != NULL) { 31 | char *p = strchr(d->d_name, 0); 32 | //printf("-%s,%s\n", d->d_name, p-e); 33 | if (strstr(p-e, ext)) { 34 | n++; 35 | if (n==c) { 36 | strncpy(s, d->d_name, BUFSIZ); 37 | break; 38 | } 39 | } 40 | } 41 | closedir(dir); 42 | 43 | if (n==c) return s; 44 | return 0; 45 | } 46 | 47 | void keyEvent(int key, int action) 48 | { 49 | static int obj; 50 | char *s = 0; 51 | 52 | if (action == CATGL_ACTION_DOWN) { 53 | switch (key) { 54 | case CATGL_KEY_P: 55 | caMode = CATGL_MODE_POINT; 56 | break; 57 | case CATGL_KEY_W: 58 | caMode = CATGL_MODE_LINE; 59 | break; 60 | case CATGL_KEY_T: 61 | caMode = CATGL_MODE_TRIANGLES; 62 | break; 63 | case CATGL_KEY_RIGHT: 64 | obj++; 65 | s = getObjFile(obj); 66 | if (!s) { 67 | obj = 0; 68 | s = getObjFile(obj); 69 | } 70 | break; 71 | case CATGL_KEY_LEFT: 72 | obj--; 73 | if (obj<0) obj = 0; 74 | s = getObjFile(obj); 75 | break; 76 | } 77 | } 78 | 79 | if (s) { 80 | printf("%s\n", s); 81 | caDeleteObject_GL1(vbo); 82 | caUnloadObj(&m); 83 | caLoadObj(&m, s); 84 | caCreateObject_GL1(vbo, &m); 85 | } 86 | } 87 | void mouseEvent(int button, int action, int x, int y) 88 | { 89 | keyEvent(CATGL_KEY_RIGHT, action); 90 | } 91 | 92 | // 透視投影の設定 93 | void gluPerspective(double fovy, double aspect, double zNear, double zFar) 94 | { 95 | GLfloat xmin, xmax, ymin, ymax; 96 | ymax = zNear * tan(fovy * CATGL_PI / 360.0); 97 | ymin = -ymax; 98 | xmin = ymin * aspect; 99 | xmax = ymax * aspect; 100 | // glFrustumf(xmin, xmax, ymin, ymax, zNear, zFar); 101 | glFrustum(xmin, xmax, ymin, ymax, zNear, zFar); 102 | } 103 | 104 | void caInit(int width, int height) 105 | { 106 | // Set background color and clear buffers 107 | glClearColor((0.3922f+7*0.5f)/8, (0.1176f+7*0.5f)/8, (0.5882f+7*0.5f)/8, 1.0f); 108 | 109 | // Enable back face culling. 110 | glEnable(GL_CULL_FACE); 111 | 112 | glEnable(GL_DEPTH_TEST); 113 | glClearDepthf(1.0); 114 | glDepthFunc(GL_LEQUAL); 115 | 116 | float noAmbient[] = {1.0f, 1.0f, 1.0f, 1.0f}; 117 | glLightfv(GL_LIGHT0, GL_AMBIENT, noAmbient); 118 | glEnable(GL_LIGHT0); 119 | glEnable(GL_LIGHTING); 120 | 121 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); 122 | glEnableClientState(GL_VERTEX_ARRAY); 123 | 124 | // 縦横比の設定 125 | float ratio = (float)width / (float)height; 126 | glViewport(0, 0, (int)width, (int)height); 127 | 128 | // 行列演算のモード設定 129 | glMatrixMode(GL_PROJECTION); 130 | // 単位行列のロード 131 | glLoadIdentity(); 132 | // 透視投影の設定 133 | gluPerspective(40.0, ratio, 0.1, 100); 134 | 135 | caLoadObj(&m, "teapot.obj"); 136 | caCreateObject_GL1(vbo, &m); 137 | 138 | caKeyEvent = keyEvent; 139 | caMouseEvent = mouseEvent; 140 | } 141 | 142 | void caRender() 143 | { 144 | // 行列演算のモード設定 145 | glMatrixMode(GL_MODELVIEW); 146 | // 単位行列のロード 147 | glLoadIdentity(); 148 | // 平行移動 149 | glTranslatef(0.0, 0.0, -3.0); 150 | // 角度を演算 151 | angle = (angle + 2); 152 | if (angle >= 360) { 153 | angle = 0; 154 | } 155 | // 角度を設定 156 | glRotatef(angle, angle, angle, 1.0f); 157 | 158 | // バッファをクリアー 159 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 160 | caDrawObject(vbo, &m); 161 | } 162 | 163 | void caEnd() 164 | { 165 | caDeleteObject_GL1(vbo); 166 | caUnloadObj(&m); 167 | } 168 | -------------------------------------------------------------------------------- /sample/viewer_GL1/viewer_GL1-debug.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yui0/catgl/d6528aad417b114dd711cfa2968c183de1bbc8a0/sample/viewer_GL1/viewer_GL1-debug.apk --------------------------------------------------------------------------------