forked from cricel/ScientificVisualization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplayWindow.cpp
More file actions
51 lines (35 loc) · 1.29 KB
/
DisplayWindow.cpp
File metadata and controls
51 lines (35 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "DisplayWindow.h"
#include "Application.h"
#include "Gui.h"
extern Gui *gui;
extern Image curImage; // defined in Application.cpp
// the constructor method
CDisplayWindow::CDisplayWindow(int x,int y,int w,int h,const char *l)
: Fl_Gl_Window(x,y,w,h,l)
{
// clear window
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
// the drawing method: the image gets drawn here
void CDisplayWindow::draw() {
if (!valid()) {
glLoadIdentity(); glViewport(0,0,w(),h()); gluOrtho2D(0,w(),0,h());
make_current();
}
// clear window first
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if(curImage.nx==0)
return;
// display the image as a greylevel image in the center of the window
// h() returns the height of the window, w() returns the width
//OutputDebugStringA(curImage);
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glRasterPos2i((w()-curImage.nx)/2,(h()-curImage.ny)/2);
if(curImage.ncolorChannels==1) // grey level image
glDrawPixels(curImage.nx,curImage.ny,GL_LUMINANCE,GL_UNSIGNED_BYTE,curImage.data);
else if(curImage.ncolorChannels==3) // color image
glDrawPixels(curImage.nx,curImage.ny,GL_RGB,GL_UNSIGNED_BYTE,curImage.data);
// translate to gray
}