summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2010-02-09 11:38:58 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2010-02-09 11:38:58 +0100
commit19b6628549c8b80f23976d9b42f2cd853989422c (patch)
tree3d8ad793b39c0e96b3bb6d6ca7e0a2555a17a803
Initial commit.
-rw-r--r--.gitignore3
-rw-r--r--SConstruct8
-rw-r--r--camera_para.datbin0 -> 136 bytes
-rwxr-xr-xfoo.cpp180
-rw-r--r--foo.pngbin0 -> 212146 bytes
-rw-r--r--patt.head196
-rwxr-xr-xpatt.hiro196
-rwxr-xr-xtexture.cpp25
-rwxr-xr-xtexture.h13
-rwxr-xr-xtexturepng.cpp45
-rwxr-xr-xtexturepng.h8
11 files changed, 674 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0731c13
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+.*
+*.o
+foo \ No newline at end of file
diff --git a/SConstruct b/SConstruct
new file mode 100644
index 0000000..1040b0c
--- /dev/null
+++ b/SConstruct
@@ -0,0 +1,8 @@
+env = Environment(
+ CPPFLAGS = '-m32',
+ LINKFLAGS = '-m32',
+ LIBS = ['ARgsub', 'ARvideo', 'AR', 'png'],
+ FRAMEWORKS = ['GLUT', 'OpenGL', 'QuickTime', 'Carbon', 'AppKit'],
+)
+
+env.Program('foo', ['foo.cpp', 'texture.cpp', 'texturepng.cpp'])
diff --git a/camera_para.dat b/camera_para.dat
new file mode 100644
index 0000000..eb671b1
--- /dev/null
+++ b/camera_para.dat
Binary files differ
diff --git a/foo.cpp b/foo.cpp
new file mode 100755
index 0000000..c924245
--- /dev/null
+++ b/foo.cpp
@@ -0,0 +1,180 @@
+#ifndef __APPLE__
+#include <GL/gl.h>
+#include <GL/glut.h>
+#else
+#include <OpenGL/gl.h>
+#include <GLUT/glut.h>
+#endif
+#include <AR/gsub.h>
+#include <AR/video.h>
+#include <AR/param.h>
+#include <AR/ar.h>
+
+#include <stdexcept>
+#include <iostream>
+
+#include "texturepng.h"
+
+class Pattern {
+ private:
+ double patt_width;
+ double patt_center[2];
+ int patt_id;
+ double patt_trans_kake[3][4];
+
+ Texture* tex;
+
+ public:
+ Pattern() {
+ patt_width = 10.0;
+ patt_center[0] = 0.0;
+ patt_center[1] = 0.0;
+
+ patt_id = arLoadPatt("patt.head");
+
+ tex = new TexturePNG("foo.png");
+ }
+
+ void update(ARMarkerInfo* marker_info, int marker_num) {
+ for(int j = 0; j < marker_num; j++) {
+ if( patt_id == marker_info[j].id ) {
+ arGetTransMat(&marker_info[j], patt_center, patt_width, patt_trans_kake);
+ draw();
+ //else if( marker_info[k].cf < marker_info[j].cf ) k = j;
+ }
+ }
+ }
+
+ void draw() {
+ double gl_para[16];
+ argConvGlpara(patt_trans_kake, gl_para);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadMatrixd(gl_para);
+
+ glTranslatef(0.0, -8.0, 0.0);
+
+ glBindTexture(GL_TEXTURE_2D, tex->tex());
+ glBegin(GL_QUADS);
+ glTexCoord2f(0, 1);
+ glVertex3f(-30, -30, 0);
+ glTexCoord2f(0, 0);
+ glVertex3f(-30, 30, 0);
+ glTexCoord2f(1, 0);
+ glVertex3f(30, 30, 0);
+ glTexCoord2f(1, 1);
+ glVertex3f(30, -30, 0);
+ glEnd();
+ }
+};
+
+Pattern* patt;
+
+static void init() {
+ ARParam wparam;
+
+ // Open video device.
+ if(arVideoOpen(NULL) < 0) {
+ throw(std::runtime_error("arVideoOpen() failed."));
+ }
+
+ // Find the size of the window.
+ int xsize, ysize;
+ if(arVideoInqSize(&xsize, &ysize) < 0) {
+ throw(std::runtime_error("arVideoInqSize() failed."));
+ }
+
+ std::cout << "Image size (x, y) = (" << xsize << ", " << ysize << ")" << std::endl;
+
+ // Set the initial camera parameters.
+ ARParam cparam;
+ if(arParamLoad("camera_para.dat", 1, &wparam) < 0) {
+ throw(std::runtime_error("arParamLoad() failed."));
+ }
+
+ arParamChangeSize(&wparam, xsize, ysize, &cparam);
+ arInitCparam(&cparam);
+ std::cout << "*** Camera Parameters ***" << std::endl;
+ arParamDisp(&cparam);
+
+ // Open the graphics window.
+ argInit(&cparam, 1.0, 0, 0, 0, 0);
+
+ // Texturing
+ glEnable(GL_TEXTURE_2D);
+ // Blending
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+ // Smooth shading
+ glShadeModel(GL_SMOOTH);
+
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
+}
+
+static void cleanup(void) {
+ arVideoCapStop();
+ arVideoClose();
+ argCleanup();
+}
+
+int count = 0;
+
+static void key_event(unsigned char key, int x, int y) {
+ switch(key) {
+ case 0x1b:
+ printf("*** %f (frame/sec)\n", (double)count/arUtilTimer());
+ cleanup();
+ exit(0);
+ }
+}
+
+static void main_loop(void) {
+ ARUint8 *dataPtr;
+
+ if((dataPtr = (ARUint8 *)arVideoGetImage()) == NULL) {
+ arUtilSleep(10);
+ return;
+ }
+
+ if(count == 0) arUtilTimerReset();
+ count++;
+
+ argDrawMode2D();
+ argDispImage(dataPtr, 0, 0);
+
+ ARMarkerInfo* marker_info;
+ int marker_num;
+
+ if(arDetectMarker(dataPtr, 100, &marker_info, &marker_num) < 0) {
+ throw(std::runtime_error("arDetectMarker() failed."));
+ }
+
+ argDrawMode3D();
+ argDraw3dCamera( 0, 0 );
+ glClearDepth( 1.0 );
+ glClear(GL_DEPTH_BUFFER_BIT);
+ glEnable(GL_DEPTH_TEST);
+ glDepthFunc(GL_LEQUAL);
+
+ patt->update(marker_info, marker_num);
+
+ glDisable( GL_DEPTH_TEST );
+
+ arVideoCapNext();
+ argSwapBuffers();
+}
+
+int main(int argc, char **argv)
+{
+ try {
+ glutInit(&argc, argv);
+ init();
+ patt = new Pattern();
+ arVideoCapStart();
+ argMainLoop( NULL, key_event, main_loop );
+ } catch(std::runtime_error e) {
+ cleanup();
+ std::cerr << "Exception caught: " << e.what() << std::endl;
+ }
+ return 0;
+}
diff --git a/foo.png b/foo.png
new file mode 100644
index 0000000..bdef43c
--- /dev/null
+++ b/foo.png
Binary files differ
diff --git a/patt.head b/patt.head
new file mode 100644
index 0000000..0c22b41
--- /dev/null
+++ b/patt.head
@@ -0,0 +1,196 @@
+ 60 68 57 77 84 69 56 70 71 63 63 70 63 54 52 52
+ 151 193 178 172 199 189 173 156 189 179 174 153 165 159 156 111
+ 155 211 191 199 208 213 213 211 209 212 212 190 167 121 194 151
+ 121 217 78 83 210 209 212 214 209 213 204 152 61 83 215 148
+ 131 185 47 38 46 160 211 207 212 213 208 113 71 142 229 192
+ 149 181 78 37 36 87 207 213 209 208 164 75 84 175 206 190
+ 138 204 151 50 42 54 159 224 204 189 93 64 73 182 204 172
+ 132 206 197 99 62 56 72 189 204 167 74 57 129 209 210 157
+ 147 202 200 206 143 67 66 100 190 112 74 86 197 214 212 208
+ 182 214 212 210 196 72 62 69 73 66 60 113 212 213 211 207
+ 142 218 211 209 206 154 72 55 49 54 62 191 223 209 207 206
+ 132 214 211 210 211 208 108 55 49 51 69 174 209 208 207 209
+ 154 205 210 206 207 210 162 38 50 51 102 213 211 211 210 212
+ 163 204 211 211 210 210 208 117 48 70 185 216 211 213 208 210
+ 126 203 206 211 213 210 209 194 78 105 212 209 211 212 210 210
+ 156 204 209 203 206 208 215 210 191 179 206 206 208 211 207 212
+ 46 49 48 59 63 50 45 52 52 47 46 50 47 46 45 45
+ 115 180 170 163 198 191 169 146 198 191 170 135 168 153 146 98
+ 124 204 193 197 206 209 208 208 208 211 207 194 167 106 182 146
+ 90 197 96 77 192 207 210 212 213 209 209 159 63 66 195 129
+ 115 178 49 30 39 155 210 211 209 212 211 102 48 120 209 180
+ 145 185 85 30 36 70 201 213 212 213 168 63 66 165 212 186
+ 127 206 154 36 37 46 126 205 212 203 90 47 56 191 213 172
+ 110 205 205 87 47 44 56 179 213 178 68 49 117 211 215 151
+ 138 207 211 206 132 48 49 94 190 108 44 68 187 212 215 204
+ 158 207 212 210 193 61 46 59 69 47 42 93 210 212 215 210
+ 122 208 209 211 205 139 52 38 42 44 55 158 206 214 215 211
+ 125 206 209 211 211 205 107 40 39 42 61 172 214 217 217 212
+ 155 208 208 210 214 211 157 50 37 39 93 211 214 214 214 212
+ 158 208 211 214 216 214 211 135 45 45 166 215 212 213 214 215
+ 112 208 211 214 213 215 215 201 86 116 211 214 212 211 215 215
+ 129 207 213 212 213 211 209 212 194 179 213 216 213 214 215 213
+ 34 44 38 53 60 52 40 51 56 47 39 48 45 32 35 39
+ 107 172 154 147 183 174 154 143 184 166 144 129 153 140 139 98
+ 98 173 164 172 183 185 185 185 185 181 183 156 133 81 156 126
+ 71 164 59 42 158 180 183 187 187 185 184 125 36 46 166 115
+ 97 156 36 27 28 135 183 188 190 191 190 89 37 94 177 160
+ 124 161 70 23 20 56 171 187 187 190 145 48 55 147 186 161
+ 104 176 133 31 27 34 113 187 188 174 66 32 43 164 187 148
+ 94 179 177 79 43 38 44 158 187 148 47 39 90 180 190 133
+ 119 179 180 186 114 37 39 79 170 86 32 54 156 189 191 182
+ 138 184 190 188 178 51 34 44 55 39 38 73 185 193 192 187
+ 100 182 188 188 187 126 47 28 31 33 44 112 174 193 189 188
+ 110 186 189 190 190 183 93 32 29 30 40 145 190 189 188 189
+ 130 186 188 189 191 189 142 37 26 24 66 181 191 191 192 194
+ 139 182 186 190 191 194 184 115 33 33 142 189 192 194 193 190
+ 96 184 188 191 193 194 194 177 58 85 185 188 193 195 194 191
+ 112 187 188 189 193 192 190 187 171 160 190 191 191 193 194 191
+
+ 52 111 151 148 192 190 172 157 208 207 206 209 212 210 210 212
+ 52 156 194 215 229 206 204 210 212 211 207 207 210 208 210 207
+ 54 159 121 83 142 175 182 209 214 213 209 208 211 213 212 211
+ 63 165 167 61 71 84 73 129 197 212 223 209 211 211 211 208
+ 70 153 190 152 113 75 64 57 86 113 191 174 213 216 209 206
+ 63 174 212 204 208 164 93 74 74 60 62 69 102 185 212 206
+ 63 179 212 213 213 208 189 167 112 66 54 51 51 70 105 179
+ 71 189 209 209 212 209 204 204 190 73 49 49 50 48 78 191
+ 70 156 211 214 207 213 224 189 100 69 55 55 38 117 194 210
+ 56 173 213 212 211 207 159 72 66 62 72 108 162 208 209 215
+ 69 189 213 209 160 87 54 56 67 72 154 208 210 210 210 208
+ 84 199 208 210 46 36 42 62 143 196 206 211 207 210 213 206
+ 77 172 199 83 38 37 50 99 206 210 209 210 206 211 211 203
+ 57 178 191 78 47 78 151 197 200 212 211 211 210 211 206 209
+ 68 193 211 217 185 181 204 206 202 214 218 214 205 204 203 204
+ 60 151 155 121 131 149 138 132 147 182 142 132 154 163 126 156
+ 45 98 146 129 180 186 172 151 204 210 211 212 212 215 215 213
+ 45 146 182 195 209 212 213 215 215 215 215 217 214 214 215 215
+ 46 153 106 66 120 165 191 211 212 212 214 217 214 213 211 214
+ 47 168 167 63 48 66 56 117 187 210 206 214 214 212 212 213
+ 50 135 194 159 102 63 47 49 68 93 158 172 211 215 214 216
+ 46 170 207 209 211 168 90 68 44 42 55 61 93 166 211 213
+ 47 191 211 209 212 213 203 178 108 47 44 42 39 45 116 179
+ 52 198 208 213 209 212 212 213 190 69 42 39 37 45 86 194
+ 52 146 208 212 211 213 205 179 94 59 38 40 50 135 201 212
+ 45 169 208 210 210 201 126 56 49 46 52 107 157 211 215 209
+ 50 191 209 207 155 70 46 44 48 61 139 205 211 214 215 211
+ 63 198 206 192 39 36 37 47 132 193 205 211 214 216 213 213
+ 59 163 197 77 30 30 36 87 206 210 211 211 210 214 214 212
+ 48 170 193 96 49 85 154 205 211 212 209 209 208 211 211 213
+ 49 180 204 197 178 185 206 205 207 207 208 206 208 208 208 207
+ 46 115 124 90 115 145 127 110 138 158 122 125 155 158 112 129
+ 39 98 126 115 160 161 148 133 182 187 188 189 194 190 191 191
+ 35 139 156 166 177 186 187 190 191 192 189 188 192 193 194 194
+ 32 140 81 46 94 147 164 180 189 193 193 189 191 194 195 193
+ 45 153 133 36 37 55 43 90 156 185 174 190 191 192 193 191
+ 48 129 156 125 89 48 32 39 54 73 112 145 181 189 188 191
+ 39 144 183 184 190 145 66 47 32 38 44 40 66 142 185 190
+ 47 166 181 185 191 190 174 148 86 39 33 30 24 33 85 160
+ 56 184 185 187 190 187 188 187 170 55 31 29 26 33 58 171
+ 51 143 185 187 188 187 187 158 79 44 28 32 37 115 177 187
+ 40 154 185 183 183 171 113 44 39 34 47 93 142 184 194 190
+ 52 174 185 180 135 56 34 38 37 51 126 183 189 194 194 192
+ 60 183 183 158 28 20 27 43 114 178 187 190 191 191 193 193
+ 53 147 172 42 27 23 31 79 186 188 188 190 189 190 191 189
+ 38 154 164 59 36 70 133 177 180 190 188 189 188 186 188 188
+ 44 172 173 164 156 161 176 179 179 184 182 186 186 182 184 187
+ 34 107 98 71 97 124 104 94 119 138 100 110 130 139 96 112
+
+ 212 207 211 208 206 206 179 191 210 215 208 206 203 209 204 156
+ 210 210 212 211 209 212 105 78 194 209 210 213 211 206 203 126
+ 210 208 213 211 216 185 70 48 117 208 210 210 211 211 204 163
+ 212 210 211 211 213 102 51 50 38 162 210 207 206 210 205 154
+ 209 207 208 209 174 69 51 49 55 108 208 211 210 211 214 132
+ 206 207 209 223 191 62 54 49 55 72 154 206 209 211 218 142
+ 207 211 213 212 113 60 66 73 69 62 72 196 210 212 214 182
+ 208 212 214 197 86 74 112 190 100 66 67 143 206 200 202 147
+ 157 210 209 129 57 74 167 204 189 72 56 62 99 197 206 132
+ 172 204 182 73 64 93 189 204 224 159 54 42 50 151 204 138
+ 190 206 175 84 75 164 208 209 213 207 87 36 37 78 181 149
+ 192 229 142 71 113 208 213 212 207 211 160 46 38 47 185 131
+ 148 215 83 61 152 204 213 209 214 212 209 210 83 78 217 121
+ 151 194 121 167 190 212 212 209 211 213 213 208 199 191 211 155
+ 111 156 159 165 153 174 179 189 156 173 189 199 172 178 193 151
+ 52 52 54 63 70 63 63 71 70 56 69 84 77 57 68 60
+ 213 215 214 213 216 213 179 194 212 209 211 213 212 213 207 129
+ 215 215 211 212 214 211 116 86 201 215 215 213 214 211 208 112
+ 215 214 213 212 215 166 45 45 135 211 214 216 214 211 208 158
+ 212 214 214 214 211 93 39 37 50 157 211 214 210 208 208 155
+ 212 217 217 214 172 61 42 39 40 107 205 211 211 209 206 125
+ 211 215 214 206 158 55 44 42 38 52 139 205 211 209 208 122
+ 210 215 212 210 93 42 47 69 59 46 61 193 210 212 207 158
+ 204 215 212 187 68 44 108 190 94 49 48 132 206 211 207 138
+ 151 215 211 117 49 68 178 213 179 56 44 47 87 205 205 110
+ 172 213 191 56 47 90 203 212 205 126 46 37 36 154 206 127
+ 186 212 165 66 63 168 213 212 213 201 70 36 30 85 185 145
+ 180 209 120 48 102 211 212 209 211 210 155 39 30 49 178 115
+ 129 195 66 63 159 209 209 213 212 210 207 192 77 96 197 90
+ 146 182 106 167 194 207 211 208 208 208 209 206 197 193 204 124
+ 98 146 153 168 135 170 191 198 146 169 191 198 163 170 180 115
+ 45 45 46 47 50 46 47 52 52 45 50 63 59 48 49 46
+ 191 194 193 191 191 190 160 171 187 190 192 193 189 188 187 112
+ 191 194 195 193 188 185 85 58 177 194 194 193 191 188 184 96
+ 190 193 194 192 189 142 33 33 115 184 194 191 190 186 182 139
+ 194 192 191 191 181 66 24 26 37 142 189 191 189 188 186 130
+ 189 188 189 190 145 40 30 29 32 93 183 190 190 189 186 110
+ 188 189 193 174 112 44 33 31 28 47 126 187 188 188 182 100
+ 187 192 193 185 73 38 39 55 44 34 51 178 188 190 184 138
+ 182 191 189 156 54 32 86 170 79 39 37 114 186 180 179 119
+ 133 190 180 90 39 47 148 187 158 44 38 43 79 177 179 94
+ 148 187 164 43 32 66 174 188 187 113 34 27 31 133 176 104
+ 161 186 147 55 48 145 190 187 187 171 56 20 23 70 161 124
+ 160 177 94 37 89 190 191 190 188 183 135 28 27 36 156 97
+ 115 166 46 36 125 184 185 187 187 183 180 158 42 59 164 71
+ 126 156 81 133 156 183 181 185 185 185 185 183 172 164 173 98
+ 98 139 140 153 129 144 166 184 143 154 174 183 147 154 172 107
+ 39 35 32 45 48 39 47 56 51 40 52 60 53 38 44 34
+
+ 156 126 163 154 132 142 182 147 132 138 149 131 121 155 151 60
+ 204 203 204 205 214 218 214 202 206 204 181 185 217 211 193 68
+ 209 206 211 210 211 211 212 200 197 151 78 47 78 191 178 57
+ 203 211 211 206 210 209 210 206 99 50 37 38 83 199 172 77
+ 206 213 210 207 211 206 196 143 62 42 36 46 210 208 199 84
+ 208 210 210 210 208 154 72 67 56 54 87 160 209 213 189 69
+ 215 209 208 162 108 72 62 66 72 159 207 211 212 213 173 56
+ 210 194 117 38 55 55 69 100 189 224 213 207 214 211 156 70
+ 191 78 48 50 49 49 73 190 204 204 209 212 209 209 189 71
+ 179 105 70 51 51 54 66 112 167 189 208 213 213 212 179 63
+ 206 212 185 102 69 62 60 74 74 93 164 208 204 212 174 63
+ 206 209 216 213 174 191 113 86 57 64 75 113 152 190 153 70
+ 208 211 211 211 209 223 212 197 129 73 84 71 61 167 165 63
+ 211 212 213 211 208 209 213 214 209 182 175 142 83 121 159 54
+ 207 210 208 210 207 207 211 212 210 204 206 229 215 194 156 52
+ 212 210 210 212 209 206 207 208 157 172 190 192 148 151 111 52
+ 129 112 158 155 125 122 158 138 110 127 145 115 90 124 115 46
+ 207 208 208 208 206 208 207 207 205 206 185 178 197 204 180 49
+ 213 211 211 208 209 209 212 211 205 154 85 49 96 193 170 48
+ 212 214 214 210 211 211 210 206 87 36 30 30 77 197 163 59
+ 213 213 216 214 211 205 193 132 47 37 36 39 192 206 198 63
+ 211 215 214 211 205 139 61 48 44 46 70 155 207 209 191 50
+ 209 215 211 157 107 52 46 49 56 126 201 210 210 208 169 45
+ 212 201 135 50 40 38 59 94 179 205 213 211 212 208 146 52
+ 194 86 45 37 39 42 69 190 213 212 212 209 213 208 198 52
+ 179 116 45 39 42 44 47 108 178 203 213 212 209 211 191 47
+ 213 211 166 93 61 55 42 44 68 90 168 211 209 207 170 46
+ 216 214 215 211 172 158 93 68 49 47 63 102 159 194 135 50
+ 213 212 212 214 214 206 210 187 117 56 66 48 63 167 168 47
+ 214 211 213 214 217 214 212 212 211 191 165 120 66 106 153 46
+ 215 215 214 214 217 215 215 215 215 213 212 209 195 182 146 45
+ 213 215 215 212 212 211 210 204 151 172 186 180 129 146 98 45
+ 112 96 139 130 110 100 138 119 94 104 124 97 71 98 107 34
+ 187 184 182 186 186 182 184 179 179 176 161 156 164 173 172 44
+ 188 188 186 188 189 188 190 180 177 133 70 36 59 164 154 38
+ 189 191 190 189 190 188 188 186 79 31 23 27 42 172 147 53
+ 193 193 191 191 190 187 178 114 43 27 20 28 158 183 183 60
+ 192 194 194 189 183 126 51 37 38 34 56 135 180 185 174 52
+ 190 194 184 142 93 47 34 39 44 113 171 183 183 185 154 40
+ 187 177 115 37 32 28 44 79 158 187 187 188 187 185 143 51
+ 171 58 33 26 29 31 55 170 187 188 187 190 187 185 184 56
+ 160 85 33 24 30 33 39 86 148 174 190 191 185 181 166 47
+ 190 185 142 66 40 44 38 32 47 66 145 190 184 183 144 39
+ 191 188 189 181 145 112 73 54 39 32 48 89 125 156 129 48
+ 191 193 192 191 190 174 185 156 90 43 55 37 36 133 153 45
+ 193 195 194 191 189 193 193 189 180 164 147 94 46 81 140 32
+ 194 194 193 192 188 189 192 191 190 187 186 177 166 156 139 35
+ 191 191 190 194 189 188 187 182 133 148 161 160 115 126 98 39
+
diff --git a/patt.hiro b/patt.hiro
new file mode 100755
index 0000000..7f78e3c
--- /dev/null
+++ b/patt.hiro
@@ -0,0 +1,196 @@
+ 234 235 240 233 240 234 240 235 240 237 240 238 240 240 240 232
+ 229 240 240 240 240 240 240 240 240 240 240 240 240 240 240 228
+ 227 240 240 240 240 240 240 240 240 240 240 240 240 240 240 239
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 236 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 234 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 236 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 231 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 229 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 225 149 240 240 186 216 225 174 240 240 240 237 238 240 240 240
+ 150 107 238 231 75 208 115 147 238 228 223 226 237 180 226 240
+ 150 62 181 213 62 187 113 169 197 72 29 237 120 50 53 207
+ 149 63 47 78 53 184 113 101 142 5 150 150 45 217 186 83
+ 121 84 220 222 58 180 121 92 128 109 237 124 155 232 161 64
+ 149 71 240 240 76 210 98 109 122 108 240 129 51 119 161 155
+ 149 186 240 240 98 219 135 152 207 191 236 227 152 77 175 209
+ 235 235 240 233 240 234 240 235 240 236 240 238 240 240 240 240
+ 229 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 227 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 236 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 234 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 236 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 232 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 229 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 225 156 240 240 186 216 225 186 240 240 240 240 240 240 240 240
+ 150 117 240 231 72 206 115 162 240 232 223 237 240 180 226 240
+ 150 74 187 213 51 184 103 168 197 78 29 237 120 50 53 216
+ 144 77 51 74 61 184 106 101 142 5 150 152 52 217 186 85
+ 117 89 219 219 65 184 121 92 128 100 236 125 156 240 170 73
+ 148 71 240 240 76 210 109 109 121 99 240 137 51 120 166 164
+ 140 186 240 240 98 220 150 156 207 192 236 230 152 77 176 212
+ 234 235 240 233 240 234 240 235 240 236 240 238 240 240 240 233
+ 229 240 240 240 240 240 240 240 240 240 240 240 240 240 240 239
+ 227 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 234 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 232 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 235 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 232 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 228 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 225 156 240 240 182 212 225 180 240 240 240 240 240 240 240 240
+ 150 116 238 228 66 205 115 151 238 236 225 240 240 180 226 240
+ 156 84 186 211 47 184 109 170 200 92 30 240 120 50 53 216
+ 147 83 51 73 50 184 106 110 148 17 151 150 45 217 186 85
+ 127 98 219 219 58 179 109 101 128 107 237 125 155 240 163 72
+ 155 86 240 240 76 201 85 108 121 95 232 137 51 118 153 155
+ 149 189 240 240 98 220 141 154 206 178 235 230 152 77 175 209
+
+ 232 228 239 240 240 240 240 240 240 240 240 207 83 64 155 209
+ 240 240 240 240 240 240 240 240 240 240 226 53 186 161 161 175
+ 240 240 240 240 240 240 240 240 240 240 180 50 217 232 119 77
+ 240 240 240 240 240 240 240 240 240 238 237 120 45 155 51 152
+ 238 240 240 240 240 240 240 240 240 237 226 237 150 124 129 227
+ 240 240 240 240 240 240 240 240 240 240 223 29 150 237 240 236
+ 237 240 240 240 240 240 240 240 240 240 228 72 5 109 108 191
+ 240 240 240 240 240 240 240 240 240 240 238 197 142 128 122 207
+ 235 240 240 240 240 240 240 240 240 174 147 169 101 92 109 152
+ 240 240 240 240 240 240 240 240 240 225 115 113 113 121 98 135
+ 234 240 240 240 240 240 240 240 240 216 208 187 184 180 210 219
+ 240 240 240 240 240 240 240 240 240 186 75 62 53 58 76 98
+ 233 240 240 240 240 240 240 240 240 240 231 213 78 222 240 240
+ 240 240 240 240 240 240 240 240 240 240 238 181 47 220 240 240
+ 235 240 240 240 240 240 240 240 240 149 107 62 63 84 71 186
+ 234 229 227 240 236 234 236 231 229 225 150 150 149 121 149 149
+ 240 240 240 240 240 240 240 240 240 240 240 216 85 73 164 212
+ 240 240 240 240 240 240 240 240 240 240 226 53 186 170 166 176
+ 240 240 240 240 240 240 240 240 240 240 180 50 217 240 120 77
+ 240 240 240 240 240 240 240 240 240 240 240 120 52 156 51 152
+ 238 240 240 240 240 240 240 240 240 240 237 237 152 125 137 230
+ 240 240 240 240 240 240 240 240 240 240 223 29 150 236 240 236
+ 236 240 240 240 240 240 240 240 240 240 232 78 5 100 99 192
+ 240 240 240 240 240 240 240 240 240 240 240 197 142 128 121 207
+ 235 240 240 240 240 240 240 240 240 186 162 168 101 92 109 156
+ 240 240 240 240 240 240 240 240 240 225 115 103 106 121 109 150
+ 234 240 240 240 240 240 240 240 240 216 206 184 184 184 210 220
+ 240 240 240 240 240 240 240 240 240 186 72 51 61 65 76 98
+ 233 240 240 240 240 240 240 240 240 240 231 213 74 219 240 240
+ 240 240 240 240 240 240 240 240 240 240 240 187 51 219 240 240
+ 235 240 240 240 240 240 240 240 240 156 117 74 77 89 71 186
+ 235 229 227 240 236 234 236 232 229 225 150 150 144 117 148 140
+ 233 239 240 240 240 240 240 240 240 240 240 216 85 72 155 209
+ 240 240 240 240 240 240 240 240 240 240 226 53 186 163 153 175
+ 240 240 240 240 240 240 240 240 240 240 180 50 217 240 118 77
+ 240 240 240 240 240 240 240 240 240 240 240 120 45 155 51 152
+ 238 240 240 240 240 240 240 240 240 240 240 240 150 125 137 230
+ 240 240 240 240 240 240 240 240 240 240 225 30 151 237 232 235
+ 236 240 240 240 240 240 240 240 240 240 236 92 17 107 95 178
+ 240 240 240 240 240 240 240 240 240 240 238 200 148 128 121 206
+ 235 240 240 240 240 240 240 240 240 180 151 170 110 101 108 154
+ 240 240 240 240 240 240 240 240 240 225 115 109 106 109 85 141
+ 234 240 240 240 240 240 240 240 240 212 205 184 184 179 201 220
+ 240 240 240 240 240 240 240 240 240 182 66 47 50 58 76 98
+ 233 240 240 240 240 240 240 240 240 240 228 211 73 219 240 240
+ 240 240 240 240 240 240 240 240 240 240 238 186 51 219 240 240
+ 235 240 240 240 240 240 240 240 240 156 116 84 83 98 86 189
+ 234 229 227 240 234 232 235 232 228 225 150 156 147 127 155 149
+
+ 209 175 77 152 227 236 191 207 152 135 219 98 240 240 186 149
+ 155 161 119 51 129 240 108 122 109 98 210 76 240 240 71 149
+ 64 161 232 155 124 237 109 128 92 121 180 58 222 220 84 121
+ 83 186 217 45 150 150 5 142 101 113 184 53 78 47 63 149
+ 207 53 50 120 237 29 72 197 169 113 187 62 213 181 62 150
+ 240 226 180 237 226 223 228 238 147 115 208 75 231 238 107 150
+ 240 240 240 238 237 240 240 240 174 225 216 186 240 240 149 225
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 229
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 231
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 236
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 234
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 236
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 239 240 240 240 240 240 240 240 240 240 240 240 240 240 240 227
+ 228 240 240 240 240 240 240 240 240 240 240 240 240 240 240 229
+ 232 240 240 240 238 240 237 240 235 240 234 240 233 240 235 234
+ 212 176 77 152 230 236 192 207 156 150 220 98 240 240 186 140
+ 164 166 120 51 137 240 99 121 109 109 210 76 240 240 71 148
+ 73 170 240 156 125 236 100 128 92 121 184 65 219 219 89 117
+ 85 186 217 52 152 150 5 142 101 106 184 61 74 51 77 144
+ 216 53 50 120 237 29 78 197 168 103 184 51 213 187 74 150
+ 240 226 180 240 237 223 232 240 162 115 206 72 231 240 117 150
+ 240 240 240 240 240 240 240 240 186 225 216 186 240 240 156 225
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 229
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 232
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 236
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 234
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 236
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 227
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 229
+ 240 240 240 240 238 240 236 240 235 240 234 240 233 240 235 235
+ 209 175 77 152 230 235 178 206 154 141 220 98 240 240 189 149
+ 155 153 118 51 137 232 95 121 108 85 201 76 240 240 86 155
+ 72 163 240 155 125 237 107 128 101 109 179 58 219 219 98 127
+ 85 186 217 45 150 151 17 148 110 106 184 50 73 51 83 147
+ 216 53 50 120 240 30 92 200 170 109 184 47 211 186 84 156
+ 240 226 180 240 240 225 236 238 151 115 205 66 228 238 116 150
+ 240 240 240 240 240 240 240 240 180 225 212 182 240 240 156 225
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 228
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 232
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 235
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 232
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 234
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240
+ 240 240 240 240 240 240 240 240 240 240 240 240 240 240 240 227
+ 239 240 240 240 240 240 240 240 240 240 240 240 240 240 240 229
+ 233 240 240 240 238 240 236 240 235 240 234 240 233 240 235 234
+
+ 149 149 121 149 150 150 225 229 231 236 234 236 240 227 229 234
+ 186 71 84 63 62 107 149 240 240 240 240 240 240 240 240 235
+ 240 240 220 47 181 238 240 240 240 240 240 240 240 240 240 240
+ 240 240 222 78 213 231 240 240 240 240 240 240 240 240 240 233
+ 98 76 58 53 62 75 186 240 240 240 240 240 240 240 240 240
+ 219 210 180 184 187 208 216 240 240 240 240 240 240 240 240 234
+ 135 98 121 113 113 115 225 240 240 240 240 240 240 240 240 240
+ 152 109 92 101 169 147 174 240 240 240 240 240 240 240 240 235
+ 207 122 128 142 197 238 240 240 240 240 240 240 240 240 240 240
+ 191 108 109 5 72 228 240 240 240 240 240 240 240 240 240 237
+ 236 240 237 150 29 223 240 240 240 240 240 240 240 240 240 240
+ 227 129 124 150 237 226 237 240 240 240 240 240 240 240 240 238
+ 152 51 155 45 120 237 238 240 240 240 240 240 240 240 240 240
+ 77 119 232 217 50 180 240 240 240 240 240 240 240 240 240 240
+ 175 161 161 186 53 226 240 240 240 240 240 240 240 240 240 240
+ 209 155 64 83 207 240 240 240 240 240 240 240 240 239 228 232
+ 140 148 117 144 150 150 225 229 232 236 234 236 240 227 229 235
+ 186 71 89 77 74 117 156 240 240 240 240 240 240 240 240 235
+ 240 240 219 51 187 240 240 240 240 240 240 240 240 240 240 240
+ 240 240 219 74 213 231 240 240 240 240 240 240 240 240 240 233
+ 98 76 65 61 51 72 186 240 240 240 240 240 240 240 240 240
+ 220 210 184 184 184 206 216 240 240 240 240 240 240 240 240 234
+ 150 109 121 106 103 115 225 240 240 240 240 240 240 240 240 240
+ 156 109 92 101 168 162 186 240 240 240 240 240 240 240 240 235
+ 207 121 128 142 197 240 240 240 240 240 240 240 240 240 240 240
+ 192 99 100 5 78 232 240 240 240 240 240 240 240 240 240 236
+ 236 240 236 150 29 223 240 240 240 240 240 240 240 240 240 240
+ 230 137 125 152 237 237 240 240 240 240 240 240 240 240 240 238
+ 152 51 156 52 120 240 240 240 240 240 240 240 240 240 240 240
+ 77 120 240 217 50 180 240 240 240 240 240 240 240 240 240 240
+ 176 166 170 186 53 226 240 240 240 240 240 240 240 240 240 240
+ 212 164 73 85 216 240 240 240 240 240 240 240 240 240 240 240
+ 149 155 127 147 156 150 225 228 232 235 232 234 240 227 229 234
+ 189 86 98 83 84 116 156 240 240 240 240 240 240 240 240 235
+ 240 240 219 51 186 238 240 240 240 240 240 240 240 240 240 240
+ 240 240 219 73 211 228 240 240 240 240 240 240 240 240 240 233
+ 98 76 58 50 47 66 182 240 240 240 240 240 240 240 240 240
+ 220 201 179 184 184 205 212 240 240 240 240 240 240 240 240 234
+ 141 85 109 106 109 115 225 240 240 240 240 240 240 240 240 240
+ 154 108 101 110 170 151 180 240 240 240 240 240 240 240 240 235
+ 206 121 128 148 200 238 240 240 240 240 240 240 240 240 240 240
+ 178 95 107 17 92 236 240 240 240 240 240 240 240 240 240 236
+ 235 232 237 151 30 225 240 240 240 240 240 240 240 240 240 240
+ 230 137 125 150 240 240 240 240 240 240 240 240 240 240 240 238
+ 152 51 155 45 120 240 240 240 240 240 240 240 240 240 240 240
+ 77 118 240 217 50 180 240 240 240 240 240 240 240 240 240 240
+ 175 153 163 186 53 226 240 240 240 240 240 240 240 240 240 240
+ 209 155 72 85 216 240 240 240 240 240 240 240 240 240 239 233
+
diff --git a/texture.cpp b/texture.cpp
new file mode 100755
index 0000000..5a4a7ab
--- /dev/null
+++ b/texture.cpp
@@ -0,0 +1,25 @@
+#ifndef __APPLE__
+#include <GL/gl.h>
+#include <GL/glut.h>
+#else
+#include <OpenGL/gl.h>
+#include <GLUT/glut.h>
+#endif
+#include <stdexcept>
+#include "texture.h"
+
+unsigned int Texture::tex() {
+ return texture;
+}
+
+void Texture::build() {
+ if(!data) {
+ throw(std::runtime_error("No texture data"));
+ }
+ glGenTextures(1, &texture);
+ glBindTexture(GL_TEXTURE_2D, texture);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
+ //glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
+ gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
+}
diff --git a/texture.h b/texture.h
new file mode 100755
index 0000000..33f6178
--- /dev/null
+++ b/texture.h
@@ -0,0 +1,13 @@
+#ifndef _TEXTURE_H_
+#define _TEXTURE_H_
+class Texture {
+ public:
+ unsigned int tex();
+ protected:
+ void build();
+ unsigned char* data;
+ unsigned int width;
+ unsigned int height;
+ unsigned int texture;
+};
+#endif // _TEXTURE_H_
diff --git a/texturepng.cpp b/texturepng.cpp
new file mode 100755
index 0000000..19dd4ab
--- /dev/null
+++ b/texturepng.cpp
@@ -0,0 +1,45 @@
+#include <iostream>
+#include <stdexcept>
+#include <png.h>
+#include "texturepng.h"
+
+TexturePNG::TexturePNG(const char* filename) {
+ FILE *file = fopen(filename, "rb");
+ if(!file) {
+ throw(std::runtime_error("TexturePNG file not found"));
+ }
+ png_byte header[8];
+ fread(header, 1, 8, file);
+ if(png_sig_cmp(header, 0, 8)) {
+ throw(std::runtime_error("Invalid PNG file"));
+ }
+ png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
+ if(!png_ptr) {
+ throw(std::runtime_error("LibPNG Error (png_ptr)"));
+ }
+ png_infop info_ptr = png_create_info_struct(png_ptr);
+ if(!info_ptr) {
+ throw(std::runtime_error("LibPNG Error (info_ptr)"));
+ }
+ png_infop end_info = png_create_info_struct(png_ptr);
+ if(!end_info) {
+ throw(std::runtime_error("LibPNG Error (end_info)"));
+ }
+ if (setjmp(png_jmpbuf(png_ptr))) {
+ throw(std::runtime_error("LibPNG Error"));
+ }
+ png_init_io(png_ptr, file);
+ png_set_sig_bytes(png_ptr, 8);
+ png_read_png(png_ptr, info_ptr, 0, 0);
+ png_bytep* row_pointers = png_get_rows(png_ptr, info_ptr);
+ width = png_get_image_width(png_ptr, info_ptr);
+ height = png_get_image_height(png_ptr, info_ptr);
+ data = new unsigned char[width * height * 4];
+ for(int y = 0; y < height; y++) {
+ for(int x = 0; x < width * 4; x++) {
+ data[x + y*width*4] = row_pointers[y][x];
+ }
+ }
+ build();
+ png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+}
diff --git a/texturepng.h b/texturepng.h
new file mode 100755
index 0000000..9236d39
--- /dev/null
+++ b/texturepng.h
@@ -0,0 +1,8 @@
+#ifndef _TEXTUREPNG_H_
+#define _TEXTUREPNG_H_
+#include "texture.h"
+class TexturePNG : public Texture {
+ public:
+ TexturePNG(const char* filename);
+};
+#endif // _TEXTUREPNG_H_