volray

annotate src/volray.c @ 4:3e53a16d4667

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