From 43549c8cab1bcfbefc2f061405f78d1de6a754f6 Mon Sep 17 00:00:00 2001 From: Marcel Plch Date: Fri, 27 Apr 2018 17:03:40 +0200 Subject: [PATCH] Functioning clock --- CMakeLists.txt | 2 +- Include/clock.h | 1 + Include/model.h | 10 +- clock.obj | 1057 +++++++++++++++++++ shaders/SimpleFragmentShader.fragmentshader | 19 +- shaders/SimpleVertexShader.vertexshader | 26 +- src/clock.c | 74 +- src/model.c | 81 +- 8 files changed, 1198 insertions(+), 72 deletions(-) create mode 100644 clock.obj diff --git a/CMakeLists.txt b/CMakeLists.txt index c208874..809bf2b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ set(ALL_LIBS GLEW ) -set(CMAKE_C_FLAGS "-O0 -ggdb") +set(CMAKE_C_FLAGS "-O0 -ggdb -lm") add_definitions( -DTW_STATIC diff --git a/Include/clock.h b/Include/clock.h index f5acaa1..f22f0f4 100644 --- a/Include/clock.h +++ b/Include/clock.h @@ -6,6 +6,7 @@ #include #include #include +#include #include // Include GLEW diff --git a/Include/model.h b/Include/model.h index df554bc..df7769b 100644 --- a/Include/model.h +++ b/Include/model.h @@ -1,12 +1,18 @@ #ifndef MODEL_LOADER_H #define MODEL_LOADER_H +typedef struct _entity { + size_t offset; + size_t size; +} Entity; + typedef struct _model { - GLfloat *buffer; + GLfloat *object; size_t bufsize; + Entity *entities[5]; } Model; -Model * model_load(const char *path); +Model * model_load(const char *); #endif diff --git a/clock.obj b/clock.obj new file mode 100644 index 0000000..98c2942 --- /dev/null +++ b/clock.obj @@ -0,0 +1,1057 @@ +# Blender v2.79 (sub 0) OBJ File: '' +# www.blender.org +o Text.011 +v -0.004195 0.411665 0.054248 +v 0.005051 0.476004 0.054248 +v -0.004195 0.476004 0.054248 +v 0.005051 0.411665 0.054248 +v -0.050232 0.444966 0.054248 +v -0.064760 0.476004 0.054248 +v -0.075986 0.476004 0.054248 +v -0.044572 0.451476 0.054248 +v -0.013345 0.476004 0.054248 +v -0.024477 0.476004 0.054248 +v -0.039006 0.444966 0.054248 +v -0.077967 0.411665 0.054248 +v -0.044572 0.438268 0.054248 +v -0.011553 0.411665 0.054248 +v -0.066741 0.411665 0.054248 +v -0.022685 0.411665 0.054248 +v 0.020068 0.411665 0.054248 +v 0.029314 0.476004 0.054248 +v 0.020068 0.476004 0.054248 +v 0.029314 0.411665 0.054248 +s off +f 1 2 3 +f 1 4 2 +f 5 6 7 +f 5 8 6 +f 8 9 10 +f 8 11 9 +f 5 11 8 +f 12 11 5 +f 12 13 11 +f 13 14 11 +f 12 15 13 +f 16 14 13 +f 17 18 19 +f 17 20 18 +o Text.010 +v -0.219180 0.305326 0.054248 +v -0.209934 0.369665 0.054248 +v -0.219180 0.369665 0.054248 +v -0.209934 0.305326 0.054248 +v -0.265217 0.338628 0.054248 +v -0.279745 0.369665 0.054248 +v -0.290971 0.369665 0.054248 +v -0.259557 0.345137 0.054248 +v -0.228330 0.369665 0.054248 +v -0.239462 0.369665 0.054248 +v -0.253991 0.338628 0.054248 +v -0.292952 0.305326 0.054248 +v -0.259557 0.331930 0.054248 +v -0.226538 0.305326 0.054248 +v -0.281726 0.305326 0.054248 +v -0.237670 0.305326 0.054248 +s off +f 21 22 23 +f 21 24 22 +f 25 26 27 +f 25 28 26 +f 28 29 30 +f 28 31 29 +f 25 31 28 +f 32 31 25 +f 32 33 31 +f 33 34 31 +f 32 35 33 +f 36 34 33 +o Text.009 +v -0.355334 0.201649 0.054248 +v -0.369862 0.232687 0.054248 +v -0.381089 0.232687 0.054248 +v -0.349674 0.208159 0.054248 +v -0.318448 0.232687 0.054248 +v -0.329580 0.232687 0.054248 +v -0.344108 0.201649 0.054248 +v -0.383070 0.168348 0.054248 +v -0.349674 0.194951 0.054248 +v -0.316655 0.168348 0.054248 +v -0.371844 0.168348 0.054248 +v -0.327787 0.168348 0.054248 +s off +f 37 38 39 +f 37 40 38 +f 40 41 42 +f 40 43 41 +f 37 43 40 +f 44 43 37 +f 44 45 43 +f 45 46 43 +f 44 47 45 +f 48 46 45 +o Text.008 +v -0.409251 0.005193 0.054248 +v -0.423779 0.036231 0.054248 +v -0.435005 0.036231 0.054248 +v -0.403590 0.011703 0.054248 +v -0.372364 0.036231 0.054248 +v -0.383496 0.036231 0.054248 +v -0.398024 0.005193 0.054248 +v -0.436986 -0.028108 0.054248 +v -0.403590 -0.001505 0.054248 +v -0.370572 -0.028108 0.054248 +v -0.425760 -0.028108 0.054248 +v -0.381704 -0.028108 0.054248 +v -0.453590 -0.028108 0.054248 +v -0.444345 0.036231 0.054248 +v -0.453590 0.036231 0.054248 +v -0.444345 -0.028108 0.054248 +s off +f 49 50 51 +f 49 52 50 +f 52 53 54 +f 52 55 53 +f 49 55 52 +f 56 55 49 +f 56 57 55 +f 57 58 55 +f 56 59 57 +f 60 58 57 +f 61 62 63 +f 61 64 62 +o Text.007 +v -0.277346 -0.217355 0.054248 +v -0.268101 -0.153016 0.054248 +v -0.277346 -0.153016 0.054248 +v -0.268101 -0.217355 0.054248 +v -0.300931 -0.217355 0.054248 +v -0.291685 -0.153016 0.054248 +v -0.300931 -0.153016 0.054248 +v -0.291685 -0.217355 0.054248 +v -0.324515 -0.217355 0.054248 +v -0.315270 -0.153016 0.054248 +v -0.324515 -0.153016 0.054248 +v -0.315270 -0.217355 0.054248 +v -0.360836 -0.217921 0.054248 +v -0.379420 -0.153016 0.054248 +v -0.388666 -0.153016 0.054248 +v -0.360081 -0.198204 0.054248 +v -0.331685 -0.153016 0.054248 +v -0.340836 -0.153016 0.054248 +v -0.358949 -0.217921 0.054248 +s off +f 65 66 67 +f 65 68 66 +f 69 70 71 +f 69 72 70 +f 73 74 75 +f 73 76 74 +f 77 78 79 +f 77 80 78 +f 80 81 82 +f 80 83 81 +f 77 83 80 +o Text.006 +v -0.171162 -0.386775 0.054248 +v -0.161916 -0.322436 0.054248 +v -0.171162 -0.322436 0.054248 +v -0.161916 -0.386775 0.054248 +v -0.194746 -0.386775 0.054248 +v -0.185501 -0.322436 0.054248 +v -0.194746 -0.322436 0.054248 +v -0.185501 -0.386775 0.054248 +v -0.231067 -0.387341 0.054248 +v -0.249651 -0.322436 0.054248 +v -0.258897 -0.322436 0.054248 +v -0.230312 -0.367625 0.054248 +v -0.201916 -0.322436 0.054248 +v -0.211067 -0.322436 0.054248 +v -0.229180 -0.387341 0.054248 +s off +f 84 85 86 +f 84 87 85 +f 88 89 90 +f 88 91 89 +f 92 93 94 +f 92 95 93 +f 95 96 97 +f 95 98 96 +f 92 98 95 +o Text.005 +v 0.037757 -0.451660 0.054248 +v 0.047002 -0.387321 0.054248 +v 0.037757 -0.387321 0.054248 +v 0.047002 -0.451660 0.054248 +v 0.001436 -0.452226 0.054248 +v -0.017148 -0.387321 0.054248 +v -0.026394 -0.387321 0.054248 +v 0.002191 -0.432509 0.054248 +v 0.030587 -0.387321 0.054248 +v 0.021436 -0.387321 0.054248 +v 0.003323 -0.452226 0.054248 +s off +f 99 100 101 +f 99 102 100 +f 103 104 105 +f 103 106 104 +f 106 107 108 +f 106 109 107 +f 103 109 106 +o Text.004 +v 0.235741 -0.362109 0.054248 +v 0.217157 -0.297204 0.054248 +v 0.207912 -0.297204 0.054248 +v 0.236496 -0.342392 0.054248 +v 0.264892 -0.297204 0.054248 +v 0.255741 -0.297204 0.054248 +v 0.237628 -0.362109 0.054248 +s off +f 110 111 112 +f 110 113 111 +f 113 114 115 +f 113 116 114 +f 110 116 113 +o Text.003 +v 0.389095 -0.219723 0.054248 +v 0.370510 -0.154818 0.054248 +v 0.361265 -0.154818 0.054248 +v 0.389850 -0.200006 0.054248 +v 0.418246 -0.154818 0.054248 +v 0.409095 -0.154818 0.054248 +v 0.390982 -0.219723 0.054248 +v 0.344850 -0.219157 0.054248 +v 0.354096 -0.154818 0.054248 +v 0.344850 -0.154818 0.054248 +v 0.354096 -0.219157 0.054248 +s off +f 117 118 119 +f 117 120 118 +f 120 121 122 +f 120 123 121 +f 117 123 120 +f 124 125 126 +f 124 127 125 +o Text.002 +v 0.456904 -0.033515 0.054248 +v 0.466149 0.030824 0.054248 +v 0.456904 0.030824 0.054248 +v 0.466149 -0.033515 0.054248 +v 0.433320 -0.033515 0.054248 +v 0.442565 0.030824 0.054248 +v 0.433320 0.030824 0.054248 +v 0.442565 -0.033515 0.054248 +v 0.409735 -0.033515 0.054248 +v 0.418980 0.030824 0.054248 +v 0.409735 0.030824 0.054248 +v 0.418980 -0.033515 0.054248 +s off +f 128 129 130 +f 128 131 129 +f 132 133 134 +f 132 135 133 +f 136 137 138 +f 136 139 137 +o Text.001 +v 0.386458 0.139510 0.054248 +v 0.395704 0.203849 0.054248 +v 0.386458 0.203849 0.054248 +v 0.395704 0.139510 0.054248 +v 0.362874 0.139510 0.054248 +v 0.372119 0.203849 0.054248 +v 0.362874 0.203849 0.054248 +v 0.372119 0.139510 0.054248 +s off +f 140 141 142 +f 140 143 141 +f 144 145 146 +f 144 147 145 +o Text +v 0.224093 0.319745 0.054248 +v 0.233338 0.384084 0.054248 +v 0.224093 0.384084 0.054248 +v 0.233338 0.319745 0.054248 +s off +f 148 149 150 +f 148 151 149 +o Sphere +v 0.000000 -0.097545 -0.490392 +v 0.090120 -0.191342 -0.453064 +v 0.000000 -0.191342 -0.461940 +v 0.000000 0.415735 -0.277785 +v 0.037329 0.461940 -0.187665 +v 0.054193 0.415735 -0.272448 +v 0.081106 -0.277785 -0.407747 +v 0.000000 -0.277785 -0.415734 +v 0.000000 0.353553 -0.353553 +v 0.068975 0.353553 -0.346760 +v 0.068975 -0.353553 -0.346760 +v 0.000000 -0.353553 -0.353553 +v 0.000000 0.277785 -0.415734 +v 0.081106 0.277785 -0.407747 +v 0.054193 -0.415735 -0.272448 +v 0.000000 -0.415735 -0.277785 +v 0.000000 0.191342 -0.461940 +v 0.090120 0.191342 -0.453064 +v 0.037329 -0.461940 -0.187665 +v 0.000000 -0.461940 -0.191341 +v 0.000000 0.097545 -0.490392 +v 0.095671 0.097545 -0.480970 +v 0.019030 -0.490393 -0.095671 +v 0.000000 -0.490393 -0.097545 +v 0.000000 0.000000 -0.500000 +v 0.097545 0.000000 -0.490393 +v 0.000000 0.490393 -0.097545 +v 0.000000 0.500000 0.000000 +v 0.019030 0.490393 -0.095671 +v 0.000000 -0.500000 -0.000000 +v 0.095671 -0.097545 -0.480970 +v 0.000000 0.461940 -0.191341 +v 0.191342 0.000000 -0.461940 +v 0.187665 -0.097545 -0.453064 +v 0.073223 0.461940 -0.176777 +v 0.176777 -0.191342 -0.426777 +v 0.106304 0.415735 -0.256640 +v 0.159095 -0.277785 -0.384089 +v 0.135299 0.353553 -0.326641 +v 0.135299 -0.353553 -0.326641 +v 0.159095 0.277785 -0.384089 +v 0.106304 -0.415735 -0.256640 +v 0.176777 0.191342 -0.426777 +v 0.073223 -0.461940 -0.176777 +v 0.187665 0.097545 -0.453064 +v 0.037329 -0.490393 -0.090120 +v 0.037329 0.490393 -0.090120 +v 0.196424 -0.353553 -0.293969 +v 0.154329 -0.415735 -0.230970 +v 0.256640 0.191342 -0.384089 +v 0.106304 -0.461940 -0.159095 +v 0.272448 0.097545 -0.407746 +v 0.054193 -0.490393 -0.081106 +v 0.277785 0.000000 -0.415735 +v 0.054193 0.490393 -0.081106 +v 0.272448 -0.097545 -0.407746 +v 0.106304 0.461940 -0.159095 +v 0.256640 -0.191342 -0.384089 +v 0.154329 0.415735 -0.230970 +v 0.230970 -0.277785 -0.345671 +v 0.196424 0.353553 -0.293969 +v 0.230970 0.277785 -0.345671 +v 0.068975 0.490393 -0.068975 +v 0.135299 0.461940 -0.135299 +v 0.326641 -0.191342 -0.326641 +v 0.196424 0.415735 -0.196424 +v 0.293969 -0.277785 -0.293969 +v 0.250000 0.353553 -0.250000 +v 0.250000 -0.353553 -0.250000 +v 0.293969 0.277785 -0.293969 +v 0.196424 -0.415735 -0.196424 +v 0.326641 0.191342 -0.326641 +v 0.135299 -0.461940 -0.135299 +v 0.346760 0.097545 -0.346760 +v 0.068975 -0.490393 -0.068975 +v 0.353554 0.000000 -0.353553 +v 0.346760 -0.097545 -0.346760 +v 0.384089 0.191342 -0.256640 +v 0.159095 -0.461940 -0.106304 +v 0.407747 0.097545 -0.272447 +v 0.081106 -0.490393 -0.054193 +v 0.415735 0.000000 -0.277785 +v 0.081106 0.490393 -0.054193 +v 0.407747 -0.097545 -0.272447 +v 0.159095 0.461940 -0.106304 +v 0.384089 -0.191342 -0.256640 +v 0.230970 0.415735 -0.154329 +v 0.345671 -0.277785 -0.230970 +v 0.293969 0.353553 -0.196424 +v 0.293969 -0.353553 -0.196424 +v 0.345671 0.277785 -0.230970 +v 0.230970 -0.415735 -0.154329 +v 0.426777 -0.191342 -0.176777 +v 0.256640 0.415735 -0.106304 +v 0.384089 -0.277785 -0.159095 +v 0.326641 0.353553 -0.135299 +v 0.326641 -0.353553 -0.135299 +v 0.384089 0.277785 -0.159095 +v 0.256640 -0.415735 -0.106304 +v 0.426777 0.191342 -0.176777 +v 0.176777 -0.461940 -0.073223 +v 0.453064 0.097545 -0.187665 +v 0.090120 -0.490393 -0.037329 +v 0.461940 0.000000 -0.191342 +v 0.090120 0.490393 -0.037329 +v 0.453064 -0.097545 -0.187665 +v 0.176777 0.461940 -0.073223 +v 0.187665 -0.461940 -0.037329 +v 0.453064 0.191342 -0.090120 +v 0.480970 0.097545 -0.095671 +v 0.095671 -0.490393 -0.019030 +v 0.490393 0.000000 -0.097545 +v 0.095671 0.490393 -0.019030 +v 0.480970 -0.097545 -0.095671 +v 0.187665 0.461940 -0.037329 +v 0.453064 -0.191342 -0.090120 +v 0.272448 0.415735 -0.054193 +v 0.407747 -0.277785 -0.081106 +v 0.346760 0.353553 -0.068975 +v 0.346760 -0.353553 -0.068975 +v 0.407747 0.277785 -0.081106 +v 0.272448 -0.415735 -0.054193 +v 0.461940 -0.191342 -0.000000 +v 0.415735 -0.277785 -0.000000 +v 0.353553 0.353553 0.000000 +v 0.353553 -0.353553 -0.000000 +v 0.415735 0.277785 0.000000 +v 0.277785 -0.415735 -0.000000 +v 0.461940 0.191342 0.000000 +v 0.191342 -0.461940 -0.000000 +v 0.490393 0.097545 0.000000 +v 0.097545 -0.490393 -0.000000 +v 0.500000 0.000000 0.000000 +v 0.097545 0.490393 0.000000 +v 0.490393 -0.097545 -0.000000 +v 0.191342 0.461940 0.000000 +v 0.277785 0.415735 0.000000 +v -0.415735 -0.277785 -0.000000 +v -0.346760 -0.353553 -0.068975 +v -0.353553 -0.353553 -0.000000 +v -0.353553 0.353553 0.000000 +v -0.407746 0.277785 -0.081106 +v -0.415735 0.277785 0.000000 +v -0.272447 -0.415735 -0.054193 +v -0.277785 -0.415735 -0.000000 +v -0.453064 0.191342 -0.090120 +v -0.461940 0.191342 0.000000 +v -0.191342 -0.461940 -0.000000 +v -0.187665 -0.461940 -0.037329 +v -0.490392 0.097545 0.000000 +v -0.480970 0.097545 -0.095671 +v -0.097545 -0.490393 -0.000000 +v -0.095671 -0.490393 -0.019030 +v -0.490393 0.000000 -0.097545 +v -0.500000 0.000000 0.000000 +v -0.097545 0.490393 0.000000 +v -0.095671 0.490393 -0.019030 +v -0.490392 -0.097545 -0.000000 +v -0.480970 -0.097545 -0.095671 +v -0.187665 0.461940 -0.037329 +v -0.191342 0.461940 0.000000 +v -0.453064 -0.191342 -0.090120 +v -0.461940 -0.191342 -0.000000 +v -0.272448 0.415735 -0.054193 +v -0.277785 0.415735 0.000000 +v -0.407746 -0.277785 -0.081106 +v -0.346760 0.353553 -0.068975 +v -0.090120 -0.490393 -0.037329 +v -0.461940 0.000000 -0.191342 +v -0.453063 -0.097545 -0.187665 +v -0.176777 0.461940 -0.073223 +v -0.426777 -0.191342 -0.176777 +v -0.256640 0.415735 -0.106304 +v -0.384089 -0.277785 -0.159095 +v -0.326641 0.353553 -0.135299 +v -0.326641 -0.353553 -0.135299 +v -0.384089 0.277785 -0.159095 +v -0.256640 -0.415735 -0.106304 +v -0.426777 0.191342 -0.176777 +v -0.176777 -0.461940 -0.073223 +v -0.453063 0.097545 -0.187665 +v -0.090120 0.490393 -0.037329 +v -0.230970 -0.415735 -0.154329 +v -0.384089 0.191342 -0.256640 +v -0.159095 -0.461940 -0.106304 +v -0.407746 0.097545 -0.272447 +v -0.081106 -0.490393 -0.054193 +v -0.415735 0.000000 -0.277785 +v -0.081106 0.490393 -0.054193 +v -0.407746 -0.097545 -0.272447 +v -0.159095 0.461940 -0.106304 +v -0.384089 -0.191342 -0.256640 +v -0.230970 0.415735 -0.154329 +v -0.345671 -0.277785 -0.230970 +v -0.293969 0.353553 -0.196424 +v -0.293969 -0.353553 -0.196424 +v -0.345671 0.277785 -0.230970 +v -0.135299 0.461940 -0.135299 +v -0.326641 -0.191342 -0.326641 +v -0.196424 0.415735 -0.196424 +v -0.293969 -0.277785 -0.293969 +v -0.250000 0.353553 -0.250000 +v -0.250000 -0.353553 -0.250000 +v -0.293969 0.277785 -0.293969 +v -0.196424 -0.415735 -0.196424 +v -0.326641 0.191342 -0.326641 +v -0.135299 -0.461940 -0.135299 +v -0.346760 0.097545 -0.346760 +v -0.068975 -0.490393 -0.068975 +v -0.353553 0.000000 -0.353553 +v -0.068975 0.490393 -0.068975 +v -0.346760 -0.097545 -0.346760 +v -0.256640 0.191342 -0.384089 +v -0.154329 -0.415735 -0.230970 +v -0.106304 -0.461940 -0.159095 +v -0.272447 0.097545 -0.407746 +v -0.054193 -0.490393 -0.081106 +v -0.277785 0.000000 -0.415735 +v -0.054193 0.490393 -0.081106 +v -0.272447 -0.097545 -0.407746 +v -0.106304 0.461940 -0.159095 +v -0.256640 -0.191342 -0.384089 +v -0.154329 0.415735 -0.230970 +v -0.230970 -0.277785 -0.345671 +v -0.196424 0.353553 -0.293969 +v -0.196424 -0.353553 -0.293969 +v -0.230970 0.277785 -0.345671 +v -0.176777 -0.191342 -0.426776 +v -0.073223 0.461940 -0.176776 +v -0.106304 0.415735 -0.256640 +v -0.159095 -0.277785 -0.384089 +v -0.135299 0.353553 -0.326641 +v -0.135299 -0.353553 -0.326641 +v -0.159095 0.277785 -0.384089 +v -0.106304 -0.415735 -0.256640 +v -0.176777 0.191342 -0.426776 +v -0.073223 -0.461940 -0.176776 +v -0.187665 0.097545 -0.453063 +v -0.037329 -0.490393 -0.090120 +v -0.191342 0.000000 -0.461939 +v -0.037329 0.490393 -0.090120 +v -0.187665 -0.097545 -0.453063 +v -0.037329 -0.461940 -0.187665 +v -0.090120 0.191342 -0.453063 +v -0.095671 0.097545 -0.480969 +v -0.019030 -0.490393 -0.095671 +v -0.097545 0.000000 -0.490392 +v -0.019030 0.490393 -0.095671 +v -0.095671 -0.097545 -0.480969 +v -0.037329 0.461940 -0.187665 +v -0.090120 -0.191342 -0.453063 +v -0.054193 0.415735 -0.272447 +v -0.081106 -0.277785 -0.407746 +v -0.068975 0.353553 -0.346760 +v -0.068975 -0.353553 -0.346760 +v -0.081106 0.277785 -0.407746 +v -0.054193 -0.415735 -0.272447 +s off +f 152 153 154 +f 155 156 157 +f 154 158 159 +f 160 157 161 +f 159 162 163 +f 164 161 165 +f 163 166 167 +f 168 165 169 +f 167 170 171 +f 172 169 173 +f 171 174 175 +f 176 173 177 +f 178 179 180 +f 181 175 174 +f 176 182 152 +f 183 180 156 +f 182 184 185 +f 180 186 156 +f 182 187 153 +f 156 188 157 +f 153 189 158 +f 157 190 161 +f 162 189 191 +f 161 192 165 +f 166 191 193 +f 165 194 169 +f 166 195 170 +f 169 196 173 +f 174 195 197 +f 173 184 177 +f 180 179 198 +f 181 174 197 +f 193 199 200 +f 192 201 194 +f 195 200 202 +f 194 203 196 +f 195 204 197 +f 196 205 184 +f 198 179 206 +f 181 197 204 +f 184 207 185 +f 198 208 186 +f 185 209 187 +f 186 210 188 +f 189 209 211 +f 188 212 190 +f 189 199 191 +f 190 213 192 +f 208 214 215 +f 207 216 209 +f 208 217 210 +f 211 216 218 +f 210 219 212 +f 211 220 199 +f 213 219 221 +f 199 222 200 +f 213 223 201 +f 200 224 202 +f 201 225 203 +f 202 226 204 +f 203 227 205 +f 206 179 214 +f 181 204 226 +f 205 228 207 +f 221 229 223 +f 222 230 224 +f 225 229 231 +f 226 230 232 +f 227 231 233 +f 214 179 234 +f 181 226 232 +f 227 235 228 +f 214 236 215 +f 228 237 216 +f 215 238 217 +f 218 237 239 +f 217 240 219 +f 218 241 220 +f 221 240 242 +f 220 243 222 +f 235 244 237 +f 236 245 238 +f 239 244 246 +f 238 247 240 +f 239 248 241 +f 240 249 242 +f 243 248 250 +f 242 251 229 +f 243 252 230 +f 231 251 253 +f 230 254 232 +f 231 255 233 +f 234 179 256 +f 181 232 254 +f 233 257 235 +f 234 258 236 +f 250 259 252 +f 253 260 261 +f 252 262 254 +f 253 263 255 +f 256 179 264 +f 181 254 262 +f 255 265 257 +f 256 266 258 +f 257 267 244 +f 258 268 245 +f 246 267 269 +f 245 270 247 +f 248 269 271 +f 247 272 249 +f 250 271 273 +f 249 260 251 +f 269 274 275 +f 268 276 270 +f 271 275 277 +f 270 278 272 +f 273 277 279 +f 272 280 260 +f 273 281 259 +f 261 280 282 +f 262 281 283 +f 261 284 263 +f 264 179 285 +f 181 262 283 +f 263 286 265 +f 264 287 266 +f 265 274 267 +f 266 288 268 +f 289 290 291 +f 292 293 294 +f 291 295 296 +f 294 297 298 +f 299 295 300 +f 301 297 302 +f 303 300 304 +f 301 305 306 +f 307 179 308 +f 181 303 304 +f 309 305 310 +f 307 311 312 +f 309 313 314 +f 312 315 316 +f 289 313 317 +f 292 315 318 +f 181 304 319 +f 310 320 321 +f 308 322 311 +f 310 323 313 +f 315 322 324 +f 317 323 325 +f 318 324 326 +f 317 327 290 +f 318 328 293 +f 290 329 295 +f 293 330 297 +f 300 329 331 +f 302 330 332 +f 300 319 304 +f 302 320 305 +f 308 179 333 +f 327 334 329 +f 328 335 330 +f 329 336 331 +f 332 335 337 +f 331 338 319 +f 332 339 320 +f 333 179 340 +f 181 319 338 +f 320 341 321 +f 322 340 342 +f 321 343 323 +f 322 344 324 +f 325 343 345 +f 326 344 346 +f 325 347 327 +f 328 346 348 +f 340 349 342 +f 341 350 343 +f 344 349 351 +f 345 350 352 +f 346 351 353 +f 345 354 347 +f 348 353 355 +f 347 356 334 +f 348 357 335 +f 334 358 336 +f 337 357 359 +f 336 360 338 +f 337 361 339 +f 340 179 362 +f 181 338 360 +f 341 361 363 +f 355 364 357 +f 358 365 366 +f 359 364 367 +f 358 368 360 +f 361 367 369 +f 362 179 370 +f 181 360 368 +f 361 371 363 +f 349 370 372 +f 363 373 350 +f 349 374 351 +f 352 373 375 +f 351 376 353 +f 352 377 354 +f 355 376 378 +f 354 365 356 +f 371 379 373 +f 374 380 381 +f 375 379 382 +f 374 383 376 +f 375 384 377 +f 378 383 385 +f 365 384 386 +f 378 387 364 +f 366 386 388 +f 367 387 389 +f 366 390 368 +f 367 391 369 +f 370 179 392 +f 181 368 390 +f 371 391 393 +f 370 380 372 +f 386 394 388 +f 389 395 396 +f 388 397 390 +f 389 398 391 +f 392 179 399 +f 181 390 397 +f 391 400 393 +f 392 401 380 +f 393 402 379 +f 380 403 381 +f 382 402 404 +f 381 405 383 +f 382 406 384 +f 385 405 407 +f 386 406 408 +f 385 395 387 +f 401 155 403 +f 404 154 159 +f 405 155 160 +f 404 163 406 +f 407 160 164 +f 408 163 167 +f 407 168 395 +f 408 171 394 +f 396 168 172 +f 394 175 397 +f 396 176 398 +f 399 179 178 +f 181 397 175 +f 398 152 400 +f 401 178 183 +f 400 154 402 +f 152 182 153 +f 155 183 156 +f 154 153 158 +f 160 155 157 +f 159 158 162 +f 164 160 161 +f 163 162 166 +f 168 164 165 +f 167 166 170 +f 172 168 169 +f 171 170 174 +f 176 172 173 +f 176 177 182 +f 183 178 180 +f 182 177 184 +f 180 198 186 +f 182 185 187 +f 156 186 188 +f 153 187 189 +f 157 188 190 +f 162 158 189 +f 161 190 192 +f 166 162 191 +f 165 192 194 +f 166 193 195 +f 169 194 196 +f 174 170 195 +f 173 196 184 +f 193 191 199 +f 192 213 201 +f 195 193 200 +f 194 201 203 +f 195 202 204 +f 196 203 205 +f 184 205 207 +f 198 206 208 +f 185 207 209 +f 186 208 210 +f 189 187 209 +f 188 210 212 +f 189 211 199 +f 190 212 213 +f 208 206 214 +f 207 228 216 +f 208 215 217 +f 211 209 216 +f 210 217 219 +f 211 218 220 +f 213 212 219 +f 199 220 222 +f 213 221 223 +f 200 222 224 +f 201 223 225 +f 202 224 226 +f 203 225 227 +f 205 227 228 +f 221 242 229 +f 222 243 230 +f 225 223 229 +f 226 224 230 +f 227 225 231 +f 227 233 235 +f 214 234 236 +f 228 235 237 +f 215 236 238 +f 218 216 237 +f 217 238 240 +f 218 239 241 +f 221 219 240 +f 220 241 243 +f 235 257 244 +f 236 258 245 +f 239 237 244 +f 238 245 247 +f 239 246 248 +f 240 247 249 +f 243 241 248 +f 242 249 251 +f 243 250 252 +f 231 229 251 +f 230 252 254 +f 231 253 255 +f 233 255 257 +f 234 256 258 +f 250 273 259 +f 253 251 260 +f 252 259 262 +f 253 261 263 +f 255 263 265 +f 256 264 266 +f 257 265 267 +f 258 266 268 +f 246 244 267 +f 245 268 270 +f 248 246 269 +f 247 270 272 +f 250 248 271 +f 249 272 260 +f 269 267 274 +f 268 288 276 +f 271 269 275 +f 270 276 278 +f 273 271 277 +f 272 278 280 +f 273 279 281 +f 261 260 280 +f 262 259 281 +f 261 282 284 +f 263 284 286 +f 264 285 287 +f 265 286 274 +f 266 287 288 +f 289 317 290 +f 292 318 293 +f 291 290 295 +f 294 293 297 +f 299 296 295 +f 301 298 297 +f 303 299 300 +f 301 302 305 +f 309 306 305 +f 307 308 311 +f 309 310 313 +f 312 311 315 +f 289 314 313 +f 292 316 315 +f 310 305 320 +f 308 333 322 +f 310 321 323 +f 315 311 322 +f 317 313 323 +f 318 315 324 +f 317 325 327 +f 318 326 328 +f 290 327 329 +f 293 328 330 +f 300 295 329 +f 302 297 330 +f 300 331 319 +f 302 332 320 +f 327 347 334 +f 328 348 335 +f 329 334 336 +f 332 330 335 +f 331 336 338 +f 332 337 339 +f 320 339 341 +f 322 333 340 +f 321 341 343 +f 322 342 344 +f 325 323 343 +f 326 324 344 +f 325 345 347 +f 328 326 346 +f 340 362 349 +f 341 363 350 +f 344 342 349 +f 345 343 350 +f 346 344 351 +f 345 352 354 +f 348 346 353 +f 347 354 356 +f 348 355 357 +f 334 356 358 +f 337 335 357 +f 336 358 360 +f 337 359 361 +f 341 339 361 +f 355 378 364 +f 358 356 365 +f 359 357 364 +f 358 366 368 +f 361 359 367 +f 361 369 371 +f 349 362 370 +f 363 371 373 +f 349 372 374 +f 352 350 373 +f 351 374 376 +f 352 375 377 +f 355 353 376 +f 354 377 365 +f 371 393 379 +f 374 372 380 +f 375 373 379 +f 374 381 383 +f 375 382 384 +f 378 376 383 +f 365 377 384 +f 378 385 387 +f 366 365 386 +f 367 364 387 +f 366 388 390 +f 367 389 391 +f 371 369 391 +f 370 392 380 +f 386 408 394 +f 389 387 395 +f 388 394 397 +f 389 396 398 +f 391 398 400 +f 392 399 401 +f 393 400 402 +f 380 401 403 +f 382 379 402 +f 381 403 405 +f 382 404 406 +f 385 383 405 +f 386 384 406 +f 385 407 395 +f 401 183 155 +f 404 402 154 +f 405 403 155 +f 404 159 163 +f 407 405 160 +f 408 406 163 +f 407 164 168 +f 408 167 171 +f 396 395 168 +f 394 171 175 +f 396 172 176 +f 398 176 152 +f 401 399 178 +f 400 152 154 +o Sec_Plane +v 0.007589 -0.018388 0.120824 +v -0.007589 0.348706 0.120824 +v -0.007589 -0.018388 0.120824 +v 0.022687 0.348706 0.120824 +v -0.022687 0.348706 0.120824 +v 0.000000 0.451929 0.120824 +v 0.007589 0.348706 0.120824 +s off +f 409 410 411 +f 410 412 413 +f 413 412 414 +f 409 415 410 +f 410 415 412 +o Hrs_Plane.001 +v 0.031070 -0.009043 0.095341 +v -0.031070 0.171492 0.095341 +v -0.031070 -0.009043 0.095341 +v 0.092879 0.171492 0.095341 +v -0.092879 0.171492 0.095341 +v 0.000000 0.222256 0.095341 +v 0.031070 0.171492 0.095341 +s off +f 416 417 418 +f 417 419 420 +f 420 419 421 +f 416 422 417 +f 417 422 419 +o mins_Plane.002 +v 0.017950 -0.017662 0.108768 +v -0.017950 0.334939 0.108768 +v -0.017950 -0.017662 0.108768 +v 0.053659 0.334939 0.108768 +v -0.053659 0.334939 0.108768 +v 0.000000 0.434087 0.108768 +v 0.017950 0.334939 0.108768 +s off +f 423 424 425 +f 424 426 427 +f 427 426 428 +f 423 429 424 +f 424 429 426 diff --git a/shaders/SimpleFragmentShader.fragmentshader b/shaders/SimpleFragmentShader.fragmentshader index 26db610..463a7cb 100644 --- a/shaders/SimpleFragmentShader.fragmentshader +++ b/shaders/SimpleFragmentShader.fragmentshader @@ -1,8 +1,11 @@ -#version 330 core - -out vec3 color; - -void main() { - color = vec3(1, 0, 0); - -} +#version 330 core + +in float colorF; +out vec3 color; + +void main() { + if (colorF == 0) + color = vec3(1, 1, 1); + else + color = vec3(0, 0, 0); +} diff --git a/shaders/SimpleVertexShader.vertexshader b/shaders/SimpleVertexShader.vertexshader index 8afde95..7a94262 100644 --- a/shaders/SimpleVertexShader.vertexshader +++ b/shaders/SimpleVertexShader.vertexshader @@ -1,12 +1,14 @@ -#version 330 core - -// Input vertex data, different for all executions of this shader. -layout(location = 0) in vec3 vertexPosition_modelspace; - -void main(){ - - gl_Position.xyz = vertexPosition_modelspace; - gl_Position.w = 1.0; - -} - +#version 330 core + +// Input vertex data, different for all executions of this shader. +layout(location = 0) in vec4 position; +out float colorF; + +void main() { + if (position.z <= 0.0) + colorF = 0; + else + colorF = 1; + + gl_Position = position; +} diff --git a/src/clock.c b/src/clock.c index ff80fb0..4dd588c 100644 --- a/src/clock.c +++ b/src/clock.c @@ -64,17 +64,17 @@ clock_run(GLFWwindow *window) { 0.0f, 0.3f, 0.0f, 1.0f }; Model *model; - model = model_load("../cube.obj"); + model = model_load("../clock.obj"); GLuint vertexbuffer; glGenBuffers(1, &vertexbuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); - glBufferData(GL_ARRAY_BUFFER, model->bufsize*4*sizeof(GLfloat), model->buffer, GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, model->bufsize*4*sizeof(GLfloat), model->object, GL_STATIC_DRAW); double xpos, ypos; glfwGetCursorPos(window, &xpos, &ypos); - GLfloat **matrices = malloc(2 * sizeof(GLfloat *)); + GLfloat **matrices = malloc(4 * sizeof(GLfloat *)); GLfloat *temp = matrix_new(); @@ -84,34 +84,36 @@ clock_run(GLFWwindow *window) { //temp[5] = cos(M_PI*2/60); matrices[0] = temp; - temp = matrix_new(); + time_t t = time(NULL); + for (int i = 1; i < 4; i++) { + temp = matrix_new(); - temp[0] = cos(M_PI*2/60/4); - temp[8] = -sin(M_PI*2/60/4); - temp[2] = sin(M_PI*2/60/4); - temp[10] = cos(M_PI*2/60/4); + temp[0] = cos(M_PI*2/60*(t%60)); + temp[4] = -sin(M_PI*2/60*(t%60)); + temp[1] = sin(M_PI*2/60*(t%60)); + temp[5] = cos(M_PI*2/60*(t%60)); - matrices[1] = temp; - - GLfloat *mat = matrix_new(); - - for (int i = 1; i >= 0; i--) { - temp = matrix_multip(matrices[i], mat); - free(mat); - mat = temp; + matrices[i] = temp; + t /= 60; } + GLfloat *projection = matrix_new(); GLfloat *buffer; projection[14] = -1.0f; buffer = matrix_new(); buffer[0] = (GLfloat)9/16; temp = matrix_multip(projection, buffer); + free(buffer); free(projection); - projection = buffer; + projection = temp; temp = malloc(model->bufsize * 4 * sizeof(GLfloat)); buffer = malloc(model->bufsize * 4 * sizeof(GLfloat)); - memcpy(temp, model->buffer, model->bufsize * 4 * sizeof(GLfloat)); + memcpy(temp, model->object, model->bufsize * 4 * sizeof(GLfloat)); + + GLfloat *orig; + orig = malloc(model->bufsize * 4 * sizeof(GLfloat)); + memcpy(orig, model->object, model->bufsize * 4 * sizeof(GLfloat)); do { // Clear the screen. It's not mentioned before Tutorial 02, @@ -129,18 +131,35 @@ clock_run(GLFWwindow *window) { //g_vertex_buffer_data[6] = (float)xpos / 1280 * 2 - 1; //g_vertex_buffer_data[7] = 2 - (float)ypos / 720 * 2 - 1 + 0.15; - buffer = matrix_transform(temp, model->bufsize, mat); - free(temp); - temp = buffer; - buffer = matrix_transform(buffer, model->bufsize, projection); - memcpy(model->buffer, buffer, model->bufsize * 4 * sizeof(GLfloat)); + time_t t = time(NULL); + for (int i = 1; i < 4; i++) { + GLfloat *temp_mat; + temp_mat = matrix_new(); + + temp_mat[0] = cos(M_PI*2/60*(t%60)); + temp_mat[4] = -sin(M_PI*2/60*(t%60)); + temp_mat[1] = sin(M_PI*2/60*(t%60)); + temp_mat[5] = cos(M_PI*2/60*(t%60)); + + matrices[i] = temp_mat; + t /= 60; + } + for (int i = 2; i < 5; i++) { + GLfloat *slice; + slice = matrix_transform(&(orig[model->entities[i]->offset]), model->entities[i]->size, matrices[i-1]); + memcpy(&(temp[model->entities[i]->offset]), slice, model->entities[i]->size* 4 * sizeof(GLfloat)); + free(slice); + } free(buffer); + buffer = matrix_transform(temp, model->bufsize, projection); + memcpy(model->object, buffer, model->bufsize * 4 * sizeof(GLfloat)); GLuint vertexbuffer; glGenBuffers(1, &vertexbuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); - glBufferData(GL_ARRAY_BUFFER, model->bufsize * 4 * sizeof(GLfloat), model->buffer, GL_STATIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, model->bufsize * 4 * sizeof(GLfloat), model->object, GL_STATIC_DRAW); + // 1rst attribute buffer : vertices glEnableVertexAttribArray(0); @@ -154,7 +173,8 @@ clock_run(GLFWwindow *window) { NULL // array buffer offset ); - // Draw the triangle ! + + // Draw! glDrawArrays(GL_TRIANGLES, 0, model->bufsize); // 3 indices starting at 0 -> 1 triangle glDisableVertexAttribArray(0); @@ -166,10 +186,10 @@ clock_run(GLFWwindow *window) { // Check if the ESC key was pressed or the window was closed usleep(1000000/60); } while(glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && - glfwWindowShouldClose(window) == 0); + !glfwWindowShouldClose(window)); // Close OpenGL window and terminate GLFW - for (int i = 0; i < 2; i++) { + for (int i = 0; i < 4; i++) { free(matrices[i]); } free(matrices); diff --git a/src/model.c b/src/model.c index 8cad5ae..c56743d 100644 --- a/src/model.c +++ b/src/model.c @@ -3,32 +3,42 @@ Model * model_new(size_t size) { Model *model = calloc(1, sizeof(Model)); - model->buffer = calloc((size ? size : 1) *4 , sizeof(GLfloat)); + model->object = calloc((size ? size : 1) *4 , sizeof(GLfloat)); model->bufsize = size; + for (int i = 0; i < 5; i++) { + model->entities[i] = calloc(1, sizeof(Entity)); + } } void model_free(Model *self) { - free(self->buffer); + free(self->object); free(self); + for (int i = 0; i < 5; i++) { + free(self->entities[i]); + } } Model * model_load(const char *path) { Model *model; GLfloat *vertices; - int *faces; - size_t vertcount, facecount; - char type, check, *line; + int **faces; + size_t vertcount, facecount[5] = {0}; + char type, check, *buffer; FILE *f; + GLfloat colorset[3]; + size_t entity_read; f = fopen(path, "r"); - line = malloc(255); + buffer = malloc(255); vertices = malloc(3 * sizeof(GLfloat)); - faces = malloc(3 * sizeof(int)); + faces = malloc(5*sizeof(int *)); + for (int i = 0; i < 5; i++) { + faces[i] = malloc(3 * sizeof(int)); + } type = 0; vertcount = 0; - facecount = 0; do { check = fscanf(f, "%c", &type); @@ -43,11 +53,29 @@ model_load(const char *path) { vertcount++; } else if (type == 'f') { - faces = realloc(faces, (facecount+1)*3*sizeof(GLfloat)); - check = fscanf(f, "%d %d %d\n", &(faces[facecount*3]), - &(faces[facecount*3+1]), - &(faces[facecount*3+2])); - facecount++; + faces[entity_read] = realloc(faces[entity_read], (facecount[entity_read]+1)*3*sizeof(GLfloat)); + check = fscanf(f, "%d %d %d\n", &(faces[entity_read][facecount[entity_read]*3]), + &(faces[entity_read][facecount[entity_read]*3+1]), + &(faces[entity_read][facecount[entity_read]*3+2])); + facecount[entity_read]++; + } + else if (type == 'o') { + check = fscanf(f, "%s\n", buffer); + if (strstr(buffer, "Sphere")) { + entity_read = 0; + } + else if (strstr(buffer, "Text")) { + entity_read = 1; + } + else if (strstr(buffer, "Sec")) { + entity_read = 2; + } + else if (strstr(buffer, "Min")) { + entity_read = 3; + } + else if (strstr(buffer, "Hrs")) { + entity_read = 4; + } } else { check = fscanf(f, "%*[^\n]\n", NULL); @@ -55,16 +83,25 @@ model_load(const char *path) { } } while(check != EOF); - model = model_new(facecount*3); - for (int i = 0; i < facecount; i++) { - for (int j = 0; j < 3; j++) { - for (int k = 0; k < 3; k++) { - model->buffer[i*12+j*4+k] = vertices[(faces[i*3+j]-1)*3+k]; - } - model->buffer[i*12+j*4+3] = 1; - } + int total_facecount = 0; + for (int i = 0; i < 5; i++) { + total_facecount += facecount[i]; + } + model = model_new(total_facecount*3); + int offset = 0; + for (int ent = 0; ent < 5; ent++) { + model->entities[ent]->offset = offset; + for (int i = 0; i < facecount[ent]; i++) { + for (int j = 0; j < 3; j++) { + for (int k = 0; k < 3; k++) { + model->object[i*12+j*4+k+offset] = vertices[(faces[ent][i*3+j]-1)*3+k]; + } + model->object[i*12+j*4+3+offset] = 1; + } + } + offset += facecount[ent]*4*3; + model->entities[ent]->size = facecount[ent]*3; } - return model; }