1 | #include "RNA3D_GlobalHeader.hxx" |
---|
2 | #include "RNA3D_Global.hxx" |
---|
3 | #include "RNA3D_OpenGLEngine.hxx" |
---|
4 | #include "RNA3D_OpenGLGraphics.hxx" |
---|
5 | #include "RNA3D_StructureData.hxx" |
---|
6 | #include "RNA3D_Textures.hxx" |
---|
7 | #include "RNA3D_Renderer.hxx" |
---|
8 | #include "RNA3D_Graphics.hxx" |
---|
9 | #include "RNA3D_Interface.hxx" |
---|
10 | |
---|
11 | #include <iostream> |
---|
12 | |
---|
13 | #include <aw_awars.hxx> |
---|
14 | #include <BI_helix.hxx> |
---|
15 | |
---|
16 | #include <GL/aw_window_ogl.hxx> |
---|
17 | |
---|
18 | // -------------------------------------------------------------------------------- |
---|
19 | // global data |
---|
20 | |
---|
21 | RNA3D_Global *RNA3D = 0; |
---|
22 | char globalComment[1000]; |
---|
23 | |
---|
24 | void RNA3D_init_global_data() { |
---|
25 | if (!RNA3D) { |
---|
26 | RNA3D = new RNA3D_Global(); |
---|
27 | } |
---|
28 | } |
---|
29 | |
---|
30 | RNA3D_Global::RNA3D_Global(){ |
---|
31 | OpenGLEngineState = -1; |
---|
32 | iRotateMolecule = 0; |
---|
33 | bPointSpritesSupported = false; |
---|
34 | bEColiRefInitialised = false; |
---|
35 | bMapSaiDispListCreated = false; |
---|
36 | bAutoRotate = false; |
---|
37 | bRotateMolecule = false; |
---|
38 | bDisplayMask = false; |
---|
39 | bDisplayComments = false; |
---|
40 | bMapSearchStringsDispListCreated = false; |
---|
41 | |
---|
42 | ROTATION_SPEED = 0.5; |
---|
43 | scale = 0.01; |
---|
44 | |
---|
45 | cGraphics = new OpenGLGraphics(); |
---|
46 | cStructure = new Structure3D(); |
---|
47 | cTexture = new Texture2D(); |
---|
48 | cRenderer = new GLRenderer(); |
---|
49 | |
---|
50 | Viewer = Vector3(0.0, 0.0, -2); |
---|
51 | Center = Vector3(0.0, 0.0, 0.0); |
---|
52 | Up = Vector3(0.0, 1.0, 0.0); |
---|
53 | } |
---|
54 | |
---|
55 | RNA3D_Global::~RNA3D_Global() { |
---|
56 | delete cGraphics; |
---|
57 | delete cStructure; |
---|
58 | delete cTexture; |
---|
59 | delete cRenderer; |
---|
60 | } |
---|
61 | |
---|
62 | // end of global data section |
---|
63 | // -------------------------------------------------------------------------------- |
---|
64 | |
---|
65 | static float fAspectRatio; |
---|
66 | const float fViewAngle = 40.0; |
---|
67 | const float fClipNear = 0.5f; |
---|
68 | const float fClipFar = 100; |
---|
69 | |
---|
70 | // GBDATA *OpenGL_gb_main; |
---|
71 | |
---|
72 | static Display *dpy; |
---|
73 | static GLXContext glx_context; |
---|
74 | |
---|
75 | static int DoubleBufferWithAlpha[] = { GLX_RGBA, |
---|
76 | GLX_DEPTH_SIZE, 12, |
---|
77 | GLX_RED_SIZE, 4, |
---|
78 | GLX_GREEN_SIZE, 4, |
---|
79 | GLX_BLUE_SIZE, 4, |
---|
80 | GLX_ALPHA_SIZE, 4, |
---|
81 | GLX_DOUBLEBUFFER, |
---|
82 | None }; |
---|
83 | |
---|
84 | static int DoubleBuffer[] = { GLX_RGBA, |
---|
85 | GLX_DEPTH_SIZE, 12, |
---|
86 | GLX_RED_SIZE, 4, |
---|
87 | GLX_GREEN_SIZE, 4, |
---|
88 | GLX_BLUE_SIZE, 4, |
---|
89 | GLX_DOUBLEBUFFER, |
---|
90 | None }; |
---|
91 | |
---|
92 | static int SingleBuffer[] = { GLX_RGBA, |
---|
93 | GLX_DEPTH_SIZE, 12, |
---|
94 | GLX_RED_SIZE, 4, |
---|
95 | GLX_GREEN_SIZE, 4, |
---|
96 | GLX_BLUE_SIZE, 4, |
---|
97 | None }; |
---|
98 | |
---|
99 | static GLfloat rotation_matrix[16]; |
---|
100 | static GLfloat rot_x = 0.0, rot_y = 0.0; |
---|
101 | |
---|
102 | static int iScreenWidth, iScreenHeight; |
---|
103 | |
---|
104 | static bool bMapSpDispListCreated = false; |
---|
105 | static bool bCursorPosDispListCreated = false; |
---|
106 | static bool bHelixNrDispListCreated = false; |
---|
107 | |
---|
108 | using namespace std; |
---|
109 | |
---|
110 | void ShowVendorInformation(){ |
---|
111 | const GLubyte *vendor = NULL; |
---|
112 | vendor = glGetString(GL_VENDOR); cout<<"Vendor : "<<vendor<<endl; |
---|
113 | vendor = glGetString(GL_RENDERER); cout<<"Renderer: "<<vendor<<endl; |
---|
114 | vendor = glGetString(GL_VERSION); cout<<"Version : "<<vendor<<endl; |
---|
115 | } |
---|
116 | |
---|
117 | void initExtensions() { |
---|
118 | // check mandatory for extensions |
---|
119 | char missingExtensions[500]=""; |
---|
120 | if (!GLEW_VERSION_1_2) { |
---|
121 | strcat(missingExtensions,"\nOpenGL Version 1.2"); |
---|
122 | } |
---|
123 | if (strlen(missingExtensions) > 0) { |
---|
124 | printf("ERROR: Some needed extensions are not present:%s\n",missingExtensions); |
---|
125 | char dummy; scanf( "%c",&dummy); exit(-1); |
---|
126 | } else { |
---|
127 | #ifdef DEBUG |
---|
128 | printf("DEBUG: All mandatory extensions seem to be ok.\n"); |
---|
129 | #endif // DEBUG |
---|
130 | } |
---|
131 | |
---|
132 | // the following code checks if point sprites could be used and activates them if possible |
---|
133 | missingExtensions[0] = 0; |
---|
134 | if (!GLEW_EXT_point_parameters) strcat(missingExtensions,"\nGL_EXT_point_parameters"); |
---|
135 | if (!GLEW_ARB_point_sprite) strcat(missingExtensions,"\nGL_ARB_point_sprite"); |
---|
136 | if (strlen(missingExtensions) > 0) { |
---|
137 | printf("Some extra extensions are not present:%s\n",missingExtensions); |
---|
138 | printf("Molecule Display: Quality of Rendering is LOW!!\n"); |
---|
139 | RNA3D->bPointSpritesSupported = false; |
---|
140 | } else { |
---|
141 | #ifdef DEBUG |
---|
142 | printf("DEBUG: All extra extensions seem to be ok as well.\n"); |
---|
143 | #endif // DEBUG |
---|
144 | RNA3D->bPointSpritesSupported = true ; |
---|
145 | } |
---|
146 | } |
---|
147 | |
---|
148 | void ReshapeOpenGLWindow( GLint width, GLint height ) { |
---|
149 | iScreenWidth = width; |
---|
150 | iScreenHeight = height; |
---|
151 | |
---|
152 | fAspectRatio = (float) width / (float) height; |
---|
153 | |
---|
154 | glViewport( 0, 0, width, height ); |
---|
155 | glMatrixMode( GL_PROJECTION ); |
---|
156 | glLoadIdentity(); |
---|
157 | gluPerspective( fViewAngle, fAspectRatio, fClipNear, fClipFar ); |
---|
158 | glMatrixMode( GL_MODELVIEW ); |
---|
159 | glLoadIdentity(); |
---|
160 | } |
---|
161 | |
---|
162 | void InitializeOpenGLEngine(GLint width, GLint height ) { |
---|
163 | cout<<"RNA3D: Initializing OpenGLEngine : "<<width<<" x "<<height<<endl; |
---|
164 | |
---|
165 | RNA3D->saved_x = RNA3D->saved_y = 2.0f; |
---|
166 | ComputeRotationXY(1,1); |
---|
167 | |
---|
168 | //Get Information about Vendor & Version |
---|
169 | ShowVendorInformation(); |
---|
170 | |
---|
171 | GLenum err = glewInit(); |
---|
172 | if (GLEW_OK != err){ |
---|
173 | /* problem: glewInit failed, something is seriously wrong */ |
---|
174 | fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); |
---|
175 | } |
---|
176 | fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION)); |
---|
177 | |
---|
178 | initExtensions(); |
---|
179 | |
---|
180 | { // Preparing secondary structure masks for RNA3D program |
---|
181 | // RNA3D->cStructure->PrepareSecondaryStructureData(); |
---|
182 | } |
---|
183 | |
---|
184 | // Prepare the structure Data and Generate Display Lists |
---|
185 | |
---|
186 | RNA3D->cStructure->ReadCoOrdinateFile(); // Reading Structure information |
---|
187 | RNA3D->cStructure->GetSecondaryStructureInfo(); // Getting Secondary Structure Information |
---|
188 | RNA3D->cStructure->Combine2Dand3DstructureInfo(); // Combining Secondary Structure data with 3D Coordinates |
---|
189 | |
---|
190 | RNA3D->cStructure->GenerateDisplayLists(); // Generating Display Lists for Rendering |
---|
191 | |
---|
192 | // Generate Textures |
---|
193 | RNA3D->cTexture->LoadGLTextures(); // Load The Texture(s) |
---|
194 | |
---|
195 | glShadeModel(GL_SMOOTH); |
---|
196 | glClearColor(0,0,0,1); |
---|
197 | glClearDepth(1.0f); |
---|
198 | |
---|
199 | glEnable(GL_DEPTH_TEST); // Enables Depth Testing |
---|
200 | glDepthFunc(GL_LEQUAL); // The Type Of Depth Test To Do |
---|
201 | |
---|
202 | // glHint(GL_CLIP_VOLUME_CLIPPING_HINT_EXT,GL_DONT_CARE); |
---|
203 | glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); |
---|
204 | glEnable(GL_TEXTURE_2D); // Enable Texture Mapping |
---|
205 | |
---|
206 | ReshapeOpenGLWindow(width,height); |
---|
207 | |
---|
208 | CalculateRotationMatrix(); |
---|
209 | } |
---|
210 | |
---|
211 | void ComputeRotationXY(int x, int y) { |
---|
212 | GLfloat dx, dy; |
---|
213 | dx = RNA3D->saved_x - x; |
---|
214 | dy = RNA3D->saved_y - y; |
---|
215 | rot_y = (GLfloat)(x - RNA3D->saved_x) * RNA3D->ROTATION_SPEED; |
---|
216 | rot_x = (GLfloat)(y - RNA3D->saved_y) * RNA3D->ROTATION_SPEED; |
---|
217 | RNA3D->saved_x = x; |
---|
218 | RNA3D->saved_y = y; |
---|
219 | } |
---|
220 | |
---|
221 | void CalculateRotationMatrix(){ |
---|
222 | static int initialized = 0; |
---|
223 | GLfloat new_rotation_matrix[16]; |
---|
224 | |
---|
225 | /* calculate new rotation matrix */ |
---|
226 | glPushMatrix(); |
---|
227 | glLoadIdentity(); |
---|
228 | glRotatef(-rot_x, 1.0, 0.0, 0.0); |
---|
229 | glRotatef(rot_y, 0.0, 1.0, 0.0); |
---|
230 | glGetFloatv(GL_MODELVIEW_MATRIX, new_rotation_matrix); |
---|
231 | glPopMatrix(); |
---|
232 | |
---|
233 | /* calculate total rotation */ |
---|
234 | glPushMatrix(); |
---|
235 | glLoadIdentity(); |
---|
236 | glMultMatrixf(new_rotation_matrix); |
---|
237 | if (initialized) { |
---|
238 | glMultMatrixf(rotation_matrix); |
---|
239 | } |
---|
240 | |
---|
241 | glGetFloatv(GL_MODELVIEW_MATRIX, rotation_matrix); |
---|
242 | initialized = 1; |
---|
243 | glPopMatrix(); |
---|
244 | } |
---|
245 | |
---|
246 | void MapDisplayParameters(AW_root *root){ |
---|
247 | GLRenderer *cRenderer = RNA3D->cRenderer; |
---|
248 | Structure3D *cStructure = RNA3D->cStructure; |
---|
249 | |
---|
250 | // General Molecule Display Section |
---|
251 | cRenderer->iBackBone = root->awar(AWAR_3D_MOL_BACKBONE)->read_int(); |
---|
252 | cRenderer->iColorise = root->awar(AWAR_3D_MOL_COLORIZE)->read_int(); |
---|
253 | cRenderer->fSkeletonSize = root->awar(AWAR_3D_MOL_SIZE)->read_float(); |
---|
254 | cRenderer->iDispPos = root->awar(AWAR_3D_MOL_DISP_POS)->read_int(); |
---|
255 | cStructure->iInterval = root->awar(AWAR_3D_MOL_POS_INTERVAL)->read_int(); |
---|
256 | cRenderer->iDispCursorPos = root->awar(AWAR_3D_CURSOR_POSITION)->read_int(); |
---|
257 | RNA3D->iRotateMolecule = root->awar(AWAR_3D_MOL_ROTATE)->read_int(); |
---|
258 | |
---|
259 | // Display Bases Section |
---|
260 | cRenderer->iDisplayBases = root->awar(AWAR_3D_DISPLAY_BASES)->read_int(); |
---|
261 | cRenderer->ObjectSize = root->awar(AWAR_3D_DISPLAY_SIZE)->read_float(); |
---|
262 | cRenderer->iBaseMode = root->awar(AWAR_3D_BASES_MODE)->read_int(); |
---|
263 | cRenderer->iBaseHelix = root->awar(AWAR_3D_BASES_HELIX)->read_int(); |
---|
264 | cRenderer->iBaseUnpairHelix = root->awar(AWAR_3D_BASES_UNPAIRED_HELIX)->read_int(); |
---|
265 | cRenderer->iBaseNonHelix = root->awar(AWAR_3D_BASES_NON_HELIX)->read_int(); |
---|
266 | cRenderer->iShapeHelix = root->awar(AWAR_3D_SHAPES_HELIX)->read_int(); |
---|
267 | cRenderer->iShapeUnpairHelix = root->awar(AWAR_3D_SHAPES_UNPAIRED_HELIX)->read_int(); |
---|
268 | cRenderer->iShapeNonHelix = root->awar(AWAR_3D_SHAPES_NON_HELIX)->read_int(); |
---|
269 | |
---|
270 | //Display Helices Section |
---|
271 | cRenderer->iDisplayHelix = root->awar(AWAR_3D_DISPLAY_HELIX)->read_int(); |
---|
272 | cRenderer->iHelixMidPoint = root->awar(AWAR_3D_HELIX_MIDPOINT)->read_int(); |
---|
273 | cRenderer->iHelixNrs = root->awar(AWAR_3D_HELIX_NUMBER)->read_int(); |
---|
274 | cRenderer->fHelixSize = root->awar(AWAR_3D_HELIX_SIZE)->read_float(); |
---|
275 | cRenderer->iHelixBackBone = root->awar(AWAR_3D_HELIX_BACKBONE)->read_int(); |
---|
276 | cRenderer->iStartHelix = root->awar(AWAR_3D_HELIX_FROM)->read_int(); |
---|
277 | cRenderer->iEndHelix = root->awar(AWAR_3D_HELIX_TO)->read_int(); |
---|
278 | cRenderer->iDispTerInt = root->awar(AWAR_3D_DISPLAY_TERTIARY_INTRACTIONS)->read_int(); |
---|
279 | |
---|
280 | // Mapping Sequence Data Section |
---|
281 | cStructure->iMapSAI = root->awar(AWAR_3D_MAP_SAI)->read_int(); |
---|
282 | cStructure->iMapSearch = root->awar(AWAR_3D_MAP_SEARCH_STRINGS)->read_int(); |
---|
283 | cStructure->iMapEnable = root->awar(AWAR_3D_MAP_ENABLE)->read_int(); |
---|
284 | cRenderer->iMapSpecies = root->awar(AWAR_3D_MAP_SPECIES)->read_int(); |
---|
285 | cRenderer->iMapSpeciesBase = root->awar(AWAR_3D_MAP_SPECIES_DISP_BASE)->read_int(); |
---|
286 | cRenderer->iMapSpeciesPos = root->awar(AWAR_3D_MAP_SPECIES_DISP_POS)->read_int(); |
---|
287 | cRenderer->iMapSpeciesDels = root->awar(AWAR_3D_MAP_SPECIES_DISP_DELETIONS)->read_int(); |
---|
288 | cRenderer->iMapSpeciesMiss = root->awar(AWAR_3D_MAP_SPECIES_DISP_MISSING)->read_int(); |
---|
289 | cRenderer->iMapSpeciesIns = root->awar(AWAR_3D_MAP_SPECIES_DISP_INSERTIONS)->read_int(); |
---|
290 | cRenderer->iMapSpeciesInsInfo = root->awar(AWAR_3D_MAP_SPECIES_DISP_INSERTIONS_INFO)->read_int(); |
---|
291 | |
---|
292 | { // Validation of Helix Numbers entered by the User |
---|
293 | int NoOfHelices = 0; |
---|
294 | int rnaType = cStructure->FindTypeOfRNA(); |
---|
295 | switch (rnaType){ |
---|
296 | case LSU_23S: NoOfHelices = 101; break; |
---|
297 | case SSU_16S: NoOfHelices = 50; break; |
---|
298 | case LSU_5S: NoOfHelices = 5; break; |
---|
299 | } |
---|
300 | |
---|
301 | if (cRenderer->iStartHelix < 1 || cRenderer->iStartHelix > NoOfHelices ) { |
---|
302 | cout<<"Invalid Helix NUMBER !!"<<endl; |
---|
303 | root->awar(AWAR_3D_HELIX_FROM)->write_int(1); |
---|
304 | } |
---|
305 | if (cRenderer->iEndHelix < 1 || cRenderer->iEndHelix > NoOfHelices ) { |
---|
306 | cout<<"Invalid Helix NUMBER !!"<<endl; |
---|
307 | root->awar(AWAR_3D_HELIX_TO)->write_int(NoOfHelices); |
---|
308 | } |
---|
309 | |
---|
310 | if(cRenderer->iStartHelix > cRenderer->iEndHelix) { |
---|
311 | root->awar(AWAR_3D_HELIX_FROM)->write_int(cRenderer->iEndHelix - 1); |
---|
312 | } |
---|
313 | else if(cRenderer->iEndHelix < cRenderer->iStartHelix) { |
---|
314 | root->awar(AWAR_3D_HELIX_TO)->write_int(cRenderer->iStartHelix + 1); |
---|
315 | } |
---|
316 | } |
---|
317 | |
---|
318 | // Generation of DisplayLists for displaying Helix Numbers |
---|
319 | if (!bHelixNrDispListCreated && |
---|
320 | (cRenderer->iHelixNrs || cRenderer->iHelixMidPoint)) |
---|
321 | { |
---|
322 | cStructure->GenerateHelixNrDispList(cRenderer->iStartHelix, cRenderer->iEndHelix); |
---|
323 | bHelixNrDispListCreated = true; |
---|
324 | } |
---|
325 | |
---|
326 | // Validation of Base Position display |
---|
327 | if(cStructure->iInterval < 1) { |
---|
328 | cout<<"WARNING: Invalid POSITION Interval!! Setting it to Default Value (25)."<<endl; |
---|
329 | root->awar(AWAR_3D_MOL_POS_INTERVAL)->write_int(25); |
---|
330 | } |
---|
331 | |
---|
332 | if (cStructure->iMapEnable) |
---|
333 | { |
---|
334 | if (cStructure->iMapSearch) { |
---|
335 | if (!RNA3D->bMapSearchStringsDispListCreated) { |
---|
336 | cStructure->MapSearchStringsToEcoliTemplate(root); |
---|
337 | } |
---|
338 | } |
---|
339 | if (cStructure->iMapSAI) { |
---|
340 | if (!RNA3D->bMapSaiDispListCreated) { |
---|
341 | cStructure->MapSaiToEcoliTemplate(root); |
---|
342 | } |
---|
343 | } |
---|
344 | if(!bMapSpDispListCreated) { |
---|
345 | cStructure->MapCurrentSpeciesToEcoliTemplate(root); |
---|
346 | bMapSpDispListCreated = true; |
---|
347 | } |
---|
348 | } |
---|
349 | } |
---|
350 | |
---|
351 | |
---|
352 | void DisplayPostionsIntervalChanged_CB(AW_root *awr) { |
---|
353 | MapDisplayParameters(awr); |
---|
354 | glDeleteLists(STRUCTURE_POS,2); |
---|
355 | RNA3D->cStructure->ComputeBasePositions(); |
---|
356 | RefreshOpenGLDisplay(); |
---|
357 | } |
---|
358 | |
---|
359 | void MapSelectedSpeciesChanged_CB(AW_root *awr) { |
---|
360 | |
---|
361 | // If Selected Species (in Primary Editor) changed and |
---|
362 | // the MapSpecies display lists created then, |
---|
363 | // 1. Delete the display lists; |
---|
364 | // 2. Recalculate the Display lists for current species; |
---|
365 | // 3. Map it to EColi Template; |
---|
366 | |
---|
367 | if (RNA3D->cStructure->iMapEnable && |
---|
368 | RNA3D->cRenderer->iMapSpecies && |
---|
369 | bMapSpDispListCreated) |
---|
370 | { |
---|
371 | glDeleteLists(MAP_SPECIES_BASE_DIFFERENCE,9); |
---|
372 | RNA3D->cStructure->MapCurrentSpeciesToEcoliTemplate(awr); |
---|
373 | } |
---|
374 | |
---|
375 | // If selected species changed then regenerate the SearchStrings DisplayList |
---|
376 | MapSearchStringsToEcoliTemplateChanged_CB(awr); |
---|
377 | |
---|
378 | RefreshOpenGLDisplay(); |
---|
379 | } |
---|
380 | |
---|
381 | void MapSaiToEcoliTemplateChanged_CB(AW_root *awr) { |
---|
382 | //if SAI changed in EDIT4 then diplay lists should be recalculated |
---|
383 | |
---|
384 | if (RNA3D->cStructure->iMapEnable && |
---|
385 | RNA3D->cStructure->iMapSAI && |
---|
386 | RNA3D->bMapSaiDispListCreated ) |
---|
387 | { |
---|
388 | RNA3D->bMapSaiDispListCreated = false; |
---|
389 | glDeleteLists(MAP_SAI_TO_STRUCTURE,1); |
---|
390 | RNA3D->cStructure->MapSaiToEcoliTemplate(awr); |
---|
391 | } |
---|
392 | |
---|
393 | RefreshOpenGLDisplay(); |
---|
394 | } |
---|
395 | |
---|
396 | void MapSearchStringsToEcoliTemplateChanged_CB(AW_root *awr) { |
---|
397 | |
---|
398 | // If selected species changed then regenerate the |
---|
399 | // SearchStrings DisplayList |
---|
400 | |
---|
401 | if (RNA3D->cStructure->iMapEnable && |
---|
402 | RNA3D->cStructure->iMapSearch && |
---|
403 | RNA3D->bMapSearchStringsDispListCreated) |
---|
404 | { |
---|
405 | RNA3D->bMapSearchStringsDispListCreated = false; |
---|
406 | glDeleteLists(MAP_SEARCH_STRINGS_TO_STRUCTURE,2); |
---|
407 | RNA3D->cStructure->MapSearchStringsToEcoliTemplate(awr); |
---|
408 | } |
---|
409 | } |
---|
410 | |
---|
411 | void CursorPositionChanged_CB(AW_root *awr) { |
---|
412 | |
---|
413 | if(RNA3D->bEColiRefInitialised) { |
---|
414 | long iCursorPos = awr->awar(AWAR_CURSOR_POSITION)->read_int(); |
---|
415 | long EColiPos = RNA3D->cStructure->EColiRef->abs_2_rel(iCursorPos); |
---|
416 | |
---|
417 | if (!bCursorPosDispListCreated) { |
---|
418 | RNA3D->cStructure->GenerateCursorPositionDispList(EColiPos); |
---|
419 | bMapSpDispListCreated = true; |
---|
420 | } |
---|
421 | else { |
---|
422 | glDeleteLists(ECOLI_CURSOR_POSITION,1); |
---|
423 | RNA3D->cStructure->GenerateCursorPositionDispList(EColiPos); |
---|
424 | } |
---|
425 | RefreshOpenGLDisplay(); |
---|
426 | } |
---|
427 | } |
---|
428 | |
---|
429 | void DisplayHelixNrsChanged_CB(AW_root *awr) { |
---|
430 | MapDisplayParameters(awr); |
---|
431 | |
---|
432 | int iStart = RNA3D->cRenderer->iStartHelix; |
---|
433 | int iEnd = RNA3D->cRenderer->iEndHelix; |
---|
434 | if (!bHelixNrDispListCreated) { |
---|
435 | RNA3D->cStructure->GenerateHelixNrDispList(iStart, iEnd); |
---|
436 | bHelixNrDispListCreated = true; |
---|
437 | } |
---|
438 | else { |
---|
439 | glDeleteLists(HELIX_NUMBERS, 2); |
---|
440 | RNA3D->cStructure->GenerateHelixNrDispList(iStart, iEnd); |
---|
441 | } |
---|
442 | RefreshOpenGLDisplay(); |
---|
443 | } |
---|
444 | |
---|
445 | void DrawStructure(){ |
---|
446 | GLRenderer *cRenderer = RNA3D->cRenderer; |
---|
447 | |
---|
448 | // Drawing Molecule Skeleton |
---|
449 | cRenderer->DisplayMolecule(RNA3D->cStructure); |
---|
450 | |
---|
451 | // Mapping Helices to The molecule |
---|
452 | cRenderer->DoHelixMapping(); |
---|
453 | |
---|
454 | // Texture Mapping |
---|
455 | cRenderer->BeginTexturizer(); |
---|
456 | cRenderer->TexturizeStructure(RNA3D->cTexture, RNA3D->cStructure); |
---|
457 | cRenderer->EndTexturizer(); |
---|
458 | } |
---|
459 | |
---|
460 | void RenderOpenGLScene(Widget w){ |
---|
461 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// | GL_STENCIL_BUFFER_BIT); |
---|
462 | |
---|
463 | // setting the BackGround Color of the OpenGL Scene |
---|
464 | RNA3D->cGraphics->SetOpenGLBackGroundColor(); |
---|
465 | |
---|
466 | glLoadIdentity(); |
---|
467 | |
---|
468 | gluLookAt(RNA3D->Viewer.x, RNA3D->Viewer.y, RNA3D->Viewer.z, |
---|
469 | RNA3D->Center.x, RNA3D->Center.y, RNA3D->Center.z, |
---|
470 | RNA3D->Up.x, RNA3D->Up.y, RNA3D->Up.z); |
---|
471 | |
---|
472 | {// Displaying Molecule Name |
---|
473 | RNA3D->cRenderer->DisplayMoleculeName(iScreenWidth, iScreenHeight, RNA3D->cStructure); |
---|
474 | } |
---|
475 | |
---|
476 | glScalef(RNA3D->scale, RNA3D->scale, RNA3D->scale); |
---|
477 | |
---|
478 | RNA3D->cRenderer->DisplayMoleculeMask(iScreenWidth, iScreenHeight); |
---|
479 | |
---|
480 | if(RNA3D->bRotateMolecule || RNA3D->bAutoRotate) { |
---|
481 | CalculateRotationMatrix(); |
---|
482 | } |
---|
483 | |
---|
484 | glMultMatrixf(rotation_matrix); |
---|
485 | |
---|
486 | Vector3& strCen = *RNA3D->cStructure->strCen; |
---|
487 | glTranslatef(-strCen.x, -strCen.y, -strCen.z); |
---|
488 | |
---|
489 | DrawStructure(); |
---|
490 | |
---|
491 | glFlush(); |
---|
492 | glXWaitX(); |
---|
493 | glXSwapBuffers ( XtDisplay( w ), XtWindow( w ) ); |
---|
494 | } |
---|
495 | |
---|
496 | void InitializeOpenGLWindow( Widget w ) { |
---|
497 | |
---|
498 | if (RNA3D->OpenGLEngineState == CREATED) return; |
---|
499 | |
---|
500 | Arg args[1]; |
---|
501 | XVisualInfo *vi; |
---|
502 | |
---|
503 | XtSetArg(args[0], (char *) GLwNvisualInfo, &vi); |
---|
504 | XtGetValues(w, args, 1); |
---|
505 | |
---|
506 | dpy = XtDisplay(w); |
---|
507 | if (!dpy) { |
---|
508 | fprintf(stderr, "could not open display\n"); |
---|
509 | } |
---|
510 | else { |
---|
511 | if (AW_alpha_Size_Supported) { |
---|
512 | vi = glXChooseVisual(dpy, DefaultScreen( dpy ), DoubleBufferWithAlpha); |
---|
513 | printf("RNA3D: Double Buffered Visual With Alpha Size Supported !\n"); |
---|
514 | } |
---|
515 | else { |
---|
516 | vi = glXChooseVisual(dpy, DefaultScreen( dpy ), DoubleBuffer); |
---|
517 | printf("RNA3D: Double Buffered Visual Supported !\n"); |
---|
518 | } |
---|
519 | |
---|
520 | if (!vi) { |
---|
521 | fprintf(stderr, "try to get a single buffered visual\n"); |
---|
522 | vi = glXChooseVisual(dpy, DefaultScreen(dpy), SingleBuffer); |
---|
523 | if (!vi) |
---|
524 | fprintf(stderr, "could not get visual\n"); |
---|
525 | } |
---|
526 | else { |
---|
527 | glx_context = glXCreateContext(dpy, vi, NULL, GL_TRUE); |
---|
528 | if (!glXIsDirect(dpy, glx_context)) |
---|
529 | fprintf(stderr, "direct rendering not supported\n"); |
---|
530 | else |
---|
531 | printf("RNA3D: Direct rendering supported\n"); |
---|
532 | |
---|
533 | GLwDrawingAreaMakeCurrent(w, glx_context); |
---|
534 | |
---|
535 | RNA3D->glw = w; |
---|
536 | |
---|
537 | RNA3D->OpenGLEngineState = CREATED; |
---|
538 | |
---|
539 | // Initializing fonts |
---|
540 | char fontName[] = "fixed"; |
---|
541 | RNA3D->cGraphics->InitMainFont(fontName); |
---|
542 | } |
---|
543 | } |
---|
544 | } |
---|