qvolray

annotate src/volray.cc @ 13:17d9dc2edc91

first qt version
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 10 Apr 2012 06:11:16 +0300
parents 8990b5d2c7fe
children 3d05c261a2f4
rev   line source
nuclear@0 1 #include <stdio.h>
nuclear@0 2 #include <stdlib.h>
nuclear@0 3 #include <assert.h>
nuclear@0 4
nuclear@0 5 #include <GL/glew.h>
nuclear@0 6 #ifndef __APPLE__
nuclear@0 7 #include <GL/glut.h>
nuclear@0 8 #else
nuclear@0 9 #include <GLUT/glut.h>
nuclear@0 10 #endif
nuclear@0 11
nuclear@0 12 #include <vmath/vmath.h>
nuclear@0 13 #include <imago2.h>
nuclear@0 14 #include "sdr.h"
nuclear@9 15 #include "volume.h"
nuclear@13 16 #include "ui.h"
nuclear@0 17
nuclear@3 18 #define XFER_MAP_SZ 512
nuclear@3 19
nuclear@11 20 static void render_volume();
nuclear@11 21 static void draw_slice();
nuclear@11 22 static void draw_xfer_func();
nuclear@5 23
nuclear@11 24 /*
nuclear@0 25 void keyb(unsigned char key, int x, int y);
nuclear@4 26 void keyb_up(unsigned char key, int x, int y);
nuclear@0 27 void mouse(int bn, int state, int x, int y);
nuclear@0 28 void motion(int x, int y);
nuclear@0 29 int parse_args(int argc, char **argv);
nuclear@11 30 */
nuclear@0 31
nuclear@11 32 static void create_ray_texture(int xsz, int ysz, float vfov, Vector2 *tex_scale);
nuclear@11 33 static Vector3 get_primary_ray_dir(int x, int y, int w, int h, float vfov_deg);
nuclear@0 34 static int round_pow2(int x);
nuclear@3 35 static void create_transfer_map(float mean, float sdev);
nuclear@0 36
nuclear@9 37 static float cam_theta = 0, cam_phi = 0, cam_dist = 4.0;
nuclear@9 38 static float cam_x, cam_y, cam_z;
nuclear@0 39
nuclear@13 40 static Vector2 tex_scale;
nuclear@9 41 static unsigned int vol_sdr, slice_sdr, ray_tex;
nuclear@9 42 static int win_xsz, win_ysz;
nuclear@11 43 static bool raytex_needs_recalc = true;
nuclear@0 44
nuclear@9 45 static unsigned int xfer_tex;
nuclear@9 46 static float xfer_mean = 0.7, xfer_sdev = 0.1;
nuclear@11 47 static bool xfertex_needs_recalc = true;
nuclear@3 48
nuclear@7 49 static float cur_z = 0.0;
nuclear@7 50 static float ray_step = 0.01;
nuclear@4 51
nuclear@13 52 static const Volume *volume;
nuclear@9 53
nuclear@9 54
nuclear@11 55 bool volray_init()
nuclear@0 56 {
nuclear@0 57 glewInit();
nuclear@0 58
nuclear@9 59 if(!(vol_sdr = create_program_load("sdr/volray.v.glsl", "sdr/volray.p.glsl"))) {
nuclear@11 60 return false;
nuclear@0 61 }
nuclear@5 62 set_uniform_int(vol_sdr, "volume", 0);
nuclear@5 63 set_uniform_int(vol_sdr, "ray_tex", 1);
nuclear@5 64 set_uniform_int(vol_sdr, "xfer_tex", 2);
nuclear@7 65 set_uniform_float(vol_sdr, "ray_step", ray_step);
nuclear@7 66 set_uniform_float(vol_sdr, "zclip", cur_z);
nuclear@5 67
nuclear@9 68 if(!(slice_sdr = create_program_load(0, "sdr/slice.p.glsl"))) {
nuclear@11 69 return false;
nuclear@5 70 }
nuclear@5 71 set_uniform_int(slice_sdr, "volume", 0);
nuclear@5 72 set_uniform_int(slice_sdr, "xfer_tex", 1);
nuclear@0 73
nuclear@11 74 return true;
nuclear@0 75 }
nuclear@0 76
nuclear@13 77 void volray_setvolume(const Volume *vol)
nuclear@13 78 {
nuclear@13 79 volume = vol;
nuclear@13 80 }
nuclear@13 81
nuclear@11 82 void volray_draw(void)
nuclear@0 83 {
nuclear@4 84 /* recalculate primary ray texture if needed */
nuclear@1 85 if(raytex_needs_recalc) {
nuclear@1 86 create_ray_texture(win_xsz, win_ysz, 50.0, &tex_scale);
nuclear@1 87 }
nuclear@4 88 /* recalculate transfer function texture if needed */
nuclear@3 89 if(xfertex_needs_recalc) {
nuclear@3 90 create_transfer_map(xfer_mean, xfer_sdev);
nuclear@3 91 }
nuclear@1 92
nuclear@13 93 glClear(GL_COLOR_BUFFER_BIT);
nuclear@13 94
nuclear@13 95 if(volume) {
nuclear@13 96 render_volume();
nuclear@13 97 draw_slice();
nuclear@13 98 draw_xfer_func();
nuclear@13 99 }
nuclear@4 100
nuclear@4 101 assert(glGetError() == GL_NO_ERROR);
nuclear@4 102 }
nuclear@4 103
nuclear@11 104 static void render_volume(void)
nuclear@4 105 {
nuclear@4 106 /* set the camera transformation */
nuclear@0 107 glMatrixMode(GL_MODELVIEW);
nuclear@4 108 glPushMatrix();
nuclear@0 109 glLoadIdentity();
nuclear@1 110 glRotatef(-90, 1, 0, 0);
nuclear@0 111 glTranslatef(cam_x, cam_y, -cam_z);
nuclear@0 112 glRotatef(cam_theta, 0, 1, 0);
nuclear@0 113 glRotatef(cam_phi, 1, 0, 0);
nuclear@0 114 glTranslatef(0, 0, -cam_dist);
nuclear@0 115
nuclear@4 116 /* setup the texture matrix to map the useful part of the ray texture to [0,1] */
nuclear@0 117 glMatrixMode(GL_TEXTURE);
nuclear@4 118 glPushMatrix();
nuclear@1 119 glLoadIdentity();
nuclear@0 120 glScalef(tex_scale.x, tex_scale.y, 1.0);
nuclear@0 121
nuclear@4 122 /* tex unit0: volume data 3D texture */
nuclear@0 123 glActiveTexture(GL_TEXTURE0);
nuclear@13 124 glBindTexture(GL_TEXTURE_3D, volume->get_texture());
nuclear@0 125 glEnable(GL_TEXTURE_3D);
nuclear@0 126
nuclear@4 127 /* tex unit1: primary rays in view space */
nuclear@0 128 glActiveTexture(GL_TEXTURE1);
nuclear@1 129 glBindTexture(GL_TEXTURE_2D, ray_tex);
nuclear@0 130 glEnable(GL_TEXTURE_2D);
nuclear@0 131
nuclear@4 132 /* tex unit2: transfer function (1d) */
nuclear@3 133 glActiveTexture(GL_TEXTURE2);
nuclear@3 134 glBindTexture(GL_TEXTURE_1D, xfer_tex);
nuclear@3 135 glEnable(GL_TEXTURE_1D);
nuclear@3 136
nuclear@5 137 bind_program(vol_sdr);
nuclear@0 138 glBegin(GL_QUADS);
nuclear@0 139 glColor3f(1, 1, 1);
nuclear@1 140 glTexCoord2f(0, 1); glVertex2f(-1, -1);
nuclear@1 141 glTexCoord2f(1, 1); glVertex2f(1, -1);
nuclear@1 142 glTexCoord2f(1, 0); glVertex2f(1, 1);
nuclear@1 143 glTexCoord2f(0, 0); glVertex2f(-1, 1);
nuclear@0 144 glEnd();
nuclear@0 145 bind_program(0);
nuclear@0 146
nuclear@3 147 glActiveTexture(GL_TEXTURE2);
nuclear@3 148 glDisable(GL_TEXTURE_1D);
nuclear@1 149 glActiveTexture(GL_TEXTURE1);
nuclear@0 150 glDisable(GL_TEXTURE_2D);
nuclear@0 151 glActiveTexture(GL_TEXTURE0);
nuclear@0 152 glDisable(GL_TEXTURE_3D);
nuclear@0 153
nuclear@0 154 glMatrixMode(GL_TEXTURE);
nuclear@4 155 glPopMatrix();
nuclear@4 156 glMatrixMode(GL_MODELVIEW);
nuclear@4 157 glPopMatrix();
nuclear@4 158 }
nuclear@0 159
nuclear@11 160 static void draw_slice(void)
nuclear@5 161 {
nuclear@5 162 glMatrixMode(GL_MODELVIEW);
nuclear@5 163 glPushMatrix();
nuclear@5 164 glTranslatef(0.9, 0.9, 0);
nuclear@5 165 glScalef(0.3, 0.3 * ((float)win_xsz / win_ysz), 1);
nuclear@5 166 glTranslatef(-1, -1, 0);
nuclear@5 167
nuclear@5 168 glActiveTexture(GL_TEXTURE0);
nuclear@13 169 glBindTexture(GL_TEXTURE_3D, volume->get_texture());
nuclear@5 170 glEnable(GL_TEXTURE_3D);
nuclear@5 171
nuclear@5 172 glActiveTexture(GL_TEXTURE1);
nuclear@5 173 glBindTexture(GL_TEXTURE_1D, xfer_tex);
nuclear@5 174 glEnable(GL_TEXTURE_1D);
nuclear@5 175
nuclear@5 176 bind_program(slice_sdr);
nuclear@5 177
nuclear@5 178 glBegin(GL_QUADS);
nuclear@5 179 glColor3f(1, 1, 1);
nuclear@5 180 glTexCoord3f(0, 1, cur_z); glVertex2f(-1, -1);
nuclear@5 181 glTexCoord3f(1, 1, cur_z); glVertex2f(1, -1);
nuclear@5 182 glTexCoord3f(1, 0, cur_z); glVertex2f(1, 1);
nuclear@5 183 glTexCoord3f(0, 0, cur_z); glVertex2f(-1, 1);
nuclear@5 184 glEnd();
nuclear@5 185
nuclear@5 186 bind_program(0);
nuclear@5 187
nuclear@5 188 glActiveTexture(GL_TEXTURE1);
nuclear@5 189 glDisable(GL_TEXTURE_1D);
nuclear@5 190 glActiveTexture(GL_TEXTURE0);
nuclear@5 191 glDisable(GL_TEXTURE_3D);
nuclear@5 192 glPopMatrix();
nuclear@5 193 }
nuclear@5 194
nuclear@11 195 static void draw_xfer_func(void)
nuclear@4 196 {
nuclear@4 197 glMatrixMode(GL_MODELVIEW);
nuclear@4 198 glPushMatrix();
nuclear@4 199 glTranslatef(-0.9, -0.9, 0);
nuclear@4 200 glScalef(0.5, 0.1, 1);
nuclear@4 201
nuclear@4 202 glBindTexture(GL_TEXTURE_1D, xfer_tex);
nuclear@4 203 glEnable(GL_TEXTURE_1D);
nuclear@4 204
nuclear@4 205 glBegin(GL_QUADS);
nuclear@4 206 glColor3f(1, 1, 1);
nuclear@4 207 glTexCoord1f(1);
nuclear@4 208 glVertex2f(1, 0);
nuclear@4 209 glVertex2f(1, 1);
nuclear@4 210 glTexCoord1f(0);
nuclear@4 211 glVertex2f(0, 1);
nuclear@4 212 glVertex2f(0, 0);
nuclear@4 213 glEnd();
nuclear@4 214
nuclear@4 215 glDisable(GL_TEXTURE_1D);
nuclear@4 216
nuclear@4 217 glLineWidth(2.0);
nuclear@4 218 glBegin(GL_LINE_LOOP);
nuclear@13 219 /*if(uimode == UIMODE_XFER) {
nuclear@5 220 glColor3f(1, 0, 0);
nuclear@13 221 } else {*/
nuclear@5 222 glColor3f(0, 0, 1);
nuclear@13 223 //}
nuclear@4 224 glVertex2f(0, 0);
nuclear@4 225 glVertex2f(1, 0);
nuclear@4 226 glVertex2f(1, 1);
nuclear@4 227 glVertex2f(0, 1);
nuclear@4 228 glEnd();
nuclear@4 229
nuclear@4 230 glPopMatrix();
nuclear@0 231 }
nuclear@0 232
nuclear@11 233 void volray_resize(int x, int y)
nuclear@0 234 {
nuclear@0 235 glViewport(0, 0, x, y);
nuclear@0 236
nuclear@0 237 if(x != win_xsz || y != win_ysz) {
nuclear@11 238 raytex_needs_recalc = true;
nuclear@0 239 win_xsz = x;
nuclear@0 240 win_ysz = y;
nuclear@0 241 }
nuclear@0 242 }
nuclear@0 243
nuclear@11 244 #if 0
nuclear@0 245 void keyb(unsigned char key, int x, int y)
nuclear@0 246 {
nuclear@0 247 switch(key) {
nuclear@0 248 case 27:
nuclear@0 249 exit(0);
nuclear@4 250
nuclear@4 251 case 'x':
nuclear@5 252 uimode = UIMODE_XFER;
nuclear@13 253 post_redisplay();
nuclear@4 254 break;
nuclear@5 255
nuclear@5 256 case 'c':
nuclear@5 257 uimode = UIMODE_CURSOR;
nuclear@13 258 post_redisplay();
nuclear@5 259 break;
nuclear@5 260
nuclear@5 261 default:
nuclear@5 262 break;
nuclear@4 263 }
nuclear@4 264 }
nuclear@4 265
nuclear@4 266 void keyb_up(unsigned char key, int x, int y)
nuclear@4 267 {
nuclear@4 268 switch(key) {
nuclear@4 269 case 'x':
nuclear@5 270 if(uimode == UIMODE_XFER) {
nuclear@5 271 uimode = UIMODE_DEFAULT;
nuclear@13 272 post_redisplay();
nuclear@5 273 }
nuclear@5 274 break;
nuclear@5 275
nuclear@5 276 case 'c':
nuclear@5 277 if(uimode == UIMODE_CURSOR) {
nuclear@5 278 uimode = UIMODE_DEFAULT;
nuclear@13 279 post_redisplay();
nuclear@5 280 }
nuclear@5 281 break;
nuclear@5 282
nuclear@5 283 default:
nuclear@4 284 break;
nuclear@0 285 }
nuclear@0 286 }
nuclear@13 287 #endif
nuclear@0 288
nuclear@0 289 static int bnstate[32];
nuclear@0 290 static int prev_x, prev_y;
nuclear@0 291
nuclear@13 292 void volray_mouse(int bn, int state, int x, int y)
nuclear@0 293 {
nuclear@13 294 bnstate[bn] = state;
nuclear@0 295 prev_x = x;
nuclear@0 296 prev_y = y;
nuclear@0 297 }
nuclear@0 298
nuclear@13 299 void volray_motion(int x, int y)
nuclear@0 300 {
nuclear@0 301 int dx = x - prev_x;
nuclear@0 302 int dy = y - prev_y;
nuclear@0 303 prev_x = x;
nuclear@0 304 prev_y = y;
nuclear@0 305
nuclear@13 306 /*switch(uimode) {
nuclear@5 307 case UIMODE_XFER:
nuclear@4 308 if(dx || dy) {
nuclear@4 309 xfer_mean += dx / (float)win_xsz;
nuclear@4 310 xfer_sdev += 0.5 * dy / (float)win_ysz;
nuclear@0 311
nuclear@4 312 xfer_mean = xfer_mean < 0.0 ? 0.0 : (xfer_mean > 1.0 ? 1.0 : xfer_mean);
nuclear@4 313 xfer_sdev = xfer_sdev < 0.0 ? 0.0 : (xfer_sdev > 1.0 ? 1.0 : xfer_sdev);
nuclear@0 314
nuclear@11 315 xfertex_needs_recalc = true;
nuclear@13 316 post_redisplay();
nuclear@4 317 }
nuclear@5 318 break;
nuclear@0 319
nuclear@5 320 case UIMODE_CURSOR:
nuclear@5 321 cur_z += 0.5 * dy / (float)win_ysz;
nuclear@5 322
nuclear@5 323 if(cur_z < 0.0)
nuclear@5 324 cur_z = 0.0;
nuclear@5 325 if(cur_z > 1.0)
nuclear@5 326 cur_z = 1.0;
nuclear@7 327
nuclear@7 328 set_uniform_float(vol_sdr, "zclip", cur_z);
nuclear@13 329 post_redisplay();
nuclear@5 330 break;
nuclear@5 331
nuclear@13 332 default:*/
nuclear@5 333 /* view control */
nuclear@4 334 if(bnstate[0]) {
nuclear@4 335 cam_theta += dx * 0.5;
nuclear@4 336 cam_phi += dy * 0.5;
nuclear@0 337
nuclear@4 338 if(cam_phi <= -90) cam_phi = -89;
nuclear@4 339 if(cam_phi >= 90) cam_phi = 89;
nuclear@13 340 post_redisplay();
nuclear@4 341 }
nuclear@4 342
nuclear@4 343 if(bnstate[1]) {
nuclear@4 344 cam_x += dx * 0.025;
nuclear@4 345 cam_y += dy * 0.025;
nuclear@13 346 post_redisplay();
nuclear@4 347 }
nuclear@4 348
nuclear@4 349 if(bnstate[2]) {
nuclear@4 350 cam_dist += dy * 0.025;
nuclear@4 351 if(cam_dist < 0.0) cam_dist = 0.0;
nuclear@13 352 post_redisplay();
nuclear@4 353 }
nuclear@13 354 //}
nuclear@0 355 }
nuclear@0 356
nuclear@13 357 #if 0
nuclear@0 358 int parse_args(int argc, char **argv)
nuclear@0 359 {
nuclear@0 360 int i;
nuclear@3 361 char *endp;
nuclear@0 362
nuclear@0 363 for(i=1; i<argc; i++) {
nuclear@2 364 if(argv[i][0] == '-' && argv[i][2] == 0) {
nuclear@2 365 switch(argv[i][1]) {
nuclear@3 366 case 'm':
nuclear@3 367 xfer_mean = strtod(argv[++i], &endp);
nuclear@3 368 if(endp == argv[i]) {
nuclear@3 369 fprintf(stderr, "-m must be followed by the transfer function mean\n");
nuclear@3 370 return -1;
nuclear@3 371 }
nuclear@2 372 break;
nuclear@3 373
nuclear@4 374 case 'd':
nuclear@3 375 xfer_sdev = strtod(argv[++i], &endp);
nuclear@3 376 if(endp == argv[i]) {
nuclear@4 377 fprintf(stderr, "-d must be followed by the transfer function std.deviation\n");
nuclear@3 378 return -1;
nuclear@3 379 }
nuclear@3 380 break;
nuclear@3 381
nuclear@3 382 default:
nuclear@3 383 fprintf(stderr, "unrecognized option: %s\n", argv[i]);
nuclear@3 384 return -1;
nuclear@2 385 }
nuclear@2 386 } else {
nuclear@9 387 if(fname) {
nuclear@9 388 fprintf(stderr, "unexpected argument: %s\n", argv[i]);
nuclear@2 389 return -1;
nuclear@2 390 }
nuclear@9 391 fname = argv[i];
nuclear@0 392 }
nuclear@0 393 }
nuclear@0 394
nuclear@9 395 if(!fname) {
nuclear@9 396 fprintf(stderr, "pass the volume descriptor filename\n");
nuclear@0 397 return -1;
nuclear@0 398 }
nuclear@0 399 return 0;
nuclear@0 400 }
nuclear@11 401 #endif
nuclear@0 402
nuclear@0 403
nuclear@11 404 static void create_ray_texture(int xsz, int ysz, float vfov, Vector2 *tex_scale)
nuclear@0 405 {
nuclear@1 406 int cur_tex_xsz, cur_tex_ysz;
nuclear@0 407 int tex_xsz = round_pow2(xsz);
nuclear@0 408 int tex_ysz = round_pow2(ysz);
nuclear@0 409 float *teximg, *dir;
nuclear@0 410
nuclear@11 411 teximg = new float[3 * xsz * ysz];
nuclear@0 412 dir = teximg;
nuclear@0 413
nuclear@11 414 for(int i=0; i<ysz; i++) {
nuclear@11 415 for(int j=0; j<xsz; j++) {
nuclear@11 416 Vector3 rdir = get_primary_ray_dir(j, i, xsz, ysz, vfov);
nuclear@1 417 *dir++ = rdir.x;
nuclear@1 418 *dir++ = rdir.y;
nuclear@1 419 *dir++ = rdir.z;
nuclear@0 420 }
nuclear@0 421 }
nuclear@0 422
nuclear@1 423 if(!ray_tex) {
nuclear@1 424 glGenTextures(1, &ray_tex);
nuclear@1 425 }
nuclear@1 426
nuclear@1 427 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &cur_tex_xsz);
nuclear@1 428 glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &cur_tex_ysz);
nuclear@1 429
nuclear@1 430 if(tex_xsz > cur_tex_xsz || tex_ysz > cur_tex_ysz) {
nuclear@1 431 glBindTexture(GL_TEXTURE_2D, ray_tex);
nuclear@1 432 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
nuclear@1 433 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
nuclear@1 434 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
nuclear@1 435 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
nuclear@1 436 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F_ARB, tex_xsz, tex_ysz, 0, GL_RGB, GL_FLOAT, 0);
nuclear@1 437 }
nuclear@1 438
nuclear@1 439 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, xsz, ysz, GL_RGB, GL_FLOAT, teximg);
nuclear@11 440 delete [] teximg;
nuclear@0 441
nuclear@0 442 if(tex_scale) {
nuclear@0 443 tex_scale->x = (float)xsz / (float)tex_xsz;
nuclear@0 444 tex_scale->y = (float)ysz / (float)tex_ysz;
nuclear@0 445 }
nuclear@11 446 raytex_needs_recalc = false;
nuclear@0 447 }
nuclear@0 448
nuclear@11 449 static Vector3 get_primary_ray_dir(int x, int y, int w, int h, float vfov_deg)
nuclear@0 450 {
nuclear@0 451 float vfov = M_PI * vfov_deg / 180.0;
nuclear@0 452 float aspect = (float)w / (float)h;
nuclear@0 453
nuclear@0 454 float ysz = 2.0;
nuclear@0 455 float xsz = aspect * ysz;
nuclear@0 456
nuclear@0 457 float px = ((float)x / (float)w) * xsz - xsz / 2.0;
nuclear@0 458 float py = 1.0 - ((float)y / (float)h) * ysz;
nuclear@0 459 float pz = 1.0 / tan(0.5 * vfov);
nuclear@0 460
nuclear@0 461 float mag = sqrt(px * px + py * py + pz * pz);
nuclear@11 462 return Vector3(px / mag, py / mag, pz / mag);
nuclear@0 463 }
nuclear@0 464
nuclear@0 465 static int round_pow2(int x)
nuclear@0 466 {
nuclear@0 467 x--;
nuclear@0 468 x = (x >> 1) | x;
nuclear@0 469 x = (x >> 2) | x;
nuclear@0 470 x = (x >> 4) | x;
nuclear@0 471 x = (x >> 8) | x;
nuclear@0 472 x = (x >> 16) | x;
nuclear@0 473 return x + 1;
nuclear@0 474 }
nuclear@0 475
nuclear@3 476 static void create_transfer_map(float mean, float sdev)
nuclear@3 477 {
nuclear@3 478 static float map[XFER_MAP_SZ];
nuclear@3 479
nuclear@3 480 if(!xfer_tex) {
nuclear@3 481 glGenTextures(1, &xfer_tex);
nuclear@3 482 glBindTexture(GL_TEXTURE_1D, xfer_tex);
nuclear@3 483 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
nuclear@3 484 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
nuclear@3 485 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
nuclear@3 486 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
nuclear@3 487 glTexImage1D(GL_TEXTURE_1D, 0, GL_LUMINANCE32F_ARB, XFER_MAP_SZ, 0, GL_LUMINANCE, GL_FLOAT, 0);
nuclear@3 488 }
nuclear@3 489
nuclear@11 490 for(int i=0; i<XFER_MAP_SZ; i++) {
nuclear@4 491 float x = (float)i / (float)(XFER_MAP_SZ - 1);
nuclear@4 492 map[i] = gaussian(x, mean, sdev) - 1.0;
nuclear@3 493 }
nuclear@3 494
nuclear@4 495 glTexSubImage1D(GL_TEXTURE_1D, 0, 0, XFER_MAP_SZ, GL_LUMINANCE, GL_FLOAT, map);
nuclear@11 496 xfertex_needs_recalc = false;
nuclear@3 497 }