1
#include "NuxCore/NuxCore.h"
2
#include "NuxCore/Math/Matrix4.h"
3
#include "NuxGraphics/BitmapFormats.h"
4
#include "NuxGraphics/GraphicsDisplay.h"
5
#include "NuxGraphics/GLWindowManager.h"
6
#include "NuxGraphics/GraphicsEngine.h"
7
#include "NuxCore/FilePath.h"
9
#if defined(NUX_OS_WINDOWS)
10
#define PKGDATADIR "../../data/"
14
void RenderVolume(nux::GraphicsEngine* graphics_engine, nux::BaseTexture* volume, int x, int y);
16
nux::TextureVolume* LoadVolumeTexture()
18
TCHAR* texture_list[] =
20
TEXT(PKGDATADIR"/textures/0.png"),
21
TEXT(PKGDATADIR"/textures/1.png"),
22
TEXT(PKGDATADIR"/textures/2.png"),
23
TEXT(PKGDATADIR"/textures/3.png"),
24
TEXT(PKGDATADIR"/textures/4.png"),
25
TEXT(PKGDATADIR"/textures/5.png"),
26
TEXT(PKGDATADIR"/textures/6.png"),
27
TEXT(PKGDATADIR"/textures/7.png"),
28
TEXT(PKGDATADIR"/textures/8.png"),
29
TEXT(PKGDATADIR"/textures/9.png"),
34
nux::NBitmapData* texture_bitmap[10];
36
for (int i = 0; i < N; i++)
38
texture_bitmap[i] = nux::LoadImageFile(texture_list[i]);
41
int volume_width = texture_bitmap[0]->GetWidth();
42
int volume_height = texture_bitmap[0]->GetHeight();
43
nux::BitmapFormat format = texture_bitmap[0]->GetFormat();
45
for (int i = 1; i < N; i++)
47
if (volume_width != texture_bitmap[i]->GetWidth() || volume_height != texture_bitmap[i]->GetHeight())
49
nuxDebugMsg("[LoadVolumeTexture] Invalid volume textures");
51
for (int i = 0; i < N; i++)
53
delete texture_bitmap[i];
59
nux::NVolumeData* volume_bitmap = new nux::NVolumeData(format, volume_width, volume_height, N, 1);
61
for (int i = 0; i < N; i++)
63
volume_bitmap->SetSurface(i, 0, texture_bitmap[i]->GetSurface(0, 0));
66
for (int i = 0; i < N; i++)
68
delete texture_bitmap[i];
71
nux::TextureVolume* texture_volume = new nux::TextureVolume();
72
texture_volume->Update(volume_bitmap);
73
return texture_volume;
76
void RenderVolumeTexture()
78
nux::GraphicsDisplay* graphics_display = gGLWindowManager.CreateGLWindow("Load Volume Texture", 750, 100, nux::WINDOWSTYLE_NORMAL, 0, false);
79
nux::GraphicsEngine* graphics_engine = graphics_display->GetGraphicsEngine();
81
graphics_display->ShowWindow();
83
nux::BaseTexture* texture = LoadVolumeTexture();
84
nux::ObjectPtr<nux::CachedTextureVolume> cached_texture = texture->GetCachedTexture();
85
cached_texture->m_Texture->SetFiltering(GL_LINEAR, GL_LINEAR);
86
cached_texture.Release();
89
graphics_engine->GetWindowSize(w, h);
90
graphics_engine->SetViewport(0, 0, w, h);
91
graphics_engine->SetOrthographicProjectionMatrix(w, h);
94
memset(&event, 0, sizeof(nux::Event));
95
bool first_time = true;
99
CHECKGL(glClearColor(0.36f, 0.36f, 0.36f, 1));
100
CHECKGL(glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT|GL_STENCIL_BUFFER_BIT));
102
graphics_display->GetSystemEvent(&event);
104
if(first_time || (event.type == nux::NUX_SIZE_CONFIGURATION))
107
graphics_engine->DisableAllTextureMode(0);
108
graphics_engine->DisableAllTextureMode(1);
109
graphics_engine->DisableAllTextureMode(2);
110
graphics_engine->DisableAllTextureMode(3);
112
graphics_engine->GetWindowSize(w, h);
113
graphics_engine->SetViewport(0, 0, w, h);
114
graphics_engine->SetScissor(0, 0, w, h);
115
graphics_engine->SetOrthographicProjectionMatrix(w, h);
118
graphics_engine->SetViewport(0, 0, w, h);
119
graphics_engine->SetScissor(0, 0, w, h);
120
graphics_engine->ApplyModelViewMatrix();
121
graphics_engine->SetOrthographicProjectionMatrix(w, h);
123
nux::Matrix4 modelview_matrix = graphics_engine->GetOpenGLModelViewMatrix();
124
nux::Matrix4 projection_matrix = graphics_engine->GetOpenGLProjectionMatrix();
126
glMatrixMode(GL_MODELVIEW);
127
glLoadMatrixf((float*)(modelview_matrix.m));
129
glMatrixMode(GL_PROJECTION);
130
glLoadMatrixf((float*)(projection_matrix.m));
132
if(texture->Type().IsObjectType(nux::TextureVolume::StaticObjectType))
134
RenderVolume(graphics_engine, texture, 10, 10);
137
// else if(texture->Type().IsObjectType(nux::TextureFrameAnimation::StaticObjectType))
139
// nux::ObjectPtr<nux::CachedBaseTexture> glr = nux::GetGraphicsDisplay()->GetGraphicsEngine()->ResourceCache.FindCachedResourceById(texture->GetResourceIndex());
140
// nux::ObjectPtr<nux::IOpenGLAnimatedTexture> AnimatedTextureRef = glr->m_Texture; //glr->m_Texture.CastRef<nux::IOpenGLAnimatedTexture>();
142
// AnimatedTextureRef->PresentNextFrame();
143
// graphics_engine->SetTexture(GL_TEXTURE0, (nux::BaseTexture*) texture);
144
// CHECKGL( glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR) );
145
// CHECKGL( glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR) );
146
// //graphics_engine->SetEnvModeSelectTexture(GL_TEXTURE0);
148
// glEnable(GL_TEXTURE_RECTANGLE_ARB);
149
// glDisable(GL_TEXTURE_3D);
150
// glDisable(GL_TEXTURE_CUBE_MAP);
151
// glEnable(GL_BLEND);
152
// glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
156
// int width = texture->GetWidth();
157
// int height = texture->GetHeight();
159
// glBegin(GL_QUADS);
161
// glMultiTexCoord2fARB(GL_TEXTURE0, 0.0f, 0.0f);
162
// glVertex3f(x, y, 0);
163
// glMultiTexCoord2fARB(GL_TEXTURE0, 0.0f, texture->GetHeight());
164
// glVertex3f(x, y + height, 0);
165
// glMultiTexCoord2fARB(GL_TEXTURE0, texture->GetWidth(), texture->GetHeight());
166
// glVertex3f(x + width, y + height, 0);
167
// glMultiTexCoord2fARB(GL_TEXTURE0, texture->GetWidth(), 0.0f);
168
// glVertex3f(x + width, y, 0);
171
// glDisable(GL_BLEND);
175
// graphics_engine->SetTexture(GL_TEXTURE0, (nux::BaseTexture*) texture);
176
// CHECKGL( glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) );
177
// CHECKGL( glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) );
179
// //graphics_engine->SetEnvModeSelectTexture(GL_TEXTURE0);
181
// glEnable(GL_TEXTURE_2D);
182
// glDisable(GL_TEXTURE_3D);
183
// glDisable(GL_TEXTURE_CUBE_MAP);
190
// glBegin(GL_QUADS);
192
// glMultiTexCoord2fARB(GL_TEXTURE0, 0.0f, 0.0f);
193
// glVertex3f(x, y, 0);
194
// glMultiTexCoord2fARB(GL_TEXTURE0, 0.0f, 1.0);
195
// glVertex3f(x, y + height, 0);
196
// glMultiTexCoord2fARB(GL_TEXTURE0, 1.0f, 1.0);
197
// glVertex3f(x + width, y + height, 0);
198
// glMultiTexCoord2fARB(GL_TEXTURE0, 1.0f, 0.0);
199
// glVertex3f(x + width, y, 0);
203
// //glDisable(GL_TEXTURE_3D);
207
//sprintf(gFPS, "FPS: %3.2f", nux::GetGraphicsDisplay()->GetFrameRate());
215
//graphics_engine->RenderColorTextLineStatic(GFontBold, page, gFPS, 0xffff0000, eAlignTextLeft);
217
graphics_display->SwapBuffer();
218
} while(event.type != nux::NUX_TERMINATE_APP);
220
texture->UnReference();
221
delete graphics_display;
224
void RenderVolume(nux::GraphicsEngine* graphics_engine, nux::BaseTexture* volume, int x, int y)
226
// This function assume the projection matrix is orthographic
227
if(!volume->Type().IsObjectType(nux::TextureVolume::StaticObjectType))
230
graphics_engine->SetTexture(GL_TEXTURE0, (nux::BaseTexture*)volume);
231
CHECKGL( glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) );
232
CHECKGL( glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) );
238
for (int i = 0; i < volume->GetDepth(); i++)
242
glMultiTexCoord3fARB(GL_TEXTURE0, 0.0f, 0.0f, depth);
245
glMultiTexCoord3fARB(GL_TEXTURE0, 0.0f, 1.0, depth);
246
glVertex3f(x, y + height, 0);
248
glMultiTexCoord3fARB(GL_TEXTURE0, 1.0f, 1.0, depth);
249
glVertex3f(x + width, y + height, 0);
251
glMultiTexCoord3fARB(GL_TEXTURE0, 1.0f, 0.0, depth);
252
glVertex3f(x + width, y, 0);
258
depth += 1.0f / volume->GetDepth() + 0.001;
267
int main(int argc, char **argv)
269
nux::NuxCoreInitialize(0);
270
nux::NuxGraphicsInitialize();
272
RenderVolumeTexture();
b'\\ No newline at end of file'