source: trunk/vizservers/nanovis/Nv.cpp @ 829

Last change on this file since 829 was 825, checked in by vrinside, 16 years ago

Image Loader initialization

  • Add BMP loader in Nv.cpp

Point Renderer code added..

  • Put a data container and manage the containters with std::vector
  • Renderer 1) scale factor part should be taken into account
File size: 4.6 KB
Line 
1#include "Nv.h"
2#include "NvShader.h"
3#include "NvParticleRenderer.h"
4#include "NvColorTableRenderer.h"
5#include "NvEventLog.h"
6#include "VolumeRenderer.h"
7#include "Grid.h"
8#include <R2/R2FilePath.h>
9#include <stdio.h>
10#include <stdlib.h>
11#include <assert.h>
12#include <imgLoaders/BMPImageLoaderImpl.h>
13#include <imgLoaders/ImageLoaderFactory.h>
14#include "PointSetRenderer.h"
15
16extern void NvInitCG(); // in NvShader.cpp
17
18NvParticleRenderer* g_particleRenderer;
19NvColorTableRenderer* g_color_table_renderer;
20PointSetRenderer* g_pointset_renderer;
21VolumeRenderer* g_vol_render;
22R2Fonts* g_fonts;
23Grid* g_grid;
24
25
26//query opengl information
27static void NvPrintSystemInfo()
28{
29    fprintf(stderr, "-----------------------------------------------------------\n");
30    fprintf(stderr, "OpenGL driver: %s %s\n", glGetString(GL_VENDOR), glGetString(GL_VERSION));
31    fprintf(stderr, "Graphics hardware: %s\n", glGetString(GL_RENDERER));
32    fprintf(stderr, "-----------------------------------------------------------\n");
33}
34
35void NvCgErrorCallback(void)
36{
37    CGerror lastError = cgGetError();
38    if(lastError) {
39        const char *listing = cgGetLastListing(g_context);
40        printf("\n---------------------------------------------------\n");
41        printf("%s\n\n", cgGetErrorString(lastError));
42        printf("%s\n", listing);
43        printf("-----------------------------------------------------\n");
44        printf("Cg error, exiting...\n");
45        cgDestroyContext(g_context);
46        exit(-1);
47    }
48}
49
50
51void NvInitGLEW()
52{
53    GLenum err = glewInit();
54    if (GLEW_OK != err) {
55        //glew init failed, exit.
56        fprintf(stderr, "Error: %s\n", glewGetErrorString(err));
57        getchar();
58        assert(false);
59    }
60    fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));
61}
62
63//init line integral convolution
64
65
66//init line integral convolution
67void NvInitLIC()
68{
69/*
70    g_lic = new Lic(NMESH, win_width, win_height, 0.3, g_context, volume[1]->id,
71        volume[1]->aspect_ratio_width,
72        volume[1]->aspect_ratio_height,
73        volume[1]->aspect_ratio_depth);
74        */
75}
76
77void NvInitParticle()
78{
79/*
80    //random placement on a slice
81    float* data = new float[g_particleRenderer->psys_width * g_particleRenderer->psys_height * 4];
82    bzero(data, sizeof(float)*4* g_particleRenderer->psys_width * g_particleRenderer->psys_height);
83
84    int index;
85    bool particle;
86    for (int i=0; i<g_particleRenderer->psys_width; i++) {
87        for (int j=0; j<g_particleRenderer->psys_height; j++) {
88            index = i + g_particleRenderer->psys_height*j;
89            particle = rand() % 256 > 150;
90            if(particle)
91            {
92                //assign any location (x,y,z) in range [0,1]
93                data[4*index] = lic_slice_x;
94                data[4*index+1]= j/float(g_particleRenderer->psys_height);
95                data[4*index+2]= i/float(g_particleRenderer->psys_width);
96                data[4*index+3]= 30; //shorter life span, quicker iterations   
97            }
98            else
99            {
100                data[4*index] = 0;
101                data[4*index+1]= 0;
102                data[4*index+2]= 0;
103                data[4*index+3]= 0;     
104            }
105        }
106    }
107
108    g_particleRenderer->initialize((Particle*)data);
109    delete[] data;
110    */
111}
112
113//init the particle system using vector field volume->[1]
114void NvInitParticleRenderer()
115{
116/*
117    g_particleRenderer = new NvParticleRenderer(NMESH, NMESH, g_context,
118        volume[1]->id,
119        1./volume[1]->aspect_ratio_width,
120        1./volume[1]->aspect_ratio_height,
121        1./volume[1]->aspect_ratio_depth);
122
123    NvInitParticle();
124*/
125}
126
127void NvInitVolumeRenderer()
128{
129}
130
131void NvInitPointSetRenderer()
132{
133    g_pointset_renderer = new PointSetRenderer();
134}
135
136void NvInit(char* path)
137{
138    if (path != NULL) {
139        R2FilePath::getInstance()->setPath(path);
140    }
141
142    NvPrintSystemInfo();
143    NvInitGLEW();
144    NvInitCG();
145
146    g_fonts = new R2Fonts();
147    g_fonts->addFont("verdana", "verdana.fnt");
148    g_fonts->setFont("verdana");
149
150    //g_color_table_renderer = new NvColorTableRenderer();
151    // INSOO
152    //g_color_table_renderer->setFonts(g_fonts);
153    //
154
155    ImageLoaderFactory::getInstance()->addLoaderImpl("bmp", new BMPImageLoaderImpl());
156
157    g_grid = new Grid();
158    g_grid->setFont(g_fonts);
159
160    NvInitVolumeRenderer();
161    NvInitPointSetRenderer();
162    NvInitParticleRenderer();
163   
164    printf("Nanovis GL Initialized\n");
165}
166
167void NvExit()
168{
169    if (g_particleRenderer)
170    {
171        delete g_particleRenderer;
172        g_particleRenderer;
173    }
174
175#ifdef EVENTLOG
176    NvExitEventLog();
177#endif
178
179#ifdef XINETD
180    NvExitService();
181#endif
182
183}
184
Note: See TracBrowser for help on using the repository browser.