12 |
|
|
13 |
#include "GL/glfw.h" |
#include "GL/glfw.h" |
14 |
#include "util.h" |
#include "util.h" |
15 |
#include "vr-lite.h" |
#include "vr.h" |
16 |
#include <unistd.h> |
#include <unistd.h> |
17 |
|
|
18 |
/* minimum and maximum values from */ |
/* minimum and maximum values from */ |
54 |
Nrrd *Diderot; // input image nrrd |
Nrrd *Diderot; // input image nrrd |
55 |
unsigned int Width; // view window width |
unsigned int Width; // view window width |
56 |
unsigned int Height; // view window height |
unsigned int Height; // view window height |
57 |
GLuint ImageTexture; // Texture ID of background image |
bool NeedsRedraw; |
58 |
|
bool NeedsRecompute; |
59 |
|
|
60 |
|
|
61 |
|
|
100 |
0.0, 0.0, 0.0, |
0.0, 0.0, 0.0, |
101 |
0.0, 1.0, 0.0); |
0.0, 1.0, 0.0); |
102 |
|
|
|
// Send the new window size to AntTweakBar |
|
|
TwWindowSize(width, height); |
|
|
|
|
103 |
// remember width and height |
// remember width and height |
104 |
Width = width; |
Width = width; |
105 |
Height = height; |
Height = height; |
106 |
|
|
107 |
} |
} |
108 |
|
|
109 |
// initialize a texture from a grayscale Nrrd file |
void GetData (VR_World_t *wrld, Nrrd *nRGB) |
|
void InitTexture () |
|
|
{ |
|
|
Image2D_t *img = LoadImage ("data/ddro-tx.png", true, GRAY_IMAGE); |
|
|
if (img == 0) { |
|
|
fprintf (stderr, "unable to load texture file\n"); |
|
|
exit (1); |
|
|
} |
|
|
|
|
|
// generate the TeXID |
|
|
GLuint texId; |
|
|
glGenTextures (1, &texId); |
|
|
|
|
|
// load the texture data |
|
|
glBindTexture (GL_TEXTURE_2D, texId); |
|
|
int sts = TexImage (img); |
|
|
if (sts != GL_NO_ERROR) { |
|
|
fprintf(stderr, "error loading texture\n"); |
|
|
exit (1); |
|
|
} |
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
|
|
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
|
|
|
|
|
FreeImage (img); |
|
|
|
|
|
ImageTexture = texId; |
|
|
} |
|
|
|
|
|
void TW_CALL StartButtonCB (void *data) |
|
|
{ |
|
|
State_t *st = (State_t *)data; |
|
|
|
|
|
if (st->running == 0) { |
|
|
st->running = 1; |
|
|
TwSetParam (st->ctls, "StartButton", "label", TW_PARAM_CSTRING, 1, "Stop"); |
|
|
} |
|
|
else { |
|
|
st->running = 0; |
|
|
TwSetParam (st->ctls, "StartButton", "label", TW_PARAM_CSTRING, 1, "Start"); |
|
|
} |
|
|
} |
|
|
|
|
|
void GetData (VR_World_t *wrld, Nrrd *nData) |
|
110 |
{ |
{ |
111 |
// get snapshot of state |
if (VR_OutputGet_outRGBA (wrld, nRGB)) { |
|
if (VR_Snapshot_pos (wrld, nData)) { |
|
112 |
// error |
// error |
113 |
fprintf(stderr, "Error getting nrrd data\n"); |
fprintf(stderr, "Error getting nrrd data\n"); |
114 |
exit(1); |
exit(1); |
137 |
|
|
138 |
// Set GLFW event callbacks |
// Set GLFW event callbacks |
139 |
glfwSetWindowSizeCallback (WindowSizeCB); |
glfwSetWindowSizeCallback (WindowSizeCB); |
140 |
glfwSetKeyCallback ((GLFWkeyfun)TwEventKeyGLFW); |
/* FIXME: set up key callback */ |
|
|
|
|
// load Diderot image for background texture |
|
|
InitTexture (); |
|
|
|
|
|
// setup the world coords. |
|
|
// FIXME: we should get these from the nrrd file, but for now I'm hard coding them |
|
|
WrldOrigin[0] = -0.0184375; |
|
|
WrldOrigin[1] = -0.0184375; |
|
|
WrldDim[0] = 0.013125 * 80.0; |
|
|
WrldDim[1] = 0.013125 * 80.0; |
|
141 |
|
|
142 |
// initialize the Diderot program |
// initialize the Diderot program |
143 |
VR_World_t *wrld = VR_Init (); |
VR_World_t *wrld = VR_Init (); |
146 |
Nrrd *nRGB = nrrdNew(); |
Nrrd *nRGB = nrrdNew(); |
147 |
|
|
148 |
// get and render initial state |
// get and render initial state |
149 |
GetData (wrld, nData); |
GetData (wrld, nRGB); |
150 |
Draw (nData); |
Draw (nRGB); |
151 |
|
|
152 |
// Main loop (repeated while window is not closed and [ESC] is not pressed) |
// Main loop (repeated while window is not closed and [ESC] is not pressed) |
153 |
NeedsRecompute = true; |
NeedsRecompute = true; |
162 |
fprintf(stderr, "Error getting nrrd data\n"); |
fprintf(stderr, "Error getting nrrd data\n"); |
163 |
exit(1); |
exit(1); |
164 |
} |
} |
165 |
|
NeedsRedraw = true; |
166 |
} |
} |
167 |
if (NeedsRedraw) { |
if (NeedsRedraw) { |
168 |
|
Draw (nRGB); |
169 |
|
NeedsRedraw = false; |
170 |
} |
} |
171 |
glfwWaitEvents(); |
glfwWaitEvents(); |
172 |
} |
} |
174 |
// shutdown the world |
// shutdown the world |
175 |
VR_Shutdown (wrld); |
VR_Shutdown (wrld); |
176 |
|
|
177 |
// Terminate AntTweakBar and GLFW |
// Terminate GLFW |
|
TwTerminate(); |
|
178 |
glfwTerminate(); |
glfwTerminate(); |
179 |
|
|
180 |
return 0; |
return 0; |